GridMultiWidget extends BaseGridWidget { @Override protected void onItemClick(int index) { if (selectedItems.contains(index)) { selectedItems.remove(Integer.valueOf(index)); if (noButtonsMode) { itemViews[index].setBackgroundColor(0); getAudioHelper().stop(); } } else { selectedItems.add(index); if (noButtonsMode) { itemViews[index].setBackgroundColor(bgOrange); SelectChoice item = items.get(index); Clip clip = getClip(getFormEntryPrompt(), item, getReferenceManager()); if (clip != null) { getAudioHelper().play(clip); } } } widgetValueChanged(); } GridMultiWidget(Context context, QuestionDetails questionDetails); @Override IAnswerData getAnswer(); @Override void setChoiceSelected(int choiceIndex, boolean isSelected);  }
@Test public void whenChoicesHaveAudio_andNoButtonsMode_clickingChoice_playsAndStopsAudio() throws Exception { createMockReference(referenceManager, "file: String reference = createMockReference(referenceManager, "file: formEntryPrompt = new MockFormEntryPromptBuilder() .withIndex("i am index") .withAppearance(NO_BUTTONS) .withSelectChoices(asList( new SelectChoice("1", "1"), new SelectChoice("2", "2") )) .withSpecialFormSelectChoiceText(asList( new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: )) .build(); GridMultiWidget widget = getActualWidget(); widget.onItemClick(0); verify(audioHelper).play(new Clip("i am index 0", reference)); widget.onItemClick(0); verify(audioHelper).stop(); }
@Test public void whenChoicesHaveAudio_clickingChoice_doesNotPlayAudio() throws Exception { createMockReference(referenceManager, "file: createMockReference(referenceManager, "file: formEntryPrompt = new MockFormEntryPromptBuilder() .withIndex("i am index") .withSelectChoices(asList( new SelectChoice("1", "1"), new SelectChoice("2", "2") )) .withSpecialFormSelectChoiceText(asList( new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, "file: )) .build(); GridMultiWidget widget = getActualWidget(); widget.onItemClick(0); verify(audioHelper, never()).play(any()); }