Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Compose assets and reference assets #537

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ _backup
.eslintcache
.next
android-tools
*.iml


# Xcode
Expand Down
31 changes: 22 additions & 9 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ rules_kotlin_extensions = use_extension(
"@rules_kotlin//src/main/starlark/core/repositories:bzlmod_setup.bzl",
"rules_kotlin_extensions",
)

# sha256 values can be found here - https://github.com/JetBrains/kotlin/releases/tag/v1.7.20
rules_kotlin_extensions.kotlinc_version(
sha256 = "9db4b467743c1aea8a21c08e1c286bc2aeb93f14c7ba2037dbd8f48adc357d83",
version = "1.7.22",
sha256 = "5e3c8d0f965410ff12e90d6f8dc5df2fc09fd595a684d514616851ce7e94ae7d",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason in particular we have to downgrade rules versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mainly due to point 5 in the PR description. This was the highest version I could stay at with the least amount of changes. I will give another combination of dependencies a shot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to upgrade to a few different versions till v1.8.20 but all such changes open a can of worms that require several other dependencies to be updated

version = "1.7.20",
)

use_repo(
rules_kotlin_extensions,
"com_github_jetbrains_kotlin",
Expand Down Expand Up @@ -144,15 +147,25 @@ maven.install(
"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0",

# Android
"androidx.databinding:viewbinding:7.2.2",
"androidx.databinding:viewbinding:8.0.0",
"androidx.annotation:annotation:1.1.0",

# Compose
"androidx.compose.ui:ui:1.2.0",
"androidx.compose.ui:ui-tooling:1.2.0",
"androidx.compose.ui:ui-test-junit4:1.2.0",
"androidx.compose.runtime:runtime:1.2.0",
"androidx.compose.runtime:runtime:1.2.0",
"androidx.compose.compiler:compiler:1.3.2",
"androidx.compose.foundation:foundation:1.2.0",
"androidx.compose.material:material:1.2.0",

# Android Demo
"androidx.navigation:navigation-runtime:2.3.3",
"androidx.navigation:navigation-ui-ktx:2.3.3",
"androidx.navigation:navigation-fragment-ktx:2.3.3",
"androidx.navigation:navigation-runtime:2.3.1",
"androidx.navigation:navigation-ui-ktx:2.3.1",
"androidx.navigation:navigation-fragment-ktx:2.3.1",
"com.afollestad.material-dialogs:core:3.3.0",
"com.google.android.material:material:1.4.0",
"com.google.android.material:material:1.6.1",

# Android Demo Testing
"androidx.test.espresso:espresso-intents:3.3.0",
Expand All @@ -172,8 +185,8 @@ maven.install(
"androidx.constraintlayout:constraintlayout:2.1.4",

# AndroidX Resolutions
"androidx.activity:activity-ktx:1.2.3",
"androidx.fragment:fragment-ktx:1.3.4",
"androidx.activity:activity-ktx:1.3.0",
"androidx.fragment:fragment-ktx:1.4.1",

# Graal
"org.graalvm.js:js:21.2.0",
Expand Down
3 changes: 1 addition & 2 deletions android/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ It's been tested on Andriod Studio Chipmunk(2021.2.1) and Android Studio Giraffe
Assuming you have read the [requirements on the root contributing guide](https://github.com/player-ui/player/blob/main/CONTRIBUTING.md).

1. Once you have Android Studio installed, you will need to go to tools->SDK Manager->SDK Platforms.
1. Make sure you have **only** the following SDK installed: Android API 32.
*If you are using Android Giraffe, you may need to click on show package details and it will be under Android12L. (Android SDK Platrform 32)*
1. Make sure you have **only** the following SDK installed: Android API 33.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed but I couldnt get it to build with API 32

2. The next step will be to make sure you have the right (and _only_ the right) SDK Build tools and NDK. Click on the SDK Tools tab and make sure you have only the following clicked:
1. 30.0.3
2. 21.4.7075529
Expand Down
1 change: 1 addition & 0 deletions android/demo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ maven_main = [
maven_test = [
"@maven//:androidx_test_espresso_espresso_intents",
"@maven//:androidx_test_ext_junit_ktx",
"@maven//:androidx_compose_ui_ui_test_junit4",
]

main_deps = maven_main + [
Expand Down
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
@@ -1,30 +1,36 @@
package com.intuit.playerui.android.reference.demo.test.assets.action

import androidx.test.espresso.action.ViewActions.click
import androidx.compose.ui.test.onAllNodesWithTag
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 com.intuit.playerui.android.reference.demo.test.base.AssetUITest
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
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

class ActionUITest : AssetUITest("action") {
class ActionUITest : ComposeUITest("action") {

@Test
fun basic() {
launchMock("action-basic")

repeat(10) {
waitForViewInRoot(withText("Count: $it"))
.perform(click())
.check(matches(isDisplayed()))
androidComposeRule.onNodeWithTag("action").performClick()

waitForViewInRoot(withText("Count: ${it + 1}"))
.check(matches(isDisplayed()))
}

currentState.shouldBePlayerState<InProgressState> {
Expand All @@ -38,23 +44,25 @@ class ActionUITest : AssetUITest("action") {

waitForViewInRoot(withText("End the flow (success)"))
.check(matches(isDisplayed()))
.perform(click())

currentState.shouldBePlayerState<CompletedState> {
androidComposeRule.onAllNodesWithTag("action").get(0)
.performClick()
player.state.shouldBePlayerState<CompletedState> {
assertEquals("done", endState.outcome)
}
}

@Test
fun transitionToEndError() {
launchMock("action-transition-to-end")

waitForViewInRoot(withText("End the flow (error)"))
.check(matches(isDisplayed()))
.perform(click())

currentState.shouldBePlayerState<ErrorState> {
assertEquals("Error: Unclosed brace after \"foo.bar..}\" at character 12", error.message)
runTest {
waitForViewInRoot(withText("End the flow (error)"))
.check(matches(isDisplayed()))
androidComposeRule.onAllNodesWithTag("action").get(1)
.performClick()
delay(2000)
player.state.shouldBePlayerState<ErrorState> {
assertEquals("Error: Unclosed brace after \"foo.bar..}\" at character 12", error.message)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.intuit.playerui.android.reference.demo.test.assets.badge

import androidx.compose.ui.test.onNodeWithText
import com.intuit.playerui.android.reference.demo.test.base.ComposeUITest
import com.intuit.playerui.android.reference.demo.test.base.shouldBePlayerState
import com.intuit.playerui.core.player.state.InProgressState
import org.junit.Test

class BadgeUITest : ComposeUITest("badge") {

@Test
fun basic() {
launchMock("badge-all")

androidComposeRule.onNodeWithText("INFO")
.assertExists()
androidComposeRule.onNodeWithText("ERROR")
.assertExists()
currentState.shouldBePlayerState<InProgressState>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ 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
import com.intuit.playerui.android.reference.demo.test.base.AssetUITest
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.InProgressState
import org.junit.Test

class CollectionUITest : AssetUITest("collection") {
class CollectionUITest : ComposeUITest("collection") {

@Test
fun basic() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
package com.intuit.playerui.android.reference.demo.test.assets.info

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.compose.ui.test.onAllNodesWithTag
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 com.intuit.playerui.android.reference.demo.test.base.AssetUITest
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.InProgressState
import org.junit.Test

class InfoUITest : AssetUITest("info") {
class InfoUITest : ComposeUITest("info") {

enum class Action {
Next, Dismiss, CONTINUE
Next, Dismiss, Continue
}

fun verifyView(view: Int) {
waitForViewInRoot(withText("View $view"))
.check(matches(isDisplayed()))
}

fun verifyAndProceed(view: Int, action: Action? = null) {
fun verifyAndProceed(view: Int, action: Action? = null, index: Int? = null) {
verifyView(view)

action?.let {
onView(withText(action.name))
.check(matches(isDisplayed()))
.perform(click())
androidComposeRule.onAllNodesWithTag("action").get(index ?: 0)
.performClick()
}
}

@Test
fun basic() {
launchMock("info-modal-flow")

verifyAndProceed(1, Action.CONTINUE)
verifyAndProceed(2, Action.Dismiss)
verifyAndProceed(1, Action.CONTINUE)
verifyAndProceed(2, Action.Next)
verifyAndProceed(3, Action.Next)
verifyAndProceed(1, Action.Continue, 0)
verifyAndProceed(2, Action.Dismiss, 1)
verifyAndProceed(1, Action.Continue, 0)
verifyAndProceed(2, Action.Next, 0)
verifyAndProceed(3, Action.Next, 0)
verifyView(1)

currentState.shouldBePlayerState<InProgressState>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ abstract class AssetUITest(val group: String? = null) {
@get:Rule
val rule = activityScenarioRule<MainActivity>()

open fun getActivityRule() = rule

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 All @@ -33,7 +36,7 @@ abstract class AssetUITest(val group: String? = null) {
@Before
fun before() {
Intents.init()
rule.scenario.onActivity {
getActivityRule().scenario.onActivity {
viewModel = it.viewModel
}
}
Expand All @@ -57,7 +60,7 @@ abstract class AssetUITest(val group: String? = null) {
fun launchMock(mock: Mock<*>) {
viewModel.launch(mock)

rule.scenario.onActivity {
getActivityRule().scenario.onActivity {
playerViewModel = it.currentPlayer?.playerViewModel as? DemoPlayerViewModel
?: throw IllegalStateException("player not found")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.intuit.playerui.android.reference.demo.test.base

import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.intuit.playerui.android.reference.demo.ui.main.MainActivity
import org.junit.Rule

abstract class ComposeUITest(group: String? = null) : AssetUITest(group) {
@get:Rule
val androidComposeRule = createAndroidComposeRule<MainActivity>()

override fun getActivityRule(): ActivityScenarioRule<MainActivity> {
return androidComposeRule.activityRule
}
}
Loading