Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi select widget with no-buttons appearance #5824

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ void onItemClick(Selection selection, View view) {
}
playAudio(selection.choice);
}

if (listener != null) {
listener.onItemClicked();
}
}

public void addItem(Selection item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -30,6 +31,7 @@
import org.odk.collect.android.formentry.questions.QuestionDetails;
import org.odk.collect.android.formentry.questions.QuestionTextSizeHelper;
import org.odk.collect.android.injection.config.AppDependencyModule;
import org.odk.collect.android.listeners.WidgetValueChangedListener;
import org.odk.collect.android.support.CollectHelpers;
import org.odk.collect.android.support.MockFormEntryPromptBuilder;
import org.odk.collect.android.utilities.Appearances;
Expand Down Expand Up @@ -160,27 +162,6 @@ public void whenChoicesHaveAudio_audioButtonUsesIndexAsClipID() throws Exception
verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 1", REFERENCES.get(1).second)));
}

private void overrideDependencyModule() throws Exception {
ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

@Override
public ReferenceManager providesReferenceManager() {
return referenceManager;
}

@Override
public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
return context -> audioHelper;
}

@Override
public SoftKeyboardController provideSoftKeyboardController() {
return mock(SoftKeyboardController.class);
}
});
}

@Test
public void usingReadOnlyOptionShouldMakeAllClickableElementsDisabled() {
// No appearance
Expand Down Expand Up @@ -226,6 +207,66 @@ public void whenSpacesInUnderlyingValuesExist_shouldAppropriateWarningBeDisplaye
assertThat(warningTv.getText(), is("Warning: underlying values a a, b b have spaces"));
}

@Test
public void checkingCheckboxOnItem_callsValueChangedListener() {
seadowg marked this conversation as resolved.
Show resolved Hide resolved
formEntryPrompt = new MockFormEntryPromptBuilder()
.withIndex("i am index")
.withSelectChoices(asList(
new SelectChoice("1", "1"),
new SelectChoice("2", "2")
))
.build();

SelectMultiWidget widget = getWidget();
WidgetValueChangedListener valueChangedListener = mock();
widget.setValueChangedListener(valueChangedListener);
populateRecyclerView(widget);

((CheckBox) ((AudioVideoImageTextLabel) getWidget().binding.choicesRecyclerView.getChildAt(0)).getLabelTextView()).setChecked(true);
verify(valueChangedListener).widgetValueChanged(widget);
}

@Test
public void whenPromptHasNoButtonsAppearance_clickingItem_callsValueChangedListener() {
formEntryPrompt = new MockFormEntryPromptBuilder()
.withIndex("i am index")
.withAppearance("no-buttons")
.withSelectChoices(asList(
new SelectChoice("1", "1"),
new SelectChoice("2", "2")
))
.build();

SelectMultiWidget widget = getWidget();
WidgetValueChangedListener valueChangedListener = mock();
widget.setValueChangedListener(valueChangedListener);
populateRecyclerView(widget);

getWidget().binding.choicesRecyclerView.getChildAt(0).performClick();
verify(valueChangedListener).widgetValueChanged(widget);
}

private void overrideDependencyModule() throws Exception {
ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

@Override
public ReferenceManager providesReferenceManager() {
return referenceManager;
}

@Override
public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
return context -> audioHelper;
}

@Override
public SoftKeyboardController provideSoftKeyboardController() {
return mock(SoftKeyboardController.class);
}
});
}

private ViewGroup getChoiceView(SelectMultiWidget widget, int index) {
return (ViewGroup) widget.binding.choicesRecyclerView.getChildAt(index);
}
Expand Down