Skip to content

Commit

Permalink
Merge pull request #5629 from seadowg/view-finalized-forms
Browse files Browse the repository at this point in the history
Allow viewing finalized forms in "Ready to send"
  • Loading branch information
grzesiek2010 authored Jun 8, 2023
2 parents 8babf2c + d9a36da commit 3f5ab8e
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.odk.collect.androidshared.ui

import android.widget.Button
import androidx.lifecycle.ViewModel
import org.odk.collect.androidshared.R
import org.odk.collect.androidshared.livedata.MutableNonNullLiveData
import org.odk.collect.androidshared.livedata.NonNullLiveData

Expand Down Expand Up @@ -32,3 +34,15 @@ class MultiSelectViewModel : ViewModel() {
}
}
}

fun updateSelectAll(button: Button, itemCount: Int, selectedCount: Int): Boolean {
val allSelected = itemCount > 0 && selectedCount == itemCount

if (allSelected) {
button.setText(R.string.clear_all)
} else {
button.setText(R.string.select_all)
}

return allSelected
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void instanceOfEncryptedForm_cantBeViewedAfterSending() {
.clickFinalize()

.clickSendFinalizedForm(1)
.clickOnForm("encrypted")
.clickSelectAll()
.clickSendSelected()
.clickOK(new SendFinalizedFormPage())
.pressBack(new MainMenuPage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.odk.collect.android.R
import org.odk.collect.android.support.pages.AccessControlPage
import org.odk.collect.android.support.pages.FormEntryPage
import org.odk.collect.android.support.pages.MainMenuPage
import org.odk.collect.android.support.pages.ProjectSettingsPage
import org.odk.collect.android.support.pages.SaveOrDiscardFormDialog
Expand All @@ -21,27 +22,26 @@ class FormFinalizingTest {
val copyFormChain: RuleChain = chain().around(rule)

@Test
fun fillingForm_andPressingSaveAsDraft_doesNotFinalizesForm() {
fun fillingForm_andPressingFinalize_finalizesForm() {
rule.startAtMainMenu()
.copyForm(FORM)
.assertNumberOfFinalizedForms(0)
.startBlankForm("One Question")
.swipeToEndScreen()
.clickSaveAsDraft()
.assertNumberOfEditableForms(1)
.assertNumberOfFinalizedForms(0)
.fillOutAndFinalize(FormEntryPage.QuestionAndAnswer("what is your age", "52"))
.assertNumberOfEditableForms(0)
.assertNumberOfFinalizedForms(1)
}

@Test
fun fillingForm_andPressingFinalize_finalizesForm() {
fun fillingForm_andPressingSaveAsDraft_doesNotFinalizesForm() {
rule.startAtMainMenu()
.copyForm(FORM)
.assertNumberOfFinalizedForms(0)
.startBlankForm("One Question")
.swipeToEndScreen()
.clickFinalize()
.assertNumberOfEditableForms(0)
.assertNumberOfFinalizedForms(1)
.clickSaveAsDraft()
.assertNumberOfEditableForms(1)
.assertNumberOfFinalizedForms(0)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void whenSubmissionSucceeds_instanceNotEditable() {
.clickFinalize()

.clickSendFinalizedForm(1)
.clickOnForm("One Question")
.clickSelectAll()
.clickSendSelected()
.clickOK(new SendFinalizedFormPage())
.pressBack(new MainMenuPage())
Expand Down Expand Up @@ -62,7 +62,7 @@ public void whenSubmissionFails_instanceNotEditable() {
.clickFinalize()

.clickSendFinalizedForm(1)
.clickOnForm("One Question")
.clickSelectAll()
.clickSendSelected()
.clickOK(new SendFinalizedFormPage())
.pressBack(new MainMenuPage())
Expand Down

This file was deleted.

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

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.CollectHelpers.addGDProject
import org.odk.collect.android.support.TestDependencies
import org.odk.collect.android.support.pages.FormEntryPage.QuestionAndAnswer
import org.odk.collect.android.support.pages.MainMenuPage
import org.odk.collect.android.support.pages.OkDialog
import org.odk.collect.android.support.pages.ProjectSettingsPage
import org.odk.collect.android.support.pages.SendFinalizedFormPage
import org.odk.collect.android.support.rules.CollectTestRule
import org.odk.collect.android.support.rules.TestRuleChain.chain
import org.odk.collect.androidtest.RecordedIntentsRule
import org.odk.collect.projects.Project.New

@RunWith(AndroidJUnit4::class)
class SendFinalizedFormTest {

private val testDependencies = TestDependencies()
private val rule = CollectTestRule(useDemoProject = false)

@get:Rule
val chain: RuleChain = chain(testDependencies)
.around(RecordedIntentsRule())
.around(rule)

@Test
fun canViewFormsBeforeSending() {
rule.withProject(testDependencies.server.url)
.copyForm("one-question.xml", projectName = testDependencies.server.hostName)
.startBlankForm("One Question")
.fillOutAndFinalize(QuestionAndAnswer("what is your age", "52"))
.clickSendFinalizedForm(1)
.clickOnForm("One Question")
.assertText("52")
}

@Test
fun whenThereIsAnAuthenticationError_allowsUserToReenterCredentials() {
testDependencies.server.setCredentials("Draymond", "Green")
rule.withProject(testDependencies.server.url)
.copyForm("one-question.xml", projectName = testDependencies.server.hostName)
.startBlankForm("One Question")
.answerQuestion("what is your age", "123")
.swipeToEndScreen()
.clickFinalize()
.clickSendFinalizedForm(1)
.clickSelectAll()
.clickSendSelectedWithAuthenticationError()
.fillUsername("Draymond")
.fillPassword("Green")
.clickOK(OkDialog())
.assertText("One Question - Success")
}

@Test
fun canViewSentForms() {
rule.withProject(testDependencies.server.url)
.copyForm("one-question.xml", projectName = testDependencies.server.hostName)
.startBlankForm("One Question")
.answerQuestion("what is your age", "123")
.swipeToEndScreen()
.clickFinalize()
.clickSendFinalizedForm(1)
.clickSelectAll()
.clickSendSelected()
.clickOK(SendFinalizedFormPage())
.pressBack(MainMenuPage())
.clickViewSentForm(1)
.clickOnForm("One Question")
.assertText("123")
.assertText(R.string.exit)
}

@Test
fun canSendIndividualForms() {
rule.withProject(testDependencies.server.url)
.copyForm("one-question.xml", projectName = testDependencies.server.hostName)
.startBlankForm("One Question")
.fillOutAndFinalize(QuestionAndAnswer("what is your age", "123"))
.startBlankForm("One Question")
.fillOutAndFinalize(QuestionAndAnswer("what is your age", "124"))

.clickSendFinalizedForm(2)
.selectForm(0)
.clickSendSelected()
.clickOK(SendFinalizedFormPage())
.pressBack(MainMenuPage())

.assertNumberOfFinalizedForms(1)
.clickViewSentForm(1)
.clickOnForm("One Question")
.assertText("123")
}

@Test
fun whenDeleteAfterSendIsEnabled_deletesFilledForm() {
rule.withProject(testDependencies.server.url)
.openProjectSettingsDialog()
.clickSettings()
.clickFormManagement()
.scrollToRecyclerViewItemAndClickText(R.string.delete_after_send)
.pressBack(ProjectSettingsPage())
.pressBack(MainMenuPage())
.copyForm("one-question.xml", projectName = testDependencies.server.hostName)
.startBlankForm("One Question")
.answerQuestion("what is your age", "123")
.swipeToEndScreen()
.clickFinalize()
.clickSendFinalizedForm(1)
.clickSelectAll()
.clickSendSelected()
.clickOK(SendFinalizedFormPage())
.pressBack(MainMenuPage())
.clickViewSentForm(1)
.clickOnText("One Question")
.assertOnPage()
}

@Test
fun whenGoogleUsedAsServer_sendsSubmissionToSheet() {
addGDProject(
New(
"GD Project",
"G",
"#3e9fcc"
),
"[email protected]",
testDependencies
)

rule.startAtFirstLaunch()
.clickTryCollect()
.openProjectSettingsDialog()
.selectProject("GD Project")
.copyForm("one-question-google.xml", null, false, "GD Project")
.startBlankForm("One Question Google")
.answerQuestion("what is your age", "47")
.swipeToEndScreen()
.clickFinalize()
.clickSendFinalizedForm(1)
.clickSelectAll()
.clickSendSelected()
.assertText("One Question Google - Success")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void canGetBlankForm_fillItIn_andSubmit() {

// Send form
.clickSendFinalizedForm(1)
.clickOnForm("One Question")
.clickSelectAll()
.clickSendSelected()
.assertText("One Question - Success")
.clickOK(new SendFinalizedFormPage())
Expand Down
Loading

0 comments on commit 3f5ab8e

Please sign in to comment.