Skip to content

Commit

Permalink
Add test to verify the card collapse behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
theMr17 committed Jul 14, 2024
1 parent 72256a3 commit 871ff72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import org.oppia.android.app.home.classroomlist.ClassroomSummaryViewModel
/** Test tag for the classroom list. */
const val CLASSROOM_LIST_TEST_TAG = "TEST_TAG.classroom_list"

/** Test tag for the classroom card icon. */
const val CLASSROOM_CARD_ICON_TEST_TAG = "TEST_TAG.classroom_card_icon"

/** Displays a list of classroom summaries with a header. */
@Composable
fun ClassroomList(
Expand Down Expand Up @@ -108,6 +111,7 @@ fun ClassroomCard(
),
contentDescription = classroomSummaryViewModel.title,
modifier = Modifier
.testTag("${CLASSROOM_CARD_ICON_TEST_TAG}_${classroomSummaryViewModel.title}")
.padding(bottom = dimensionResource(id = R.dimen.classrooms_card_icon_padding_bottom))
.size(size = dimensionResource(id = R.dimen.classrooms_card_icon_size)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.oppia.android.app.classroom

import android.app.Application
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextContains
Expand All @@ -21,11 +20,7 @@ import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Ignore
Expand All @@ -43,6 +38,7 @@ import org.oppia.android.app.application.ApplicationModule
import org.oppia.android.app.application.ApplicationStartupListenerModule
import org.oppia.android.app.application.testing.TestingBuildFlavorModule
import org.oppia.android.app.classroom.classroomlist.ALL_CLASSROOMS_HEADER_TEST_TAG
import org.oppia.android.app.classroom.classroomlist.CLASSROOM_CARD_ICON_TEST_TAG
import org.oppia.android.app.classroom.classroomlist.CLASSROOM_LIST_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.PROMOTED_STORY_LIST_HEADER_TEST_TAG
import org.oppia.android.app.classroom.promotedlist.PROMOTED_STORY_LIST_TEST_TAG
Expand All @@ -57,6 +53,7 @@ import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionMo
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -109,7 +106,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.locale.OppiaLocale
Expand Down Expand Up @@ -664,6 +660,21 @@ class ClassroomListFragmentTest {
composeRule.onNodeWithTag(CLASSROOM_LIST_TEST_TAG).assertIsDisplayed()
}

@Test
fun testFragment_scrollToBottom_classroomListCollapsesAndSticks_classroomListIsVisible() {
composeRule.onNodeWithTag(
CLASSROOM_CARD_ICON_TEST_TAG + "_Science",
useUnmergedTree = true
).assertIsDisplayed()

composeRule.onNodeWithTag(CLASSROOM_LIST_SCREEN_TEST_TAG).performScrollToIndex(3)

composeRule.onNodeWithTag(
CLASSROOM_CARD_ICON_TEST_TAG + "_Science",
useUnmergedTree = true
).assertDoesNotExist()
}

@Test
fun testFragment_switchClassroom_topicListUpdatesCorrectly() {
// Click on Science classroom card.
Expand Down Expand Up @@ -775,20 +786,6 @@ class ClassroomListFragmentTest {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
Expand Down

0 comments on commit 871ff72

Please sign in to comment.