Skip to content

Commit

Permalink
Issue webcompat#3380 - accepts list with 3 and 2 items tuples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
karlcow committed Jul 14, 2020
1 parent 09853fb commit fb8931c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tests/unit/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions webcompat/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb8931c

Please sign in to comment.