From 41f1195c4b0b6e02924fcf4e90a9d56d0c2d933c Mon Sep 17 00:00:00 2001 From: Rd Date: Tue, 1 Oct 2024 02:24:26 +0530 Subject: [PATCH] Added/Verified Espresso Tests - bumped Mockitor to 3.11.1 --- app/build.gradle | 6 +- .../app/player/state/StateFragmentTest.kt | 106 +++++++++++++++++- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7c94678f75c..c38647da28b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -198,7 +198,7 @@ dependencies { "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version", 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4', 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4', - 'org.mockito:mockito-core:2.7.22', + 'org.mockito:mockito-core:3.11.1', 'com.github.oppia:android-spotlight:cc23499d37dc8533a2876e45b5063e981a4583f4' ) compileOnly( @@ -222,7 +222,7 @@ dependencies { 'org.robolectric:robolectric:4.5', 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4', "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version", - 'org.mockito:mockito-core:2.7.22', + 'org.mockito:mockito-core:3.11.1', project(":testing"), ) androidTestImplementation( @@ -238,7 +238,7 @@ dependencies { 'androidx.work:work-testing:2.4.0', 'com.google.truth.extensions:truth-liteproto-extension:1.1.3', 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4', - 'org.mockito:mockito-android:2.7.22', + 'org.mockito:mockito-android:3.11.1', 'org.robolectric:annotations:4.5', ) // Adding the testing module directly causes duplicates of the below groups so we need to diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt index 85954cf693e..4f7ac99fc71 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt @@ -1327,6 +1327,80 @@ class StateFragmentTest { } } + @Test + @RunOn(TestPlatform.ESPRESSO) // TODO(#1612): Enable for Robolectric. + fun testStateFragment_loadDragDropExp_wrongAnswer_retainsLatestState() { + setUpTestWithLanguageSwitchingFeatureOff() + launchForExploration(TEST_EXPLORATION_ID_2, shouldSavePartialProgress = false).use { + startPlayingExploration() + playThroughPrototypeState1() + playThroughPrototypeState2() + playThroughPrototypeState3() + playThroughPrototypeState4() + playThroughPrototypeState5() + playThroughPrototypeState6() + playThroughPrototypeState7() + playThroughPrototypeState8() + + // Drag and drop interaction without grouping. + // Ninth state: Drag Drop Sort. Wrong answer: Move 1st item to 2nd position. + dragAndDropItem(fromPosition = 0, toPosition = 1) + clickSubmitAnswerButton() + + scrollToViewType(DRAG_DROP_SORT_INTERACTION) + onView( + atPositionOnView( + recyclerViewId = R.id.drag_drop_interaction_recycler_view, + position = 0, + targetViewId = R.id.drag_drop_content_text_view + ) + ).check(matches(withText("3/5"))) + onView( + atPositionOnView( + recyclerViewId = R.id.drag_drop_interaction_recycler_view, + position = 1, + targetViewId = R.id.drag_drop_content_text_view + ) + ).check(matches(withText("0.35"))) + } + } + + @Test + @RunOn(TestPlatform.ESPRESSO) // TODO(#1612): Enable for Robolectric. + fun testStateFragment_loadDragDropExp_wrongAnswer_unArrangedRetainState_causeSubmitTimeError() { + setUpTestWithLanguageSwitchingFeatureOff() + launchForExploration(TEST_EXPLORATION_ID_2, shouldSavePartialProgress = false).use { + startPlayingExploration() + playThroughPrototypeState1() + playThroughPrototypeState2() + playThroughPrototypeState3() + playThroughPrototypeState4() + playThroughPrototypeState5() + playThroughPrototypeState6() + playThroughPrototypeState7() + playThroughPrototypeState8() + + // Drag and drop interaction without grouping. + // Ninth state: Drag Drop Sort. Wrong answer: Move 1st item to 2nd position. + dragAndDropItem(fromPosition = 0, toPosition = 1) + clickSubmitAnswerButton() + + scrollToViewType(DRAG_DROP_SORT_INTERACTION) + onView( + atPositionOnView( + recyclerViewId = R.id.drag_drop_interaction_recycler_view, + position = 0, + targetViewId = R.id.drag_drop_content_text_view + ) + ).check(matches(withText("3/5"))) + clickSubmitAnswerButton() + + onView(withId(R.id.drag_drop_interaction_error)).check( + matches(withText(R.string.drag_and_drop_interaction_empty_input)) + ) + } + } + @Test fun testStateFragment_loadDragDropExp_mergeFirstTwoItems_wrongAnswer_retainsLatestStateCount() { setUpTestWithLanguageSwitchingFeatureOff() @@ -1398,14 +1472,44 @@ class StateFragmentTest { } @Test - fun testStateFragment_loadDragDropExp_mergeItems_unArrangedRetainState_causeSubmitTimeError() { + @RunOn(TestPlatform.ESPRESSO) // TODO(#1612): Enable for Robolectric. + fun testStateFragment_loadDragDropExp_mergeItems_dragItem_wrongAnswer_retainsLatestState() { setUpTestWithLanguageSwitchingFeatureOff() launchForExploration(TEST_EXPLORATION_ID_4, shouldSavePartialProgress = false).use { startPlayingExploration() mergeDragAndDropItems(position = 0) + dragAndDropItem(fromPosition = 0, toPosition = 2) + clickSubmitAnswerButton() + scrollToViewType(DRAG_DROP_SORT_INTERACTION) + onView( + atPositionOnView( + recyclerViewId = R.id.drag_drop_interaction_recycler_view, + position = 2, + targetViewId = R.id.drag_drop_content_text_view + ) + ).check(matches(withText("a camera at the store"))) + } + } + + @Test + fun testStateFragment_loadDragDropExp_mergeItems_unArrangedRetainState_causeSubmitTimeError() { + setUpTestWithLanguageSwitchingFeatureOff() + launchForExploration(TEST_EXPLORATION_ID_4, shouldSavePartialProgress = false).use { + startPlayingExploration() + + mergeDragAndDropItems(position = 0) clickSubmitAnswerButton() + + scrollToViewType(DRAG_DROP_SORT_INTERACTION) + onView( + atPositionOnView( + recyclerViewId = R.id.drag_drop_item_recyclerview, + position = 0, + targetViewId = R.id.drag_drop_content_text_view + ) + ).check(matches(withText("a camera at the store"))) clickSubmitAnswerButton() onView(withId(R.id.drag_drop_interaction_error)).check(