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

Fixed updating the list of questions with audio widgets #5961

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -93,11 +93,13 @@ public AudioWidget(Context context, QuestionDetails questionDetails, QuestionMed
binding.audioPlayer.recordingDuration.setText(formatLength(session.first));
binding.audioPlayer.waveform.addAmplitude(session.second);
} else {
recordingInProgress = false;
binaryName = questionDetails.getPrompt().getAnswerText();
if (binaryName != null && recordingInProgress) {
widgetValueChanged();
}
recordingInProgress = false;
updateVisibilities();
updatePlayerMedia();
widgetValueChanged();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.odk.collect.testshared.RobolectricHelpers.setupMediaPlayerDataSource;
import static org.odk.collect.android.widgets.support.QuestionWidgetHelpers.mockValueChangedListener;
Expand Down Expand Up @@ -380,8 +382,9 @@ public void whenRecordingFinished_showsButtons() {
}

@Test
public void whenRecordingFinished_callValueChangeListeners() {
FormEntryPrompt prompt = promptWithAnswer(null);
public void whenRecordingFinished_callValueChangeListenersIfAnswerIsNotNull() throws Exception {
File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
FormEntryPrompt prompt = promptWithAnswer(new StringData(answerFile.getName()));
AudioWidget widget = createWidget(prompt);
WidgetValueChangedListener valueChangedListener = mockValueChangedListener(widget);

Expand All @@ -391,6 +394,32 @@ public void whenRecordingFinished_callValueChangeListeners() {
verify(valueChangedListener).widgetValueChanged(widget);
}

@Test
public void whenRecordingFinished_doNotCallValueChangeListenersIfAnswerIsNull() {
FormEntryPrompt prompt = promptWithAnswer(null);
AudioWidget widget = createWidget(prompt);
WidgetValueChangedListener valueChangedListener = mockValueChangedListener(widget);

recordingRequester.setDuration(prompt.getIndex().toString(), 5);
recordingRequester.reset();

verifyNoInteractions(valueChangedListener);
}

@Test
public void whenRecordingFinished_doNotCallValueChangeListenersIfAnswerRecordingHasBeenAlreadyStopped() throws Exception {
File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
FormEntryPrompt prompt = promptWithAnswer(new StringData(answerFile.getName()));
AudioWidget widget = createWidget(prompt);
WidgetValueChangedListener valueChangedListener = mockValueChangedListener(widget);

recordingRequester.setDuration(prompt.getIndex().toString(), 5);
recordingRequester.reset();
recordingRequester.reset();

verify(valueChangedListener, times(1)).widgetValueChanged(widget);
}

@Test
public void afterSetBinaryData_clickingPlayAndPause_playsAndPausesAudio() throws Exception {
FormEntryPrompt prompt = promptWithAnswer(null);
Expand Down