diff --git a/android/demo/deps.bzl b/android/demo/deps.bzl index e9bc946fa..9678d1f9f 100644 --- a/android/demo/deps.bzl +++ b/android/demo/deps.bzl @@ -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) + [ diff --git a/docs/storybook/BUILD b/docs/storybook/BUILD index 4d1ab747e..5e37bbe8e 100644 --- a/docs/storybook/BUILD +++ b/docs/storybook/BUILD @@ -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", diff --git a/index.bzl b/index.bzl index 1ebe6ae15..229a4d78d 100644 --- a/index.bzl +++ b/index.bzl @@ -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, +) \ No newline at end of file diff --git a/ios/packages/swiftui/Tests/ManagedPlayer/ManagedPlayerViewModelTests.swift b/ios/packages/swiftui/Tests/ManagedPlayer/ManagedPlayerViewModelTests.swift index 14e1d84f2..f20e17806 100644 --- a/ios/packages/swiftui/Tests/ManagedPlayer/ManagedPlayerViewModelTests.swift +++ b/ios/packages/swiftui/Tests/ManagedPlayer/ManagedPlayerViewModelTests.swift @@ -313,4 +313,4 @@ internal extension XCTestCase { await fulfillment(of: [expectation], timeout: timeout) return cancel } -} +} \ No newline at end of file diff --git a/jvm/core/deps.bzl b/jvm/core/deps.bzl index aac4a82f9..c3ebaabc0 100644 --- a/jvm/core/deps.bzl +++ b/jvm/core/deps.bzl @@ -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 = [] diff --git a/jvm/testutils/BUILD b/jvm/testutils/BUILD index 54d2b7368..f72a1d117 100644 --- a/jvm/testutils/BUILD +++ b/jvm/testutils/BUILD @@ -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, ) diff --git a/jvm/testutils/deps.bzl b/jvm/testutils/deps.bzl index d793d524f..35be018fb 100644 --- a/jvm/testutils/deps.bzl +++ b/jvm/testutils/deps.bzl @@ -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", ] diff --git a/jvm/utils/src/main/kotlin/com/intuit/player/jvm/utils/mocks/ClassLoaderMocksReader.kt b/jvm/utils/src/main/kotlin/com/intuit/player/jvm/utils/mocks/ClassLoaderMocksReader.kt index a56dc2049..cb7f25033 100644 --- a/jvm/utils/src/main/kotlin/com/intuit/player/jvm/utils/mocks/ClassLoaderMocksReader.kt +++ b/jvm/utils/src/main/kotlin/com/intuit/player/jvm/utils/mocks/ClassLoaderMocksReader.kt @@ -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() ?: "[]" } /** diff --git a/plugins/beacon/mocks/beacon/beacon-action.json b/plugins/beacon/mocks/beacon/beacon-action.json new file mode 100644 index 000000000..e69eb4830 --- /dev/null +++ b/plugins/beacon/mocks/beacon/beacon-action.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/plugins/external-action/mocks/BUILD b/plugins/external-action/mocks/BUILD new file mode 100644 index 000000000..f7313fbec --- /dev/null +++ b/plugins/external-action/mocks/BUILD @@ -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"], +) diff --git a/plugins/external-action/mocks/external-action/external-action.json b/plugins/external-action/mocks/external-action/external-action.json new file mode 100644 index 000000000..348556413 --- /dev/null +++ b/plugins/external-action/mocks/external-action/external-action.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/plugins/external-action/mocks/index.ts b/plugins/external-action/mocks/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/mocks/BUILD b/plugins/mocks/BUILD new file mode 100644 index 000000000..7dd1c424b --- /dev/null +++ b/plugins/mocks/BUILD @@ -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"], +) + + diff --git a/plugins/pubsub/mocks/BUILD b/plugins/pubsub/mocks/BUILD new file mode 100644 index 000000000..b4d010e02 --- /dev/null +++ b/plugins/pubsub/mocks/BUILD @@ -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"], +) \ No newline at end of file diff --git a/plugins/pubsub/mocks/index.ts b/plugins/pubsub/mocks/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/pubsub/mocks/pubsub/pub-sub-basic.json b/plugins/pubsub/mocks/pubsub/pub-sub-basic.json new file mode 100644 index 000000000..c87a91691 --- /dev/null +++ b/plugins/pubsub/mocks/pubsub/pub-sub-basic.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/plugins/reference-assets/android/build.bzl b/plugins/reference-assets/android/build.bzl index f2ab8b5c4..7b1605620 100644 --- a/plugins/reference-assets/android/build.bzl +++ b/plugins/reference-assets/android/build.bzl @@ -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", diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/action/ActionTest.kt b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/action/ActionTest.kt index 29bfc6ecf..bc1245eef 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/action/ActionTest.kt +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/action/ActionTest.kt @@ -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 { data.label.shouldBeAsset { @@ -42,7 +42,7 @@ class ActionTest : AssetTest("action") { @Test fun transitionToEndSuccess() { - launchMock("transition-to-end") + launchMock("action-transition-to-end") val collectionValues = currentView?.findViewById(R.id.collection_values) ?: throw AssertionError("current view is null") assertEquals(2, collectionValues.childCount) @@ -59,7 +59,7 @@ class ActionTest : AssetTest("action") { @Test fun transitionToEndError() { - launchMock("transition-to-end") + launchMock("action-transition-to-end") val collectionValues = currentView?.findViewById(R.id.collection_values) ?: throw AssertionError("current view is null") assertEquals(2, collectionValues.childCount) diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/collection/CollectionTest.kt b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/collection/CollectionTest.kt index afc317cc4..bc0dade0f 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/collection/CollectionTest.kt +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/collection/CollectionTest.kt @@ -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(R.id.collection_label) ?: throw AssertionError("current view is null") val collectionValues = currentView?.findViewById(R.id.collection_values) ?: throw AssertionError("current view is null") diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/info/InfoTest.kt b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/info/InfoTest.kt index 6a1c256ab..36c910068 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/info/InfoTest.kt +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/info/InfoTest.kt @@ -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 @@ -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) diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/input/InputTest.kt b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/input/InputTest.kt index 1768943db..998821f3f 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/input/InputTest.kt +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/input/InputTest.kt @@ -13,7 +13,7 @@ import com.intuit.player.jvm.core.player.state.dataModel import org.junit.Assert.assertEquals import org.junit.Test -class InputTest : AssetTest("input") { +class InputTest : AssetTest("reference-assets") { private fun FormattedEditText.type(text: String) { requestFocus() @@ -23,7 +23,7 @@ class InputTest : AssetTest("input") { @Test fun basic() { - launchMock() + launchMock("input-basic") val inputLabelContainer = currentView?.findViewById(R.id.input_label_container) ?: throw AssertionError("current view is null") val inputField = currentView?.findViewById(R.id.input_field) ?: throw AssertionError("current view is null") @@ -50,7 +50,7 @@ class InputTest : AssetTest("input") { @Test fun validation() { - launchMock() + launchMock("input-validation") val view = currentView.shouldBeView() val inputLabelContainer = view.findViewById(R.id.input_label_container) diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/test/deps.bzl b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/test/deps.bzl index 536c48fd5..a4a2208d9 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/test/deps.bzl +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/test/deps.bzl @@ -9,10 +9,10 @@ maven = [ ] main_deps = parse_coordinates(maven) + [ + "//plugins/mocks:jar", "@robolectric//bazel:android-all", "//jvm/utils", "//plugins/common-types/jvm:common-types", "//plugins/pending-transaction/jvm:pending-transaction", "//plugins/reference-assets/android:assets", - "//plugins/reference-assets/mocks:jar", ] diff --git a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/text/TextTest.kt b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/text/TextTest.kt index 4a377c81a..09ae61800 100644 --- a/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/text/TextTest.kt +++ b/plugins/reference-assets/android/src/androidTest/java/com/intuit/player/android/reference/assets/text/TextTest.kt @@ -9,11 +9,11 @@ import com.intuit.player.android.reference.assets.test.shouldBeView import org.junit.Assert.assertEquals import org.junit.Test -class TextTest : AssetTest("text") { +class TextTest : AssetTest("reference-assets") { @Test fun basic() { - launchMock() + launchMock("text-basic") val collectionValues = currentView?.findViewById(R.id.collection_values) ?: throw AssertionError("current view is null") collectionValues[0].shouldBeView { @@ -27,7 +27,7 @@ class TextTest : AssetTest("text") { @Test fun link() { - launchMock("with-link") + launchMock("text-with-link") currentView.shouldBeView { assertEquals("A Link", text.toString()) diff --git a/plugins/reference-assets/mocks/BUILD b/plugins/reference-assets/mocks/BUILD index 4b0cf81bf..05fcbfd62 100644 --- a/plugins/reference-assets/mocks/BUILD +++ b/plugins/reference-assets/mocks/BUILD @@ -1,29 +1,34 @@ -load(":build.bzl", "generate_manifest") -load("//:index.bzl", "javascript_pipeline") +load("//:index.bzl", "generate_manifest", "javascript_pipeline") -generate_manifest( +filegroup( name = "mocks", - mocks = glob(["**/*.json"]), + srcs = glob(["**/*.json"]), + visibility = ["//visibility:public"], +) + +generate_manifest( + name = "manifest", + mocks = [":mocks"], visibility = ["//visibility:public"], ) javascript_pipeline( name = "@player-ui/reference-assets-plugin-mocks", entry = "index.ts", - dependencies = [ + dependencies = [ "@npm//@player-tools/dsl", "//plugins/reference-assets/components:@player-ui/reference-assets-components" ], other_srcs = [ "index.ts", - ":mocks", + ":manifest", ] + glob(["**/*.tsx"]), out_dir = "", ) java_library( name = "jar", - resources = [":mocks"], + resources = [":manifest"], resource_strip_prefix = "plugins/reference-assets/mocks", visibility = ["//visibility:public"], -) +) \ No newline at end of file diff --git a/plugins/reference-assets/mocks/build.bzl b/plugins/reference-assets/mocks/build.bzl deleted file mode 100644 index 3515d96e1..000000000 --- a/plugins/reference-assets/mocks/build.bzl +++ /dev/null @@ -1,27 +0,0 @@ -def _generate_manifest(context): - manifest = context.actions.declare_file("manifest.json") - context.actions.write( - output = manifest, - content = json.encode([ - { - "group": group, - "name": name.replace(".json", ""), - "path": "./%s/%s" % (group, name), - } - for group, name in [ - mock.label.name.split("/")[-2:] - for mock in context.attr.mocks - ] - ]), - ) - return [DefaultInfo(files = depset([manifest], transitive = [mock[DefaultInfo].files for mock in context.attr.mocks]))] - -generate_manifest = rule( - attrs = { - "mocks": attr.label_list( - mandatory = True, - allow_files = [".json"], - ), - }, - implementation = _generate_manifest, -)