ChoicesRecyclerView extends RecyclerView { public void initRecyclerView(AbstractSelectListAdapter adapter, boolean isFlex) { if (isFlex) { enableFlexboxLayout(); } else { enableGridLayout(adapter.getNumColumns()); } setAdapter(adapter); adjustRecyclerViewSize(); } ChoicesRecyclerView(@NonNull Context context);  ChoicesRecyclerView(Context context, AttributeSet attrs); void initRecyclerView(AbstractSelectListAdapter adapter, boolean isFlex);  }
@Test public void whenNonFLexAppearanceIsUsed_shouldGridLayoutManagerBeUsed() { SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, null, new ArrayList<>(), null, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); assertThat(recyclerView.getLayoutManager().getClass().getName(), equalTo(GridLayoutManager.class.getName())); }
@Test public void whenFLexAppearanceIsUsed_shouldFlexboxLayoutManagerBeUsed() { SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, null, new ArrayList<>(), null, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, true); assertThat(recyclerView.getLayoutManager().getClass().getName(), equalTo(FlexboxLayoutManager.class.getName())); }
@Test public void whenNonFLexAppearanceIsUsedWithOneColumn_shouldDividersBeAdded() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); assertThat(recyclerView.getItemDecorationCount(), is(1)); assertThat(recyclerView.getItemDecorationAt(0), is(instanceOf(DividerItemDecoration.class))); }
@Test public void whenNonFLexAppearanceIsUsedWithMoreThanOneColumn_shouldNotDividersBeAdded() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, activityController.get(), items, formEntryPrompt, null, null, 0, 2, false); recyclerView.initRecyclerView(adapter, false); assertThat(recyclerView.getItemDecorationCount(), is(0)); }
@Test public void whenFLexAppearanceIsUsed_shouldNotDividersBeAdded() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, activityController.get(), items, formEntryPrompt, null, null, 0, 2, false); recyclerView.initRecyclerView(adapter, true); assertThat(recyclerView.getItemDecorationCount(), is(0)); }
@Test public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectOneButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); assertVisibleItemsInButtonsMode("AAA", "BBB"); adapter.getFilter().filter("b"); assertVisibleItemsInButtonsMode("BBB"); adapter.getFilter().filter("bc"); assertVisibleItemsInButtonsMode(); adapter.getFilter().filter("b"); assertVisibleItemsInButtonsMode("BBB"); adapter.getFilter().filter(""); assertVisibleItemsInButtonsMode("AAA", "BBB"); }
@Test public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); assertVisibleItemsInButtonsMode("AAA", "BBB"); adapter.getFilter().filter("b"); assertVisibleItemsInButtonsMode("BBB"); adapter.getFilter().filter("bc"); assertVisibleItemsInButtonsMode(); adapter.getFilter().filter("b"); assertVisibleItemsInButtonsMode("BBB"); adapter.getFilter().filter(""); assertVisibleItemsInButtonsMode("AAA", "BBB"); }
@Test public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectOneNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectOneListAdapter adapter = new SelectOneListAdapter(null, null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); assertVisibleItemsInNoButtonsMode("AAA", "BBB"); adapter.getFilter().filter("b"); assertVisibleItemsInNoButtonsMode("BBB"); adapter.getFilter().filter("bc"); assertVisibleItemsInNoButtonsMode(); adapter.getFilter().filter("b"); assertVisibleItemsInNoButtonsMode("BBB"); adapter.getFilter().filter(""); assertVisibleItemsInNoButtonsMode("AAA", "BBB"); }
@Test public void whenChoicesFiltered_shouldProperValuesBeReturnedInSelectMultiNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), null, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); assertVisibleItemsInNoButtonsMode("AAA", "BBB"); adapter.getFilter().filter("b"); assertVisibleItemsInNoButtonsMode("BBB"); adapter.getFilter().filter("bc"); assertVisibleItemsInNoButtonsMode(); adapter.getFilter().filter("b"); assertVisibleItemsInNoButtonsMode("BBB"); adapter.getFilter().filter(""); assertVisibleItemsInNoButtonsMode("AAA", "BBB"); }
@Test public void whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectOneListAdapter adapter = new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(1); assertThat(isItemSelected(0), is(false)); assertThat(isItemSelected(1), is(true)); }
@Test public void whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(1); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(true)); }
@Test public void whenClickOneOption_shouldPreviouslySelectedOptionBeUnselectedInSelectOneNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectOneListAdapter adapter = new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(1); assertThat(isItemSelected(0), is(false)); assertThat(isItemSelected(1), is(true)); }
@Test public void whenClickOneOption_shouldPreviouslySelectedOptionRemainSelectedInSelectMultiNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(1); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(true)); }
@Test public void whenClickOneElementTwice_shouldThatElementRemainSelectedInSelectOneButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectOneListAdapter adapter = new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); }
@Test public void whenClickOneElementTwice_shouldThatElementBeUnselectedInSelectMultiButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(0); assertThat(isItemSelected(0), is(false)); assertThat(isItemSelected(1), is(false)); }
@Test public void whenClickOneElementTwice_shouldThatElementRemainSelectedInSelectOneNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectOneListAdapter adapter = new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); }
@Test public void whenClickOneElementTwice_shouldThatElementBeUnselectedInSelectMultiNoButtonsMode() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); clickChoice(0); assertThat(isItemSelected(0), is(true)); assertThat(isItemSelected(1), is(false)); clickChoice(0); assertThat(isItemSelected(0), is(false)); assertThat(isItemSelected(1), is(false)); }
@Test public void whenButtonsModeIsUsed_shouldViewAndItsElementsBeLongClickableToSupportRemovingAnswers() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); AudioVideoImageTextLabel view = (AudioVideoImageTextLabel) getChoiceView(0); File file = mock(File.class); when(file.exists()).thenReturn(true); view.setImage(file); view.setVideo(file); AudioHelper audioHelper = mock(AudioHelper.class); MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false); when(audioHelper.setAudio(any(AudioButton.class), any())).thenReturn(isPlaying); view.setAudio("file: assertThat(view.isLongClickable(), is(true)); assertThat(view.getImageView().isLongClickable(), is(true)); assertThat(view.getVideoButton().isLongClickable(), is(true)); assertThat(view.getAudioButton().isLongClickable(), is(true)); assertThat(view.getLabelTextView().isLongClickable(), is(true)); }
@Test public void whenNoButtonsModeIsUsed_shouldViewBeLongClickableToSupportRemovingAnswers() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, "no-buttons"); SelectItemClickListener listener = mock(SelectItemClickListener.class); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, true); recyclerView.initRecyclerView(adapter, false); assertThat(getChoiceView(0).isLongClickable(), is(true)); }
@Test public void whenChangingAnswer_shouldHasAnswerChangedReturnCorrectValue() { List<SelectChoice> items = getTestChoices(); setUpFormEntryPrompt(items, ""); SelectItemClickListener listener = mock(SelectItemClickListener.class); List<Selection> selectedItems = new ArrayList<>(); selectedItems.add(items.get(0).selection()); SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(selectedItems, listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false); recyclerView.initRecyclerView(adapter, false); clickChoice(1); assertThat(adapter.hasAnswerChanged(), is(true)); clickChoice(0); assertThat(adapter.hasAnswerChanged(), is(true)); clickChoice(1); assertThat(adapter.hasAnswerChanged(), is(true)); clickChoice(0); assertThat(adapter.hasAnswerChanged(), is(false)); }