Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
A1shK committed Feb 24, 2025
1 parent bf2e99d commit 41fc4b4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package com.intuit.playerui.android.reference.demo.test

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import com.intuit.playerui.android.reference.demo.test.base.PerformanceTest
import com.intuit.playerui.android.reference.demo.test.base.waitForViewInRoot
import com.intuit.playerui.android.reference.demo.ui.main.MainActivity
import org.hamcrest.Matchers.allOf
import org.junit.Rule
import org.junit.Test

class MainActivityTest : PerformanceTest<MainActivity> {

@get:Rule override val activityRule = activityScenarioRule<MainActivity>()

@get:Rule
val androidComposeRule = createAndroidComposeRule<MainActivity>()

@Test
fun verifyDefault() {
waitForViewInRoot(withText("Android Reference Assets"))
.check(matches(isDisplayed()))

onView(
allOf(
withText("Random Mock"),
),
).perform(click())
androidComposeRule.onNodeWithTag("action")
.performClick()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import com.intuit.playerui.android.reference.demo.test.base.ComposeUITest
import com.intuit.playerui.android.reference.demo.test.base.shouldBePlayerState
import com.intuit.playerui.android.reference.demo.test.base.waitForViewInRoot
import com.intuit.playerui.core.player.state.CompletedState
import com.intuit.playerui.core.player.state.ErrorState
import com.intuit.playerui.core.player.state.InProgressState
import com.intuit.playerui.core.player.state.dataModel
Expand Down Expand Up @@ -45,6 +46,9 @@ class ActionUITest : ComposeUITest("action") {
.check(matches(isDisplayed()))
androidComposeRule.onAllNodesWithTag("action").get(0)
.performClick()
player.state.shouldBePlayerState<CompletedState> {
assertEquals("done", endState.outcome)
}
}

@Test
Expand All @@ -56,7 +60,7 @@ class ActionUITest : ComposeUITest("action") {
androidComposeRule.onAllNodesWithTag("action").get(1)
.performClick()
delay(2000)
currentState.shouldBePlayerState<ErrorState> {
player.state.shouldBePlayerState<ErrorState> {
assertEquals("Error: Unclosed brace after \"foo.bar..}\" at character 12", error.message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.intuit.playerui.android.reference.demo.test.assets.info

import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.performClick
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand All @@ -27,8 +26,6 @@ class InfoUITest : ComposeUITest("info") {
verifyView(view)

action?.let {
onView(withText(action.name))
.check(matches(isDisplayed()))
androidComposeRule.onAllNodesWithTag("action").get(index ?: 0)
.performClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class AssetUITest(val group: String? = null) {
protected lateinit var viewModel: MainViewModel

protected lateinit var playerViewModel: DemoPlayerViewModel
protected val player get() = playerViewModel.player

protected val currentState: PlayerFlowState? get() = playerViewModel.playerFlowState.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intuit.playerui.core.player.state.CompletedState
import com.intuit.playerui.core.player.state.ErrorState
import com.intuit.playerui.core.player.state.InProgressState
import com.intuit.playerui.core.player.state.dataModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
Expand Down Expand Up @@ -45,9 +46,10 @@ class ActionTest : AssetTest("action") {
data.run()
}
}
delay(1000)
}

currentState.shouldBePlayerState<CompletedState> {
player.state.shouldBePlayerState<CompletedState> {
assertEquals("done", endState.outcome)
}
}
Expand All @@ -69,7 +71,7 @@ class ActionTest : AssetTest("action") {
}
}

currentState.shouldBePlayerState<ErrorState> {
player.state.shouldBePlayerState<ErrorState> {
assertEquals("Error: Unclosed brace after \"foo.bar..}\" at character 12", error.message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.widget.TextView
import androidx.core.view.get
import com.intuit.playerui.android.reference.assets.R
import com.intuit.playerui.android.reference.assets.action.Action
import com.intuit.playerui.android.reference.assets.text.Text
import com.intuit.playerui.android.testutils.asset.AssetTest
import com.intuit.playerui.android.testutils.asset.shouldBeAsset
import com.intuit.playerui.android.testutils.asset.shouldBePlayerState
Expand All @@ -32,13 +31,12 @@ class InfoTest : AssetTest("info") {

runTest {
currentAssetTree.shouldBeAsset<Info> {
val infoActions = data.actions
val infoActions = getData().actions

action?.let {
val buttonOrdinal = if (action.ordinal != 1) 0 else action.ordinal
infoActions[buttonOrdinal].shouldBeAsset<Action> {
val data = getData()
data.label.shouldBeAsset<Text>()
data.run()
}
}
Expand Down

0 comments on commit 41fc4b4

Please sign in to comment.