From fb8931c125a0fe977d7ed4f567a888dae32ddd32 Mon Sep 17 00:00:00 2001 From: Karl Dubost Date: Tue, 14 Jul 2020 11:32:58 +0900 Subject: [PATCH] Issue #3380 - accepts list with 3 and 2 items tuples Originally the list of tuples were 2 items long. but the wizard is using in some cases 3 items long list (because of icons) for radio fields. This leds to the duplication of the list of problem_choices with 2 items and 3 items. So instead of duplicating code, let's handle it in the function itself. There might be something more elegant to do. We can discover that later. --- tests/unit/test_form.py | 28 ++++++++++++++-------------- webcompat/form.py | 2 ++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/unit/test_form.py b/tests/unit/test_form.py index 68223f7a5..bee3767c3 100644 --- a/tests/unit/test_form.py +++ b/tests/unit/test_form.py @@ -100,22 +100,22 @@ def test_metadata_wrapping(self): def test_radio_button_label(self): """Check that appropriate radio button label is returned.""" - test_labels_list = [ - ('detection_bug', 'Desktop site instead of mobile site'), - ('unknown_bug', 'Something else') + tests_labels_lists = [ + [('detection_bug', 'i.svg', 'Desktop site instead of mobile site'), + ('unknown_bug', 'b.svg', 'Something else')], + [('detection_bug', 'Desktop site instead of mobile site'), + ('unknown_bug', 'Something else')], ] - r = form.get_radio_button_label('unknown_bug', test_labels_list) - self.assertEqual(r, 'Something else') - - r = form.get_radio_button_label('detection_bug', test_labels_list) - self.assertEqual(r, 'Desktop site instead of mobile site') - - r = form.get_radio_button_label(None, test_labels_list) - self.assertEqual(r, 'Unknown') - - r = form.get_radio_button_label('failme', test_labels_list) - self.assertEqual(r, 'Unknown') + for test_labels_list in tests_labels_lists: + r = form.get_radio_button_label('unknown_bug', test_labels_list) + self.assertEqual(r, 'Something else') + r = form.get_radio_button_label('detection_bug', test_labels_list) + self.assertEqual(r, 'Desktop site instead of mobile site') + r = form.get_radio_button_label(None, test_labels_list) + self.assertEqual(r, 'Unknown') + r = form.get_radio_button_label('failme', test_labels_list) + self.assertEqual(r, 'Unknown') def test_get_form(self): """Check we return the right form with the appropriate data.""" diff --git a/webcompat/form.py b/webcompat/form.py index f403f2e68..0806b8d0e 100644 --- a/webcompat/form.py +++ b/webcompat/form.py @@ -329,6 +329,8 @@ def build_details(details): def get_radio_button_label(field_value, label_list): """Return human-readable label for problem choices form value.""" + if len(label_list[0]) == 3: + label_list = [(value, text) for value, icon, text in label_list] for value, text in label_list: if value == field_value: return text