diff --git a/tests/data/test_example_builder.json b/tests/data/test_example_builder.json index 344d5da..06abb9c 100644 --- a/tests/data/test_example_builder.json +++ b/tests/data/test_example_builder.json @@ -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, diff --git a/tests/data/test_example_form.json b/tests/data/test_example_form.json index ef9dfe4..71efe8e 100644 --- a/tests/data/test_example_form.json +++ b/tests/data/test_example_form.json @@ -98,6 +98,12 @@ ] }, "cardinalDirection": "south", + "selectBoxes": { + "north": true, + "east": false, + "south": true, + "west": false + }, "favouriteSeason": "autumn", "favouriteFood": [ "mexican", diff --git a/tests/test_component.py b/tests/test_component.py index 4903d2a..2fd6a2a 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -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', diff --git a/tests/test_component_select_multiple.py b/tests/test_component_select_multiple.py index 82119f2..e2da659 100644 --- a/tests/test_component_select_multiple.py +++ b/tests/test_component_select_multiple.py @@ -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') diff --git a/tests/test_component_select_one.py b/tests/test_component_select_one.py index 1b3ac98..23862d8 100644 --- a/tests/test_component_select_one.py +++ b/tests/test_component_select_one.py @@ -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') diff --git a/tests/test_component_selectboxes.py b/tests/test_component_selectboxes.py new file mode 100644 index 0000000..7cd30d5 --- /dev/null +++ b/tests/test_component_selectboxes.py @@ -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, + )