Skip to content

Commit

Permalink
Merge pull request #6560 from grzesiek2010/COLLECT-6553
Browse files Browse the repository at this point in the history
Handle non-existent labels in repeats
  • Loading branch information
grzesiek2010 authored Jan 14, 2025
2 parents c72c683 + f8ea5ca commit 6c3f621
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 240 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.odk.collect.android.feature.formentry

import androidx.test.espresso.Espresso
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.odk.collect.android.R
import org.odk.collect.android.support.pages.EndOfFormPage
import org.odk.collect.android.support.pages.FormEndPage
import org.odk.collect.android.support.pages.FormEntryPage
import org.odk.collect.android.support.rules.CollectTestRule
import org.odk.collect.android.support.rules.TestRuleChain.chain

@RunWith(AndroidJUnit4::class)
class AddRepeatTest {
private val rule = CollectTestRule()

@get:Rule
var copyFormChain: RuleChain = chain().around(rule)

@Test
fun whenInRepeat_swipingNext_andClickingAdd_addsAnotherRepeat() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.assertText("Person > 1")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnAdd(FormEntryPage("One Question Repeat"))
.assertText("Person > 2")
}

@Test
fun whenInRepeat_swipingNext_andClickingDoNotAdd_leavesRepeatGroup() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.assertText("Person > 1")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnDoNotAdd(EndOfFormPage("One Question Repeat"))
}

@Test
fun whenInRepeat_thatIsAFieldList_swipingNext_andClickingAdd_addsAnotherRepeat() {
rule.startAtMainMenu()
.copyForm("field-list-repeat.xml")
.startBlankForm("Field-List Repeat")
.assertText("Person > 1")
.assertText("What is their age?")
.assertText("What is their name?")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnAdd(FormEntryPage("Field-List Repeat"))
.assertText("Person > 2")
.assertText("What is their age?")
.assertText("What is their name?")
}

@Test
fun whenInRepeat_clickingPlus_andClickingAdd_addsRepeatToEndOfSeries() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.assertText("Person > 1")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnAdd(FormEntryPage("One Question Repeat"))
.swipeToPreviousQuestion("What is their age?")
.assertText("Person > 1")
.clickPlus("Person")
.clickOnAdd(FormEntryPage("One Question Repeat"))
.assertText("Person > 3")
}

@Test
fun whenInARepeat_clickingPlus_andClickingDoNotAdd_returns() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.assertText("Person > 1")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnAdd(FormEntryPage("One Question Repeat"))
.swipeToPreviousQuestion("What is their age?")
.assertText("Person > 1")
.clickPlus("Person")
.clickOnDoNotAdd(FormEntryPage("One Question Repeat"))
.assertText("Person > 1")
}

@Test
fun whenInRepeatWithFixedCount_noPlusButtonAppears() {
rule.startAtMainMenu()
.copyForm("fixed-count-repeat.xml")
.startBlankForm("Fixed Count Repeat")

Espresso.onView(ViewMatchers.withId(R.id.menu_add_repeat))
.check(ViewAssertions.doesNotExist())
}

@Test
fun whenInHierarchyForRepeatGroup_clickingPlus_addsRepeatAtEndOfSeries() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.assertText("Person > 1")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnAdd(FormEntryPage("One Question Repeat"))
.clickGoToArrow()
.clickGoUpIcon()
.addGroup()
.assertText("Person > 3")
}

@Test
fun whenInRepeatWithoutLabel_swipingNext_displaysTheAddRepeatDialog() {
rule.startAtMainMenu()
.copyForm("repeat_without_label.xml")
.startBlankForm("Repeat without label") // group with no label
.swipeToNextQuestionWithRepeatGroup("")
.clickOnDoNotAdd(FormEntryPage("Repeat without label")) // group with blank label
.swipeToNextQuestionWithRepeatGroup("")
.clickOnDoNotAdd(FormEntryPage("Repeat without label"))
}

@Test
fun whenViewFormInHierarchyForRepeatGroup_noAddButtonAppears() {
rule.startAtMainMenu()
.copyForm("one-question-repeat.xml")
.startBlankForm("One Question Repeat")
.swipeToNextQuestionWithRepeatGroup("Person")
.clickOnDoNotAdd(FormEndPage("One Question Repeat"))
.clickFinalize()

.clickSendFinalizedForm(1)
.clickOnForm("One Question Repeat")
.clickOnGroup("Person")
.assertNoId(R.id.menu_add_repeat)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.odk.collect.android.support.pages

import androidx.test.espresso.Espresso.onView
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.strings.R

class AddNewRepeatDialog(private val repeatName: String?) : Page<AddNewRepeatDialog>() {
override fun assertOnPage(): AddNewRepeatDialog {
val dialogMessage = if (repeatName.isNullOrBlank()) {
getTranslatedString(R.string.add_another_question)
} else {
getTranslatedString(R.string.add_repeat_question, repeatName)
}
onView(withText(dialogMessage))
.inRoot(isDialog())
.check(matches(isDisplayed()))
return this
}

fun <D : Page<D>> clickOnAdd(destination: D): D {
return clickOnTextInDialog(R.string.add_repeat, destination)
}

fun <D : Page<D>> clickOnDoNotAdd(destination: D): D {
return clickOnTextInDialog(R.string.cancel, destination)
}
}
Loading

0 comments on commit 6c3f621

Please sign in to comment.