Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
A1shK committed Dec 1, 2024
1 parent de0e73c commit f44ae2f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.intuit.playerui.android.reference.assets.action

import android.widget.Button
import android.widget.LinearLayout
import androidx.core.view.get
import com.intuit.playerui.android.reference.assets.R
import com.intuit.playerui.android.reference.assets.collection.Collection
import com.intuit.playerui.android.reference.assets.test.AssetTest
import com.intuit.playerui.android.reference.assets.test.shouldBeAsset
import com.intuit.playerui.android.reference.assets.test.shouldBePlayerState
Expand All @@ -13,11 +12,11 @@ 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.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

class ActionTest : AssetTest("action") {

@Test
fun actionExpression() {
launchMock("action-basic")
Expand Down Expand Up @@ -45,13 +44,16 @@ class ActionTest : AssetTest("action") {
fun transitionToEndSuccess() {
launchMock("action-transition-to-end")

val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
assertEquals(2, collectionValues.childCount)

collectionValues[0].shouldBeView<Button> {
assertEquals("End the flow (success)", text.toString())
performClick()
blockUntilRendered()
runTest {
currentAssetTree.shouldBeAsset<Collection> {
getData().values[0].shouldBeAsset<Action> {
val data = getData()
data.label.shouldBeAsset<Text> {
assertEquals("End the flow (success)", getData().value)
}
data.run()
}
}
}

currentState.shouldBePlayerState<CompletedState> {
Expand All @@ -64,13 +66,16 @@ class ActionTest : AssetTest("action") {
fun transitionToEndError() {
launchMock("action-transition-to-end")

val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
assertEquals(2, collectionValues.childCount)

collectionValues[1].shouldBeView<Button> {
assertEquals("End the flow (error)", text.toString())
performClick()
blockUntilRendered()
runTest {
currentAssetTree.shouldBeAsset<Collection> {
getData().values[1].shouldBeAsset<Action> {
val data = getData()
data.label.shouldBeAsset<Text> {
assertEquals("End the flow (error)", getData().value)
}
data.run()
}
}
}

currentState.shouldBePlayerState<ErrorState> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.intuit.playerui.android.reference.assets.collection

import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.get
import com.intuit.playerui.android.reference.assets.R
import com.intuit.playerui.android.reference.assets.test.AssetTest
import com.intuit.playerui.android.reference.assets.test.shouldBeAsset
import com.intuit.playerui.android.reference.assets.test.shouldBePlayerState
import com.intuit.playerui.android.reference.assets.test.shouldBeView
import com.intuit.playerui.android.reference.assets.text.Text
import com.intuit.playerui.core.player.state.InProgressState
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

Expand All @@ -18,19 +16,23 @@ class CollectionTest : AssetTest("collection") {
fun basic() {
launchMock("collection-basic")

val collectionLabel = currentView?.findViewById<FrameLayout>(R.id.collection_label) ?: throw AssertionError("current view is null")
val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
runTest {
currentAssetTree.shouldBeAsset<Collection> {
val data = getData()
data.label.shouldBeAsset<Text> {
assertEquals("Collections are used to group assets.", getData().value)
}

collectionLabel[0].shouldBeView<TextView> {
assertEquals("Collections are used to group assets.", text.toString())
}

collectionValues[0].shouldBeView<TextView> {
assertEquals("This is the first item in the collection", text.toString())
}
val values = data.values
assertEquals(2, values.size)
values[0].shouldBeAsset<Text> {
assertEquals("This is the first item in the collection", getData().value)
}

collectionValues[1].shouldBeView<TextView> {
assertEquals("This is the second item in the collection", text.toString())
values[1].shouldBeAsset<Text> {
assertEquals("This is the second item in the collection", getData().value)
}
}
}
currentState.shouldBePlayerState<InProgressState>()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.intuit.playerui.android.reference.assets.text

import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.get
import com.intuit.playerui.android.reference.assets.R
import com.intuit.playerui.android.reference.assets.collection.Collection
import com.intuit.playerui.android.reference.assets.test.AssetTest
import com.intuit.playerui.android.reference.assets.test.shouldBeAsset
import com.intuit.playerui.android.reference.assets.test.shouldBeView
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

Expand All @@ -15,13 +16,20 @@ class TextTest : AssetTest("text") {
fun basic() {
launchMock("text-basic")

val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
collectionValues[0].shouldBeView<TextView> {
assertEquals("This is some text", text.toString())
}
runTest {
currentAssetTree.shouldBeAsset<Collection> {
val data = getData()

val values = data.values
assertEquals(2, values.size)
values[0].shouldBeAsset<Text> {
assertEquals("This is some text", getData().value)
}

collectionValues[1].shouldBeView<TextView> {
assertEquals("This is some text that is a link", text.toString())
values[1].shouldBeAsset<Text> {
assertEquals("This is some text that is a link", getData().value)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ class Collection(assetContext: AssetContext) : ComposableAsset<Collection.Data>(
}
Column(modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
data.values.map {
it.compose(androidViewAttributes = AndroidViewAttributes(
modifier = Modifier.fillMaxWidth()
))
it.compose(
androidViewAttributes = AndroidViewAttributes(
modifier = Modifier.fillMaxWidth(),
),
)
}
}
}
Expand Down

0 comments on commit f44ae2f

Please sign in to comment.