Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "com.lilin.gamelibrary.util.HiltTestRunner"

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())
Expand Down Expand Up @@ -193,6 +193,8 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
androidTestImplementation(libs.hilt.android.testing)
kspAndroidTest(libs.hilt.android.compiler)

debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
@file:OptIn(ExperimentalTestApi::class)

package com.lilin.gamelibrary

import androidx.compose.ui.input.key.Key
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performKeyInput
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.pressKey
import com.lilin.gamelibrary.ui.MainActivity
import com.lilin.gamelibrary.util.scrollDownUntilNodeExists
import com.lilin.gamelibrary.util.scrollRightUntilNodeExists
import com.lilin.gamelibrary.util.scrollUpUntilNodeExists
import com.lilin.gamelibrary.util.waitUntilNodeExists
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
class DiscoveryScreenNavigationTest {

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<MainActivity>()

@Before
fun setup() {
hiltRule.inject()
}

@Test
fun navigateToNewReleaseGamesFromDiscoveryScreen() {
fromDiscoveryScreenToSeeMore()

fromSeeMoreToSearchScreen()

fromSearchToFavoriteScreen()

fromFavoriteToDetail()

fromDetailToFavorite()

checkFavoriteGameAndDelete()
}

private fun fromDiscoveryScreenToSeeMore() {
composeTestRule
.waitUntilNodeExists("DiscoveryTopBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("DiscoveryLazyColumn")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("TrendingGames")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("HighRatedGames")
.performScrollTo()
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("NewReleaseGames")
.performScrollTo()
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("NewReleaseGamesSectionLazyRow")
.performScrollTo()

composeTestRule
.scrollRightUntilNodeExists(
scrollableTag = "NewReleaseGamesSectionLazyRow",
targetTag = "NewReleaseSeeMoreCard",
)
.performClick()
}

private fun fromSeeMoreToSearchScreen() {
composeTestRule
.waitUntilNodeExists("SectionDetailBottomBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("SectionDetailLazyVerticalGrid")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("ListMode")
.performClick()

composeTestRule
.waitUntilNodeExists("SectionDetailLazyColumn")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("GridMode")
.performClick()

composeTestRule
.waitUntilNodeExists("SectionDetailLazyVerticalGrid")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("BackKey")
.performClick()
}

private fun fromSearchToFavoriteScreen() {
composeTestRule
.waitUntilNodeExists("Search")
.performClick()

composeTestRule
.waitUntilNodeExists("EmptyView")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("SearchBottomBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("SearchTextField")
.apply {
performTextInput("a")
performKeyInput {
pressKey(Key.Enter)
}
}

composeTestRule
.waitUntilNodeExists("SearchResultsCompactList")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("Favorite")
.performClick()
}

private fun fromFavoriteToDetail() {
composeTestRule
.waitUntilNodeExists("FavoriteEmptyView")
.performClick()

composeTestRule
.waitUntilNodeExists("Home")
.performClick()

composeTestRule
.waitUntilNodeExists("DiscoveryTopBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("DiscoveryLazyColumn")
.assertIsDisplayed()

composeTestRule
.scrollUpUntilNodeExists(
scrollableTag = "DiscoveryLazyColumn",
targetTag = "TrendingGamesSectionLazyRow",
)
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("TrendingGameCard")

composeTestRule
.onAllNodesWithTag("TrendingGameCard")[0]
.performClick()
}

private fun fromDetailToFavorite() {
composeTestRule
.waitUntilNodeExists("GameDetailTopBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("GameDetailBottomBar")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("GameDetailSuccessContent")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("GameBackgroundImageSection")
.assertIsDisplayed()

composeTestRule
.scrollDownUntilNodeExists(
scrollableTag = "GameDetailSuccessContent",
targetTag = "GameBasicInfoSection",
)
.assertIsDisplayed()

composeTestRule
.scrollDownUntilNodeExists(
scrollableTag = "GameDetailSuccessContent",
targetTag = "GameRatingSummarySection",
)
.assertIsDisplayed()

composeTestRule
.scrollDownUntilNodeExists(
scrollableTag = "GameDetailSuccessContent",
targetTag = "GameDescriptionSection",
)
.assertIsDisplayed()

composeTestRule
.scrollDownUntilNodeExists(
scrollableTag = "GameDetailSuccessContent",
targetTag = "GameTagsSection",
)
.assertIsDisplayed()

composeTestRule
.onNodeWithTag("FavoriteButton")
.performClick()

composeTestRule
.onNodeWithTag("BackKey")
.performClick()

composeTestRule
.waitUntilNodeExists("Favorite")
.performClick()
}

private fun checkFavoriteGameAndDelete() {
composeTestRule
.waitUntilNodeExists("FavoriteGameCompactCard")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("DeleteButton")
.performClick()

composeTestRule
.waitUntilNodeExists("DeleteDialog")
.assertIsDisplayed()

composeTestRule
.waitUntilNodeExists("ConfirmDeleteButton")
.performClick()

composeTestRule
.waitUntilNodeExists("FavoriteEmptyView")
.performClick()
}
}

This file was deleted.

Loading
Loading