From d064a812ac9e4bd4d8c0cb36c50e46e49e6d9f9e Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sat, 16 Mar 2024 22:36:52 +0100 Subject: [PATCH 1/4] Improved tests --- .../feature/formentry/audit/IdentifyUserTest.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/audit/IdentifyUserTest.kt b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/audit/IdentifyUserTest.kt index fdbe574486f..3bcf72aa3a1 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/audit/IdentifyUserTest.kt +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/audit/IdentifyUserTest.kt @@ -7,6 +7,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain import org.junit.runner.RunWith +import org.odk.collect.android.support.StorageUtils import org.odk.collect.android.support.StorageUtils.getAuditLogForFirstInstance import org.odk.collect.android.support.pages.FormEntryPage import org.odk.collect.android.support.pages.FormHierarchyPage @@ -14,6 +15,7 @@ import org.odk.collect.android.support.pages.IdentifyUserPromptPage import org.odk.collect.android.support.pages.MainMenuPage import org.odk.collect.android.support.rules.CollectTestRule import org.odk.collect.android.support.rules.TestRuleChain +import java.io.File import java.io.IOException @RunWith(AndroidJUnit4::class) @@ -78,13 +80,15 @@ class IdentifyUserTest { } @Test - fun openingForm_andPressingBack_returnsToMainMenu() { + fun openingForm_andPressingBack_returnsToMainMenuAndDoesNotLeaveAnEmptyInstanceDir() { rule.startAtMainMenu() .copyForm(IDENTIFY_USER_AUDIT_FORM) .clickFillBlankForm() .clickOnFormWithIdentityPrompt("Identify User") .closeSoftKeyboard() .pressBack(MainMenuPage()) + + assertThat(File(StorageUtils.getInstancesDirPath()).listFiles().size, equalTo(0)) } @Test @@ -110,12 +114,14 @@ class IdentifyUserTest { } @Test - fun openingForm_andPressingCloseCross_returnsToMainMenu() { + fun openingForm_andPressingCloseCross_returnsToMainMenuAndDoesNotLeaveAnEmptyInstanceDir() { rule.startAtMainMenu() .copyForm(IDENTIFY_USER_AUDIT_FORM) .clickFillBlankForm() .clickOnFormWithIdentityPrompt("Identify User") .pressClose() + + assertThat(File(StorageUtils.getInstancesDirPath()).listFiles().size, equalTo(0)) } @Test From 8b870f376afd3229a118ae57978bd2ff0ae8273a Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sat, 16 Mar 2024 22:02:40 +0100 Subject: [PATCH 2/4] Remove the empty instance folder when exiting the identity dialog --- .../collect/android/activities/FormFillingActivity.java | 1 + .../android/formentry/audit/IdentityPromptViewModel.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java index 0c4c3b09462..dd3c8046fb8 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java @@ -558,6 +558,7 @@ private void setupViewModels(FormEntryViewModelFactory formEntryViewModelFactory identityPromptViewModel.isFormEntryCancelled().observe(this, isFormEntryCancelled -> { if (isFormEntryCancelled) { + identityPromptViewModel.exit(); exit(); } }); diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModel.java b/collect_app/src/main/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModel.java index 34b0a61ffaa..c1cc079fc9b 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModel.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModel.java @@ -9,6 +9,7 @@ import androidx.lifecycle.ViewModel; import org.odk.collect.android.javarosawrapper.FormController; +import org.odk.collect.android.utilities.FileUtils; public class IdentityPromptViewModel extends ViewModel { @@ -20,6 +21,7 @@ public class IdentityPromptViewModel extends ViewModel { private String identity = ""; private String formName; + private String instanceFolder; public IdentityPromptViewModel() { updateRequiresIdentity(); @@ -28,6 +30,7 @@ public IdentityPromptViewModel() { public void formLoaded(@NonNull FormController formController) { this.formName = formController.getFormTitle(); this.auditEventLogger = formController.getAuditEventLogger(); + this.instanceFolder = formController.getInstanceFile().getParent(); updateRequiresIdentity(); } @@ -72,4 +75,8 @@ private static boolean userIsValid(String user) { public String getFormTitle() { return formName; } + + public void exit() { + FileUtils.purgeMediaPath(instanceFolder); + } } From 583d71bf6da096e89b4eab66b80bbd21bcf7b374 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 23 Apr 2024 21:16:03 +0200 Subject: [PATCH 3/4] Fixed IdentityPromptViewModelTest --- .../formentry/audit/IdentityPromptViewModelTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/collect_app/src/test/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModelTest.java b/collect_app/src/test/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModelTest.java index 760c927cd1f..a020e1392a7 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModelTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/formentry/audit/IdentityPromptViewModelTest.java @@ -10,14 +10,18 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; + @RunWith(AndroidJUnit4.class) public class IdentityPromptViewModelTest { @Test - public void done_setsUserOnAuditEventLogger() { + public void done_setsUserOnAuditEventLogger() throws IOException { FormController formController = mock(FormController.class); AuditEventLogger auditEventLogger = mock(AuditEventLogger.class); when(formController.getAuditEventLogger()).thenReturn(auditEventLogger); + when(formController.getInstanceFile()).thenReturn(File.createTempFile("instance", ".xml")); IdentityPromptViewModel viewModel = new IdentityPromptViewModel(); From 7f3f9400dca0e075bf402d98334687b29cec928e Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Mon, 18 Nov 2024 14:48:55 +0100 Subject: [PATCH 4/4] Test --- .circleci/config.yml | 2 +- download-robolectric-deps.sh | 1 - robolectric-deps.properties | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4dcfbbfe222..1e8690caa19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,7 @@ jobs: - run: name: Run module unit tests command: | - ./gradlew $(cat .circleci/fork_test_modules.txt | awk '{for (i=1; i<=NF; i++) printf "%s:testDebug ",$i}') + ./gradlew $(cat .circleci/fork_test_modules.txt | awk '{for (i=1; i<=NF; i++) printf "%s:testDebug --info ",$i}') - store_test_results: path: collect_app/build/test-results diff --git a/download-robolectric-deps.sh b/download-robolectric-deps.sh index 880a7f85204..2201c094226 100755 --- a/download-robolectric-deps.sh +++ b/download-robolectric-deps.sh @@ -5,7 +5,6 @@ wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all-instrumented wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all-instrumented/12.1-robolectric-8229987-i6/android-all-instrumented-12.1-robolectric-8229987-i6.jar -P robolectric-deps wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all-instrumented/13-robolectric-9030017-i6/android-all-instrumented-13-robolectric-9030017-i6.jar -P robolectric-deps wget -nc https://repo1.maven.org/maven2/org/robolectric/android-all-instrumented/14-robolectric-10818077-i6/android-all-instrumented-14-robolectric-10818077-i6.jar -P robolectric-deps - dest_dir="src/test/resources" mkdir -p collect_app/$dest_dir && cp robolectric-deps.properties collect_app/$dest_dir mkdir -p audiorecorder/$dest_dir && cp robolectric-deps.properties audiorecorder/$dest_dir diff --git a/robolectric-deps.properties b/robolectric-deps.properties index fcb10195bfe..622fa250a2a 100644 --- a/robolectric-deps.properties +++ b/robolectric-deps.properties @@ -1,5 +1,5 @@ org.robolectric\:android-all-instrumented\:6.0.1_r3-robolectric-r1-i6=../../../../../../robolectric-deps/android-all-instrumented-6.0.1_r3-robolectric-r1-i6.jar org.robolectric\:android-all-instrumented\:7.0.0_r1-robolectric-r1-i6=../../../../../../robolectric-deps/android-all-instrumented-7.0.0_r1-robolectric-r1-i6.jar org.robolectric\:android-all-instrumented\:12.1-robolectric-8229987-i6=../../../../../../robolectric-deps/android-all-instrumented-12.1-robolectric-8229987-i6.jar -org.robolectric\:android-all-instrumented\:13-robolectric-9030017-i6=../../../../../../robolectric-deps/android-all-instrumented-13-robolectric-9030017-i6.jar -org.robolectric\:android-all-instrumented\:14-robolectric-10818077-i6=../../../../../../robolectric-deps/android-all-instrumented-14-robolectric-10818077-i6.jar +org.robolectric\:android-all-instrumented\:13-robolectric-9030017-i6=../../../../../../robolectric-depss/android-all-instrumented-13-robolectric-9030017-i6.jar +org.robolectric\:android-all-instrumented\:14-robolectric-10818077-i6=../../../../../../robolectric-deps/android-all-instrumented-14-robolectric-10818077-i6.jar \ No newline at end of file