Skip to content

Commit

Permalink
Merge pull request #206 from mercillo/mocksForPlugins
Browse files Browse the repository at this point in the history
Updated Demo App
Refactored plugin mocks for android Demo App
  • Loading branch information
mercillo authored Nov 21, 2023
2 parents 75974a8 + f630cce commit b06114c
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 58 deletions.
2 changes: 1 addition & 1 deletion android/demo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main_deps = parse_coordinates(maven_main) + [
"//plugins/reference-assets/android:assets",
"//plugins/common-types/jvm:common-types",
"//plugins/pending-transaction/jvm:pending-transaction",
"//plugins/reference-assets/mocks:jar",
"//plugins/mocks:jar",
]

test_deps = parse_coordinates(maven_test) + [
Expand Down
2 changes: 2 additions & 0 deletions docs/storybook/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ data = [
"//core/make-flow:@player-ui/make-flow",
"//plugins/reference-assets/react:@player-ui/reference-assets-plugin-react",
"//plugins/reference-assets/mocks:@player-ui/reference-assets-plugin-mocks",
"//plugins/pubsub/core:@player-ui/pubsub-plugin",
"//plugins/pubsub/mocks:@player-ui/pubsub-plugin-mocks",
"//plugins/data-change-listener/core:@player-ui/data-change-listener-plugin",
"//plugins/computed-properties/core:@player-ui/computed-properties-plugin",
"//plugins/reference-assets/components:@player-ui/reference-assets-components",
Expand Down
28 changes: 28 additions & 0 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,31 @@ def javascript_pipeline(
srcs = srcs,
mode = xlr_mode
)

def _generate_manifest(context):
manifest = context.actions.declare_file("manifest.json")
context.actions.write(
output = manifest,
content = json.encode([
{
"group": group,
"name": file.replace(".json", ""),
"path": "./%s/%s/%s/%s" % (group, name,action,file),
}
for group, name, action, file in [
mock.path.split("/")[-4:]
for filegroup in context.attr.mocks
for mock in filegroup[DefaultInfo].files.to_list()
]
]),
)
return [DefaultInfo(files = depset([manifest], transitive = [mock[DefaultInfo].files for mock in context.attr.mocks]))]

generate_manifest = rule(
attrs = {
"mocks": attr.label_list(
allow_files = [".json"],
),
},
implementation = _generate_manifest,
)
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,4 @@ internal extension XCTestCase {
await fulfillment(of: [expectation], timeout: timeout)
return cancel
}
}
}
4 changes: 3 additions & 1 deletion jvm/core/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ main_deps = main_exports + [
main_runtime_deps = []

# Test dependencies
test_deps = []
test_deps = [
"//plugins/reference-assets/jvm:reference-assets",
]
test_runtime_deps = []
1 change: 0 additions & 1 deletion jvm/testutils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ kt_player_module(
name = "testutils",
main_deps = main_deps,
main_exports = main_exports,
main_resource_strip_prefix = "plugins/reference-assets/mocks",
main_resources = main_resources,
)
3 changes: 1 addition & 2 deletions jvm/testutils/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ main_exports = [
"//jvm/j2v8:j2v8-all",
"//jvm/graaljs",
"//plugins/common-types/jvm:common-types",
"//plugins/reference-assets/jvm:reference-assets",
"//plugins/mocks:jar",
]

main_deps = main_exports

main_resources = [
"//plugins/reference-assets/mocks",
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ClassLoaderMocksReader(private val classLoader: ClassLoader = Class
* will read the manifest on demand and default to an empty list if not found.
*/
public val manifest: String by lazy {
classLoader.getResource("manifest.json")?.readText() ?: "[]"
classLoader.getResource("mocks/manifest.json")?.readText() ?: "[]"
}

/**
Expand Down
43 changes: 43 additions & 0 deletions plugins/beacon/mocks/beacon/beacon-action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "generated-flow",
"views": [
{
"id": "action",
"type": "action",
"exp": [
"{{count}} = {{count}} + 1",
"beacon('action', 'some-data')"
],
"metaData": {
"beacon": "Click count: {{count}}"
},
"label": {
"asset": {
"id": "action-label-text",
"type": "text",
"value": "Clicked {{count}} times"
}
}
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "action",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
29 changes: 29 additions & 0 deletions plugins/external-action/mocks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("//:index.bzl", "generate_manifest","javascript_pipeline")

filegroup(
name = "mocks",
srcs = glob(["**/*.json"]),
visibility = ["//visibility:public"],
)

generate_manifest(
name = "manifest",
mocks = [":mocks"],
visibility = ["//visibility:public"],
)
javascript_pipeline(
name = "@player-ui/external-action-plugin-mocks",
entry = "index.ts",
other_srcs = [
"index.ts",
":manifest",
],
out_dir = "",
)

java_library(
name = "jar",
resources = [":mocks"],
resource_strip_prefix = "plugins/external-action/mocks",
visibility = ["//visibility:public"],
)
28 changes: 28 additions & 0 deletions plugins/external-action/mocks/external-action/external-action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"id": "test-flow",
"data": {
"transitionValue": "Next"
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "EXT_1",
"EXT_1": {
"state_type": "EXTERNAL",
"ref": "test-1",
"transitions": {
"Next": "END_FWD",
"Prev": "END_BCK"
}
},
"END_FWD": {
"state_type": "END",
"outcome": "FWD"
},
"END_BCK": {
"state_type": "END",
"outcome": "BCK"
}
}
}
}
Empty file.
17 changes: 17 additions & 0 deletions plugins/mocks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("//:index.bzl", "generate_manifest")
load("//:index.bzl", "javascript_pipeline")

generate_manifest(
name = "mocks",
mocks = ["//plugins/reference-assets/mocks","//plugins/pubsub/mocks", "//plugins/external-action/mocks"],
visibility = ["//visibility:public"],
)

java_library(
name = "jar",
resources = [":mocks"],
resource_strip_prefix = "plugins/",
visibility = ["//visibility:public"],
)


36 changes: 36 additions & 0 deletions plugins/pubsub/mocks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("//:index.bzl", "generate_manifest","javascript_pipeline")




filegroup(
name = "mocks",
srcs = glob(["**/*.json"]),
visibility = ["//visibility:public"],
)

generate_manifest(
name = "manifest",
mocks = [":mocks"],
visibility = ["//visibility:public"],
)

javascript_pipeline(
name = "@player-ui/pubsub-plugin-mocks",
entry = "index.ts",
dependencies = [
"@npm//@player-tools/dsl",
],
other_srcs = [
"index.ts",
":manifest",
] + glob(["**/*.tsx"]),
out_dir = "",
)

java_library(
name = "jar",
resources = [":mocks"],
resource_strip_prefix = "plugins/pubsub/mocks/",
visibility = ["//visibility:public"],
)
Empty file added plugins/pubsub/mocks/index.ts
Empty file.
37 changes: 37 additions & 0 deletions plugins/pubsub/mocks/pubsub/pub-sub-basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id": "generated-flow",
"views": [
{
"id": "action",
"type": "action",
"exp": "@[ publish('some-event', 'event published message') ]@",
"label": {
"asset": {
"id": "action-label",
"type": "text",
"value": "Clicked to publish event"
}
}
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "action",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
3 changes: 2 additions & 1 deletion plugins/reference-assets/android/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def kt_asset_test(
custom_package = "com.intuit.player.android.reference.assets",
test_class = test_class,
deps = deps + [
"//plugins/mocks:jar",
"//plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/test",
"//jvm/j2v8:j2v8-all",

],
resources = [
"//plugins/reference-assets/mocks",
],
manifest_values = {
"minSdkVersion": "14",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import com.intuit.player.jvm.core.player.state.dataModel
import org.junit.Assert.assertEquals
import org.junit.Test

class ActionTest : AssetTest("action") {
class ActionTest : AssetTest("reference-assets") {

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

currentAssetTree.shouldBeAsset<Action> {
data.label.shouldBeAsset<Text> {
Expand All @@ -42,7 +42,7 @@ class ActionTest : AssetTest("action") {

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

val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
assertEquals(2, collectionValues.childCount)
Expand All @@ -59,7 +59,7 @@ class ActionTest : AssetTest("action") {

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

val collectionValues = currentView?.findViewById<LinearLayout>(R.id.collection_values) ?: throw AssertionError("current view is null")
assertEquals(2, collectionValues.childCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import com.intuit.player.jvm.core.player.state.InProgressState
import org.junit.Assert.assertEquals
import org.junit.Test

class CollectionTest : AssetTest("collection") {
class CollectionTest : AssetTest("reference-assets") {

@Test
fun basic() {
launchMock()
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.intuit.player.jvm.core.player.state.InProgressState
import org.junit.Assert.assertEquals
import org.junit.Test

class InfoTest : AssetTest("info") {
class InfoTest : AssetTest("reference-assets") {

enum class PlayerAction {
Next, Dismiss
Expand All @@ -37,7 +37,7 @@ class InfoTest : AssetTest("info") {

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

verifyAndProceed(1, PlayerAction.Next)
verifyAndProceed(2, PlayerAction.Dismiss)
Expand Down
Loading

0 comments on commit b06114c

Please sign in to comment.