Skip to content

Commit

Permalink
Create page for select minimal dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Apr 2, 2024
1 parent cec3dcd commit 83908a5
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,17 @@ public void selectionChangeAtOneCascadeLevelWithMinimalAppearance_ShouldUpdateNe
.clickOnQuestion("Level1")
.assertTextsDoNotExist("A1", "B1", "C1", "A1A") // No choices should be shown for levels 2 and 3 when no selection is made for level 1
.openSelectMinimalDialog(0)
.clickOnText("C") // Selecting C for level 1 should only reveal options for C at level 2
.selectItem("C") // Selecting C for level 1 should only reveal options for C at level 2
.assertTextsDoNotExist("A1", "B1")
.openSelectMinimalDialog(1)
.clickOnText("C1")
.selectItem("C1")
.assertTextDoesNotExist("A1A")
.clickOnText("C")
.clickOnText("A") // Selecting A for level 1 should reveal options for A at level 2
.openSelectMinimalDialog(1)
.assertText("A1")
.assertTextsDoNotExist("A1A", "B1", "C1")
.clickOnText("A1") // Selecting A1 for level 2 should reveal options for A1 at level 3
.selectItem("A1") // Selecting A1 for level 2 should reveal options for A1 at level 3
.openSelectMinimalDialog(2)
.assertText("A1A")
.assertTextsDoNotExist("B1A", "B1", "C1");
Expand Down Expand Up @@ -387,7 +387,7 @@ public void searchMinimalInFieldList() {
.clickOnQuestion("Source15")
.openSelectMinimalDialog()
.assertTexts("Mango", "Oranges", "Strawberries")
.clickOnText("Strawberries")
.selectItem("Strawberries")
.assertText("Target15")
.assertSelectMinimalDialogAnswer("Strawberries");
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public void recordingAudio_ShouldChangeRelevanceOfRelatedField() {
.clickOnContentDescription(org.odk.collect.strings.R.string.stop_recording)
.checkIsTranslationDisplayed("Target16")
.clickOnString(org.odk.collect.strings.R.string.delete_answer_file)
.clickOnButtonInDialog(org.odk.collect.strings.R.string.delete_answer_file, new FormEntryPage("fieldlist-updates"))
.clickOnTextInDialog(org.odk.collect.strings.R.string.delete_answer_file, new FormEntryPage("fieldlist-updates"))
.assertTextDoesNotExist("Target16");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BulkFinalizationTest {

.clickOptionsIcon(string.finalize_all_drafts)
.clickOnString(string.finalize_all_drafts)
.clickOnButtonInDialog(string.finalize, EditSavedFormPage(false))
.clickOnTextInDialog(string.finalize, EditSavedFormPage(false))
.checkIsSnackbarWithQuantityDisplayed(plurals.bulk_finalize_failure, 1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ public void bigForm_ShouldBeFilledSuccessfully() {
.startBlankForm("Nigeria Wards")
.assertQuestion("State")
.openSelectMinimalDialog()
.clickOnText("Adamawa")
.selectItem("Adamawa")
.swipeToNextQuestion("LGA", true)
.openSelectMinimalDialog()
.clickOnText("Ganye")
.selectItem("Ganye")
.swipeToNextQuestion("Ward", true)
.openSelectMinimalDialog()
.clickOnText("Jaggu")
.selectItem("Jaggu")
.swipeToNextQuestion("Comments")
.swipeToEndScreen()
.clickFinalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public AddNewRepeatDialog assertOnPage() {
}

public <D extends Page<D>> D clickOnAdd(D destination) {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.add_repeat, destination);
return clickOnTextInDialog(org.odk.collect.strings.R.string.add_repeat, destination);
}

public <D extends Page<D>> D clickOnDoNotAdd(D destination) {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.dont_add_repeat, destination);
return clickOnTextInDialog(org.odk.collect.strings.R.string.dont_add_repeat, destination);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class BulkFinalizationConfirmationDialogPage(private val count: Int) : Page<Bulk
}

fun clickFinalize(): EditSavedFormPage {
return this.clickOnButtonInDialog(R.string.finalize, EditSavedFormPage(false))
return this.clickOnTextInDialog(R.string.finalize, EditSavedFormPage(false))
}

fun clickCancel(): EditSavedFormPage {
return this.clickOnButtonInDialog(R.string.cancel, EditSavedFormPage(false))
return this.clickOnTextInDialog(R.string.cancel, EditSavedFormPage(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public FormEntryPage clickRankingButton() {
public FormEntryPage deleteGroup(String questionText) {
onView(withText(questionText)).perform(longClick());
onView(withText(org.odk.collect.strings.R.string.delete_repeat)).perform(click());
clickOnButtonInDialog(org.odk.collect.strings.R.string.discard_group, this);
clickOnTextInDialog(org.odk.collect.strings.R.string.discard_group, this);
return this;
}

Expand Down Expand Up @@ -268,7 +268,7 @@ public FormEntryPage longPressOnQuestion(String question, boolean isRequired) {

public FormEntryPage removeResponse() {
onView(withText(org.odk.collect.strings.R.string.clear_answer)).perform(click());
return clickOnButtonInDialog(org.odk.collect.strings.R.string.discard_answer, this);
return clickOnTextInDialog(org.odk.collect.strings.R.string.discard_answer, this);
}

public AddNewRepeatDialog swipeToNextQuestionWithRepeatGroup(String repeatName) {
Expand Down Expand Up @@ -354,14 +354,13 @@ private void flingRight() {
});
}

public FormEntryPage openSelectMinimalDialog() {
openSelectMinimalDialog(0);
return this;
public SelectMinimalDialogPage openSelectMinimalDialog() {
return openSelectMinimalDialog(0);
}

public FormEntryPage openSelectMinimalDialog(int index) {
public SelectMinimalDialogPage openSelectMinimalDialog(int index) {
onView(withIndex(withClassName(Matchers.endsWith("TextInputEditText")), index)).perform(click());
return this;
return new SelectMinimalDialogPage(formName).assertOnPage();
}

public FormEntryPage assertSelectMinimalDialogAnswer(String answer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public FormEntryPage addGroup() {

public FormHierarchyPage deleteGroup() {
onView(withId(R.id.menu_delete_child)).perform(click());
return clickOnButtonInDialog(org.odk.collect.strings.R.string.delete_repeat, this);
return clickOnTextInDialog(org.odk.collect.strings.R.string.delete_repeat, this);
}

public FormEndPage clickJumpEndButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public ListPreferenceDialog<T> assertOnPage() {
}

public T clickOption(int option) {
return clickOnButtonInDialog(option, page);
return clickOnTextInDialog(option, page);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public OkDialog assertOnPage() {
}

public <D extends Page<D>> D clickOK(D destination) {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.ok, destination);
return clickOnTextInDialog(org.odk.collect.strings.R.string.ok, destination);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,13 @@ abstract class Page<T : Page<T>> {
return destination!!.assertOnPage()
}

fun <D : Page<D>?> clickOnButtonInDialog(buttonText: Int, destination: D): D {
fun <D : Page<D>?> clickOnTextInDialog(buttonText: Int, destination: D): D {
return clickOnTextInDialog(getTranslatedString(buttonText), destination)
}

fun <D : Page<D>?> clickOnTextInDialog(buttonText: String, destination: D): D {
waitForDialogToSettle()
onView(withText(getTranslatedString(buttonText)))
onView(withText(buttonText))
.inRoot(isDialog())
.perform(click())
return destination!!.assertOnPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.Matchers.allOf
import org.odk.collect.android.R
import org.odk.collect.android.support.WaitFor

internal class ProjectSettingsDialogPage : Page<ProjectSettingsDialogPage>() {
Expand All @@ -21,21 +20,21 @@ internal class ProjectSettingsDialogPage : Page<ProjectSettingsDialogPage>() {
}

fun clickSettings(): ProjectSettingsPage {
return clickOnButtonInDialog(
return clickOnTextInDialog(
org.odk.collect.strings.R.string.settings,
ProjectSettingsPage()
)
}

fun clickAbout(): AboutPage {
return clickOnButtonInDialog(
return clickOnTextInDialog(
org.odk.collect.strings.R.string.about_preferences,
AboutPage()
)
}

fun clickAddProject(): QrCodeProjectCreatorDialogPage {
return clickOnButtonInDialog(
return clickOnTextInDialog(
org.odk.collect.strings.R.string.add_project,
QrCodeProjectCreatorDialogPage()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.odk.collect.android.R

class QrCodeProjectCreatorDialogPage : Page<QrCodeProjectCreatorDialogPage>() {
override fun assertOnPage(): QrCodeProjectCreatorDialogPage {
Expand All @@ -14,7 +13,7 @@ class QrCodeProjectCreatorDialogPage : Page<QrCodeProjectCreatorDialogPage>() {
}

fun switchToManualMode(): ManualProjectCreatorDialogPage {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.configure_manually, ManualProjectCreatorDialogPage())
return clickOnTextInDialog(org.odk.collect.strings.R.string.configure_manually, ManualProjectCreatorDialogPage())
}

fun assertDuplicateDialogShown(): QrCodeProjectCreatorDialogPage {
Expand All @@ -26,10 +25,10 @@ class QrCodeProjectCreatorDialogPage : Page<QrCodeProjectCreatorDialogPage>() {
}

fun switchToExistingProject(): MainMenuPage {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.switch_to_existing, MainMenuPage())
return clickOnTextInDialog(org.odk.collect.strings.R.string.switch_to_existing, MainMenuPage())
}

fun addDuplicateProject(): MainMenuPage {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.add_duplicate_project, MainMenuPage())
return clickOnTextInDialog(org.odk.collect.strings.R.string.add_duplicate_project, MainMenuPage())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class SaveOrIgnoreDrawingDialog<D : Page<D>>(
}

fun clickSaveChanges(): D {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.keep_changes, destination)
return clickOnTextInDialog(org.odk.collect.strings.R.string.keep_changes, destination)
}

fun clickDiscardChanges(): D {
return clickOnButtonInDialog(org.odk.collect.strings.R.string.discard_changes, destination)
return clickOnTextInDialog(org.odk.collect.strings.R.string.discard_changes, destination)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class SavepointRecoveryDialogPage : Page<SavepointRecoveryDialogPage>() {
}

fun <D : Page<D>> clickRecover(destination: D): D {
return this.clickOnButtonInDialog(R.string.recover, destination)
return this.clickOnTextInDialog(R.string.recover, destination)
}

fun <D : Page<D>> clickDoNotRecover(destination: D): D {
return this.clickOnButtonInDialog(R.string.do_not_recover, destination)
return this.clickOnTextInDialog(R.string.do_not_recover, destination)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.odk.collect.android.support.pages

class SelectMinimalDialogPage(private val formName: String) : Page<SelectMinimalDialogPage>() {
override fun assertOnPage(): SelectMinimalDialogPage {
assertTextDoesNotExist(formName)
return this
}

fun selectItem(item: String): FormEntryPage {
return clickOnTextInDialog(item, FormEntryPage(formName))
}
}

0 comments on commit 83908a5

Please sign in to comment.