Skip to content

Commit

Permalink
Merge pull request #38 from bobslee/master
Browse files Browse the repository at this point in the history
Add selectboxes unittest.
  • Loading branch information
bobslee authored Sep 25, 2023
2 parents 20c7939 + 3b1e5e9 commit 42cd67f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
31 changes: 31 additions & 0 deletions tests/data/test_example_builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,37 @@
"url": ""
}
},
{
"label": "Select Boxes",
"optionsLabelPosition": "right",
"tableView": false,
"values": [
{
"label": "North",
"value": "north",
"shortcut": ""
},
{
"label": "East",
"value": "east",
"shortcut": ""
},
{
"label": "South",
"value": "south",
"shortcut": ""
},
{
"label": "West",
"value": "west",
"shortcut": ""
}
],
"key": "selectBoxes",
"type": "selectboxes",
"input": true,
"inputType": "checkbox"
},
{
"collapsible": false,
"tableView": false,
Expand Down
6 changes: 6 additions & 0 deletions tests/data/test_example_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
]
},
"cardinalDirection": "south",
"selectBoxes": {
"north": true,
"east": false,
"south": true,
"west": false
},
"favouriteSeason": "autumn",
"favouriteFood": [
"mexican",
Expand Down
1 change: 1 addition & 0 deletions tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _i18n(self):
'East': 'Oost',
'South': 'Zuid',
'West': 'West',
'Select Boxes': 'Select aanvink opties',
'Month Day Year': 'Maand dag jaar',
'Day Month Year': 'Dag maand jaar',
'May': 'Mei',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_component_select_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_form(self):
self.assertEqual(food.value_labels, ['Mexican', 'Chinese'])
self.assertEqual(food.value_label, False)
self.assertEqual(food.type, 'select')

def test_get_form_data(self):
food = self.form.input.favouriteFood
self.assertEqual(food.label, 'Favourite Food')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_component_select_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_get_form(self):
season = self.form.input_components['favouriteSeason']
self.assertEqual(season.label, 'Favourite Season')
self.assertEqual(season.value, 'autumn')
self.assertEqual(season.value_label, 'Autumn')
self.assertEqual(season.value_label, 'Autumn')
self.assertEqual(season.type, 'select')

def test_get_form_data(self):
season = self.form.input.favouriteSeason
self.assertEqual(season.label, 'Favourite Season')
Expand Down
83 changes: 83 additions & 0 deletions tests/test_component_selectboxes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright Nova Code (http://www.novacode.nl)
# See LICENSE file for full licensing details.

from test_component import ComponentTestCase
from formiodata.components.selectboxes import selectboxesComponent


class selectboxesComponentTestCase(ComponentTestCase):

def setUp(self):
super(selectboxesComponentTestCase, self).setUp()
self.selectboxes_value = {
"north": True,
"east": False,
"south": True,
"west": False,
}
self.selectboxes_values_labels = {
"north": {"key": "north", "label": "North", "value": True},
"east": {"key": "east", "label": "East", "value": False},
"south": {"key": "south", "label": "South", "value": True},
"west": {"key": "west", "label": "West", "value": False},
}
self.selectboxes_values_labels_i18n_nl = {
"north": {"key": "north", "label": "Noord", "value": True},
"east": {"key": "east", "label": "Oost", "value": False},
"south": {"key": "south", "label": "Zuid", "value": True},
"west": {"key": "west", "label": "West", "value": False},
}

def test_object(self):
# selectboxesComponent
selectBoxes = self.builder.input_components['selectBoxes']
self.assertIsInstance(selectBoxes, selectboxesComponent)

# Not selectboxesComponent
email = self.builder.input_components['email']
self.assertNotIsInstance(email, selectboxesComponent)

def test_get_key(self):
selectBoxes = self.builder.input_components['selectBoxes']
self.assertEqual(selectBoxes.key, 'selectBoxes')

def test_get_type(self):
selectBoxes = self.builder.input_components['selectBoxes']
self.assertEqual(selectBoxes.type, 'selectboxes')

def test_get_label(self):
selectBoxes = self.builder.input_components['selectBoxes']
self.assertEqual(selectBoxes.label, 'Select Boxes')

def test_set_label(self):
selectBoxes = self.builder.input_components['selectBoxes']
self.assertEqual(selectBoxes.label, 'Select Boxes')
selectBoxes.label = 'Other Select Boxes'
self.assertEqual(selectBoxes.label, 'Other Select Boxes')

def test_get_form(self):
selectBoxes = self.form.input_components['selectBoxes']
self.assertEqual(selectBoxes.label, 'Select Boxes')
self.assertEqual(selectBoxes.value, self.selectboxes_value)
self.assertEqual(selectBoxes.values_labels, self.selectboxes_values_labels)
self.assertEqual(selectBoxes.type, 'selectboxes')

def test_get_form_data(self):
selectBoxes = self.form.input.selectBoxes
self.assertEqual(selectBoxes.label, 'Select Boxes')
self.assertEqual(selectBoxes.value, self.selectboxes_value)
self.assertEqual(selectBoxes.values_labels, self.selectboxes_values_labels)
self.assertEqual(selectBoxes.type, 'selectboxes')

# i18n translations
def test_get_label_i18n_nl(self):
food = self.builder_i18n_nl.input_components['selectBoxes']
self.assertEqual(food.label, 'Select aanvink opties')

def test_get_form_data_i18n_nl(self):
self.assertEqual(self.form_i18n_nl.input.selectBoxes.label, 'Select aanvink opties')
self.assertEqual(self.form_i18n_nl.input.selectBoxes.value, self.selectboxes_value)
self.assertEqual(
self.form_i18n_nl.input.selectBoxes.values_labels,
self.selectboxes_values_labels_i18n_nl,
)

0 comments on commit 42cd67f

Please sign in to comment.