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

Mocks for plugins #206

Merged
merged 44 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3648a4d
added mocks for external action and pubsub
Oct 25, 2023
0d148f0
modified build
Oct 25, 2023
1da2bf4
Merge branch 'main' into mocksForPlugins
mercillo Oct 25, 2023
d03b5f3
pubsub build modified
Oct 25, 2023
a12cd1e
updated pubsub flow
Oct 30, 2023
7e28e3e
add user info to assetViewModel
Oct 24, 2023
8152b9f
address comments
Oct 25, 2023
afddeae
update tests
Oct 25, 2023
fca3933
update doc
Oct 25, 2023
00939af
apply swift 6 warning fix to flaky iOS tests (#207)
hborawski Oct 27, 2023
68df800
update Gemfile.lock (#208)
hborawski Oct 27, 2023
a51c160
renamed folder structure for plugin mocks
Nov 3, 2023
7a99386
store cancellables in ManagedPlayerViewModelTests (#210)
hborawski Oct 31, 2023
43b0396
Singular workflow for CI (#214)
brocollie08 Nov 2, 2023
9c07351
WIP, plugin demo app
Nov 7, 2023
0f9637f
generate manifest for mocks
Nov 7, 2023
21edcdb
fixed typo in build file
Nov 7, 2023
3c2e9b6
Merge branch 'main' into mocksForPlugins
mercillo Nov 7, 2023
4d9ada3
Merge branch 'main' into mocksForPlugins
mercillo Nov 7, 2023
99ae380
modified mocks reader
Nov 7, 2023
605df1b
updated test dependencies
Nov 8, 2023
206cfc7
added dependency for all plugin tests to work with simpleFlow
Nov 8, 2023
be4fe4a
reference assets needed
Nov 8, 2023
7e87a0f
more dependencies for tests
Nov 8, 2023
bd33720
modified test names
Nov 8, 2023
2d7b38b
Merge branch 'main' into mocksForPlugins
mercillo Nov 8, 2023
451adaf
modified test names
Nov 9, 2023
dd4143e
Merge branch 'main' into mocksForPlugins
mercillo Nov 9, 2023
caf618a
removed unneeded dependencies
Nov 16, 2023
2b14916
cleaned up BUILD and index fiels
Nov 17, 2023
ffa1afd
Merge branch 'main' into mocksForPlugins
mercillo Nov 17, 2023
d429b2b
iOS: make AssetBeacon equatable and add public init for metadata (#248)
hborawski Nov 18, 2023
af597a9
Update ruby version in build (#246)
adierkens Nov 18, 2023
b818ef2
Release main
intuit-svc Nov 20, 2023
bd414d8
Update CHANGELOG.md [skip ci]
intuit-svc Nov 20, 2023
627a8d0
Bump version to: v0.4.4 [skip ci]
intuit-svc Nov 20, 2023
99bb00a
add user info to assetViewModel
Oct 24, 2023
262a1b7
address comments
Oct 25, 2023
1e55527
apply swift 6 warning fix to flaky iOS tests (#207)
hborawski Oct 27, 2023
6543efa
store cancellables in ManagedPlayerViewModelTests (#210)
hborawski Oct 31, 2023
b4c2f79
modified test names
Nov 8, 2023
9286c38
mandatory not needed
Nov 21, 2023
4b1d150
Merge branch 'main' into mocksForPlugins
mercillo Nov 21, 2023
f630cce
rebase picked up wrong file changes
Nov 21, 2023
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
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
29 changes: 29 additions & 0 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,32 @@ 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(
mandatory = True,
allow_files = [".json"],
mercillo marked this conversation as resolved.
Show resolved Hide resolved
),
},
implementation = _generate_manifest,
)
5 changes: 4 additions & 1 deletion jvm/core/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ main_deps = main_exports + [
main_runtime_deps = []

# Test dependencies
test_deps = []
test_deps = [
"//plugins/mocks:jar",
"//plugins/reference-assets/jvm:reference-assets",
mercillo marked this conversation as resolved.
Show resolved Hide resolved
]
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,
)
4 changes: 2 additions & 2 deletions jvm/testutils/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ 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",
"//plugins/mocks:jar",
mercillo marked this conversation as resolved.
Show resolved Hide resolved
]
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
62 changes: 62 additions & 0 deletions plugins/beacon/mocks/beacon/beacon-action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"id": "generated-flow",
"views": [
{
"id": "collection",
"type": "collection",
"values": [
{
"asset": {
"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"
}
}
}
},
{
"asset": {
"id": "action-end",
"type": "action",
"value": "Next",
"label": {
"asset": {
"id": "action-end-label",
"type": "text",
"value": "End the flow (View Beacons)"
}
}
}
}
]
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "collection",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
31 changes: 31 additions & 0 deletions plugins/external-action/mocks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("//:index.bzl", "generate_manifest")
load("//:index.bzl", "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"],
)
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"
}
}
}
}
7 changes: 7 additions & 0 deletions plugins/external-action/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Mock {
group: string;
name: string;
path: string;
}

export type Manifest = Array<Mock>;
mercillo marked this conversation as resolved.
Show resolved Hide resolved
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"],
)


34 changes: 34 additions & 0 deletions plugins/pubsub/mocks/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//:index.bzl", "generate_manifest")
load("//:index.bzl", "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"],
)
7 changes: 7 additions & 0 deletions plugins/pubsub/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Mock {
group: string;
name: string;
path: string;
}

export type Manifest = Array<Mock>;
59 changes: 59 additions & 0 deletions plugins/pubsub/mocks/pubsub/pub-sub-basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"id": "generated-flow",
"views": [
{
"id": "collection",
"type": "collection",
"values": [
{
"asset": {
"id": "action",
"type": "action",
"exp": "@[ publish('some-event', 'event published message') ]@",
"label": {
"asset": {
"id": "action-label",
"type": "text",
"value": "Clicked to publish event"
}
}
}
},
{
"asset": {
"id": "action-end",
"type": "action",
"value": "Next",
"label": {
"asset": {
"id": "action-end-label",
"type": "text",
"value": "End the flow (View pubsub events)"
}
}
}
}
]
}
],
"data": {
"count": 0
},
"navigation": {
"BEGIN": "FLOW_1",
"FLOW_1": {
"startState": "VIEW_1",
"VIEW_1": {
"state_type": "VIEW",
"ref": "collection",
"transitions": {
"*": "END_Done"
}
},
"END_Done": {
"state_type": "END",
"outcome": "done"
}
}
}
}
4 changes: 3 additions & 1 deletion plugins/reference-assets/android/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ 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",
"//plugins/mocks:jar",
mercillo marked this conversation as resolved.
Show resolved Hide resolved
],
manifest_values = {
"minSdkVersion": "14",
Expand Down
1 change: 1 addition & 0 deletions plugins/reference-assets/android/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ main_exports = [

main_deps = main_exports + parse_coordinates(maven_main) + [
"//jvm:kotlin_serialization",
"//plugins/mocks:jar",
mercillo marked this conversation as resolved.
Show resolved Hide resolved
"//plugins/reference-assets/jvm:reference-assets",
"//plugins/pending-transaction/jvm:pending-transaction",
]
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
Loading