Skip to content

Commit

Permalink
Add tests for oppia#4186.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGitonga committed Jul 6, 2022
1 parent 11fac48 commit 8882088
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ dependencies {
'androidx.test.ext:junit:1.1.1',
'com.github.bumptech.glide:mocks:4.11.0',
'com.google.truth:truth:1.1.3',
'androidx.work:work-testing:2.4.0',
'com.google.truth.extensions:truth-liteproto-extension:1.1.3',
'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2',
'org.mockito:mockito-android:2.7.22',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand Down Expand Up @@ -422,6 +423,58 @@ class MarkChaptersCompletedFragmentTest {
}
}

@Test
fun testMarkChaptersCompletedFragment_unSelectAll_unSelectsAllChapters() {
launch<MarkChaptersCompletedTestActivity>(
createMarkChaptersCompletedTestActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.mark_chapters_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 1)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 3)
scrollToPosition(position = 5)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 5)
scrollToPosition(position = 7)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 7)
scrollToPosition(position = 8)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 8)
scrollToPosition(position = 10)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 10)
scrollToPosition(position = 11)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 11)
scrollToPosition(position = 13)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 13)
scrollToPosition(position = 14)
verifyItemCheckedOnRecyclerViewItemAtPosition(itemPosition = 14)
onView(withId(R.id.mark_chapters_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 1)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 3)
scrollToPosition(position = 5)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 5)
scrollToPosition(position = 7)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 7)
scrollToPosition(position = 8)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 8)
scrollToPosition(position = 10)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 10)
scrollToPosition(position = 11)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 11)
scrollToPosition(position = 13)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 13)
scrollToPosition(position = 14)
verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition = 14)
println("asserts completed")
}
}

@Test
fun testMarkChaptersCompletedFragment_selectAll_configChange_selectsAllChapters() {
launch<MarkChaptersCompletedTestActivity>(
Expand Down Expand Up @@ -868,6 +921,16 @@ class MarkChaptersCompletedFragmentTest {
).check(matches(isChecked()))
}

private fun verifyItemUnCheckedOnRecyclerViewItemAtPosition(itemPosition: Int) {
onView(
atPositionOnView(
recyclerViewId = R.id.mark_chapters_completed_recycler_view,
position = itemPosition,
targetViewId = R.id.mark_chapters_completed_chapter_check_box
)
).check(matches(isNotChecked()))
}

private fun markFractionsFirstChapterCompleted() {
storyProgressTestHelper.markCompletedFractionsStory0Exp0(
profileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand Down Expand Up @@ -263,6 +264,37 @@ class MarkStoriesCompletedFragmentTest {
}
}

@Test
fun testMarkStoriesCompletedFragment_unSelectAll_unSelectsAllStories() {
launch<MarkStoriesCompletedTestActivity>(
createMarkStoriesCompletedTestActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.mark_stories_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 0)
verifyItemCheckedOnStorySummaryListItem(itemPosition = 0)
scrollToPosition(position = 1)
verifyItemCheckedOnStorySummaryListItem(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemCheckedOnStorySummaryListItem(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemCheckedOnStorySummaryListItem(itemPosition = 3)
scrollToPosition(position = 4)
verifyItemCheckedOnStorySummaryListItem(itemPosition = 4)
onView(withId(R.id.mark_stories_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 0)
verifyItemUnCheckedOnStorySummaryListItem(itemPosition = 0)
scrollToPosition(position = 1)
verifyItemUnCheckedOnStorySummaryListItem(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemUnCheckedOnStorySummaryListItem(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemUnCheckedOnStorySummaryListItem(itemPosition = 3)
scrollToPosition(position = 4)
verifyItemUnCheckedOnStorySummaryListItem(itemPosition = 4)
}
}

@Test
fun testMarkStoriesCompletedFragment_selectAll_configChange_selectsAllStories() {
launch<MarkStoriesCompletedTestActivity>(
Expand Down Expand Up @@ -535,6 +567,16 @@ class MarkStoriesCompletedFragmentTest {
).check(matches(isChecked()))
}

private fun verifyItemUnCheckedOnStorySummaryListItem(itemPosition: Int) {
onView(
atPositionOnView(
recyclerViewId = R.id.mark_stories_completed_recycler_view,
position = itemPosition,
targetViewId = R.id.mark_stories_completed_story_check_box
)
).check(matches(isNotChecked()))
}

private fun performItemCheckOnStorySummaryListItem(itemPosition: Int) {
onView(
atPositionOnView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand Down Expand Up @@ -339,6 +340,33 @@ class MarkTopicsCompletedFragmentTest {
}
}

@Test
fun testMarkTopicsCompletedFragment_unSelectAllTopics_unSelectsAllTopics() {
launch<MarkTopicsCompletedTestActivity>(
createMarkTopicsCompletedTestActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
onView(withId(R.id.mark_topics_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 0)
verifyItemCheckedOnTopicSummaryListItem(itemPosition = 0)
scrollToPosition(position = 1)
verifyItemCheckedOnTopicSummaryListItem(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemCheckedOnTopicSummaryListItem(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemCheckedOnTopicSummaryListItem(itemPosition = 3)
onView(withId(R.id.mark_topics_completed_all_check_box_container)).perform(click())
scrollToPosition(position = 0)
verifyItemUnCheckedOnTopicSummaryListItem(itemPosition = 0)
scrollToPosition(position = 1)
verifyItemUnCheckedOnTopicSummaryListItem(itemPosition = 1)
scrollToPosition(position = 2)
verifyItemUnCheckedOnTopicSummaryListItem(itemPosition = 2)
scrollToPosition(position = 3)
verifyItemUnCheckedOnTopicSummaryListItem(itemPosition = 3)
}
}

@Test
fun testMarkTopicsCompletedFragment_selectAllTopics_configChange_allCheckBoxIsChecked() {
launch<MarkTopicsCompletedTestActivity>(
Expand Down Expand Up @@ -505,6 +533,16 @@ class MarkTopicsCompletedFragmentTest {
).check(matches(isChecked()))
}

private fun verifyItemUnCheckedOnTopicSummaryListItem(itemPosition: Int) {
onView(
atPositionOnView(
recyclerViewId = R.id.mark_topics_completed_recycler_view,
position = itemPosition,
targetViewId = R.id.mark_topics_completed_topic_check_box
)
).check(matches(isNotChecked()))
}

private fun performItemCheckOnTopicSummaryListItem(itemPosition: Int) {
onView(
atPositionOnView(
Expand Down

0 comments on commit 8882088

Please sign in to comment.