Search in sources :

Example 31 with Selection

use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoiceUnselectedInSelectMultiNoButtonsMode_shouldStopPlayingAudio.

@Test
public void whenChoiceUnselectedInSelectMultiNoButtonsMode_shouldStopPlayingAudio() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    List<Selection> selectedItems = new ArrayList<>();
    selectedItems.add(items.get(0).selection());
    SelectMultipleListAdapter adapter = spy(new SelectMultipleListAdapter(selectedItems, listener, activityController.get(), items, formEntryPrompt, null, audioHelper, 0, 1, true, mock(MediaUtils.class)));
    initRecyclerView(adapter, false);
    // Unselect AAA
    clickChoice(0);
    verify(adapter.getAudioHelper()).stop();
    verify(adapter, never()).playAudio(any());
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) Selection(org.javarosa.core.model.data.helper.Selection) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) ArrayList(java.util.ArrayList) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) Test(org.junit.Test)

Example 32 with Selection

use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.

the class RankingWidgetTest method getNextAnswer.

@NonNull
@Override
public MultipleItemsData getNextAnswer() {
    List<SelectChoice> selectChoices = getSelectChoices();
    List<Selection> selections = new ArrayList<>();
    for (SelectChoice selectChoice : selectChoices) {
        selections.add(new Selection(selectChoice));
    }
    return new SelectMultiData(selections);
}
Also used : SelectMultiData(org.javarosa.core.model.data.SelectMultiData) SelectChoice(org.javarosa.core.model.SelectChoice) Selection(org.javarosa.core.model.data.helper.Selection) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Example 33 with Selection

use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.

the class SelectMultiImageMapWidgetTest method getNextAnswer.

@NonNull
@Override
public SelectMultiData getNextAnswer() {
    List<SelectChoice> selectChoices = getSelectChoices();
    int selectedIndex = Math.abs(random.nextInt()) % selectChoices.size();
    SelectChoice selectChoice = selectChoices.get(selectedIndex);
    Selection selection = new Selection(selectChoice);
    return new SelectMultiData(ImmutableList.of(selection));
}
Also used : SelectMultiData(org.javarosa.core.model.data.SelectMultiData) SelectChoice(org.javarosa.core.model.SelectChoice) Selection(org.javarosa.core.model.data.helper.Selection) NonNull(androidx.annotation.NonNull)

Example 34 with Selection

use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.

the class SelectMultiMinimalWidgetTest method whenAnswerChanges_shouldValueChangeListenersBeCalled.

@Test
public void whenAnswerChanges_shouldValueChangeListenersBeCalled() {
    WidgetValueChangedListener valueChangedListener = mockValueChangedListener(getSpyWidget());
    SelectMultiData answer = getInitialAnswer();
    Selection selectedChoice = ((List<Selection>) answer.getValue()).get(0);
    getSpyWidget().setData(Collections.singletonList(selectedChoice));
    verify(valueChangedListener).widgetValueChanged(getSpyWidget());
}
Also used : SelectMultiData(org.javarosa.core.model.data.SelectMultiData) Selection(org.javarosa.core.model.data.helper.Selection) List(java.util.List) Arrays.asList(java.util.Arrays.asList) WidgetValueChangedListener(org.odk.collect.android.listeners.WidgetValueChangedListener) Test(org.junit.Test) GeneralSelectMultiWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest)

Example 35 with Selection

use of org.javarosa.core.model.data.helper.Selection in project collect by opendatakit.

the class SelectMultiMinimalWidgetTest method whenThereIsAnswer_shouldSelectedChoicesBeDisplayed.

@Test
public void whenThereIsAnswer_shouldSelectedChoicesBeDisplayed() {
    SelectMultiData answer = getInitialAnswer();
    Selection selectedChoice = ((List<Selection>) answer.getValue()).get(0);
    when(formEntryPrompt.getAnswerValue()).thenReturn(answer);
    when(formEntryPrompt.getSelectItemText(selectedChoice)).thenReturn(selectedChoice.getValue());
    assertThat(getSpyWidget().binding.answer.getText().toString(), is(selectedChoice.getValue()));
}
Also used : SelectMultiData(org.javarosa.core.model.data.SelectMultiData) Selection(org.javarosa.core.model.data.helper.Selection) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test) GeneralSelectMultiWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest)

Aggregations

Selection (org.javarosa.core.model.data.helper.Selection)44 SelectChoice (org.javarosa.core.model.SelectChoice)20 SelectMultiData (org.javarosa.core.model.data.SelectMultiData)19 ArrayList (java.util.ArrayList)17 SelectOneData (org.javarosa.core.model.data.SelectOneData)14 List (java.util.List)12 Test (org.junit.Test)10 NonNull (androidx.annotation.NonNull)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 SuppressLint (android.annotation.SuppressLint)4 Constraint (org.javarosa.core.model.condition.Constraint)4 IAnswerData (org.javarosa.core.model.data.IAnswerData)4 GeneralSelectMultiWidgetTest (org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest)4 Arrays.asList (java.util.Arrays.asList)3 GeneralSelectOneWidgetTest (org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest)3 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)2 ConstraintHint (org.javarosa.core.model.condition.pivot.ConstraintHint)2 DateData (org.javarosa.core.model.data.DateData)2 DateTimeData (org.javarosa.core.model.data.DateTimeData)2 TreeElement (org.javarosa.core.model.instance.TreeElement)2