SelectOneWidget extends BaseSelectListWidget { @Override public IAnswerData getAnswer() { Selection selectedItem = ((SelectOneListAdapter) recyclerViewAdapter).getSelectedItem(); return selectedItem == null ? null : new SelectOneData(selectedItem); } SelectOneWidget(Context context, QuestionDetails questionDetails, boolean autoAdvance); @Override IAnswerData getAnswer(); @Override void setChoiceSelected(int choiceIndex, boolean isSelected); @Override void onItemClicked(); @Override void clearAnswer(); void setListener(AdvanceToNextListener listener);  }
@Test public void whenQuickAppearanceIsUsed_shouldAdvanceToNextListenerBeCalledInButtonsMode() { formEntryPrompt = new MockFormEntryPromptBuilder() .withSelectChoices(asList( new SelectChoice("AAA", "AAA"), new SelectChoice("BBB", "BBB") )) .withAppearance("quick") .build(); SelectOneWidget widget = getWidget(); populateRecyclerView(widget); clickChoice(widget, 0); assertThat(widget.getAnswer().getDisplayText(), is("AAA")); verify(listener).advance(); }
@Test public void whenQuickAppearanceIsUsed_shouldAdvanceToNextListenerBeCalledInNoButtonsMode() { formEntryPrompt = new MockFormEntryPromptBuilder() .withSelectChoices(asList( new SelectChoice("AAA", "AAA"), new SelectChoice("BBB", "BBB") )) .withAppearance("quick no-buttons") .build(); SelectOneWidget widget = getWidget(); populateRecyclerView(widget); clickChoice(widget, 0); assertThat(widget.getAnswer().getDisplayText(), is("AAA")); verify(listener).advance(); }
@Test public void whenQuickAppearanceIsNotUsed_shouldNotAdvanceToNextListenerBeCalledInButtonsMode() { formEntryPrompt = new MockFormEntryPromptBuilder() .withSelectChoices(asList( new SelectChoice("AAA", "AAA"), new SelectChoice("BBB", "BBB") )) .build(); SelectOneWidget widget = getWidget(); populateRecyclerView(widget); clickChoice(widget, 0); assertThat(widget.getAnswer().getDisplayText(), is("AAA")); verify(listener, times(0)).advance(); }
@Test public void whenQuickAppearanceIsNotUsed_shouldNotAdvanceToNextListenerBeCalledInNoButtonsMode() { formEntryPrompt = new MockFormEntryPromptBuilder() .withSelectChoices(asList( new SelectChoice("AAA", "AAA"), new SelectChoice("BBB", "BBB") )) .withAppearance("no-buttons") .build(); SelectOneWidget widget = getWidget(); populateRecyclerView(widget); clickChoice(widget, 0); assertThat(widget.getAnswer().getDisplayText(), is("AAA")); verify(listener, times(0)).advance(); }
@Test public void whenAChoiceValueIsNull_selecting_doesNotSetAnswer() { SelectChoice selectChoice = new SelectChoice(); selectChoice.setTextID("1"); formEntryPrompt = new MockFormEntryPromptBuilder() .withSelectChoices(asList(selectChoice)) .build(); SelectOneWidget widget = getWidget(); populateRecyclerView(widget); clickChoice(widget, 0); assertThat(widget.getAnswer(), nullValue()); }