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

update iOS tests to transition inside afterTransition #268

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
5 changes: 4 additions & 1 deletion ios/packages/core/Sources/Types/Core/Flow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ public class Flow: CreatedFromJSValue {
*/
public init(_ value: JSValue) {
self.value = value
hooks = FlowHooks(transition: Hook2<NamedState?, NamedState>(baseValue: value, name: "transition"))
hooks = FlowHooks(transition: Hook2(baseValue: value, name: "transition"), afterTransition: Hook(baseValue: value, name: "afterTransition"))
}
}

public struct FlowHooks {
/// A hook that fires when transitioning states and giving the old and new states as parameters
public var transition: Hook2<NamedState?, NamedState>

/// A hook that fires after a transition occurs giving the FlowInstance as parameter
public var afterTransition: Hook<Flow>
}

public struct NamedState: CreatedFromJSValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,14 @@ class ForceTransitionPlugin: NativePlugin {
}
}
}

player.hooks?.flowController.tap({ flowController in
flowController.hooks.flow.tap { flow in
flow.hooks.afterTransition.tap { _ in
guard let state = player.state as? InProgressState else { return }
flowController.transition(with: "NEXT")
}
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class StageRevertDataPluginTests: XCTestCase {
}
}
"""

func testStageRevertDataPluginStagesData() {
let expected = XCTestExpectation(description: "data did not change")
let player = HeadlessPlayerImpl(plugins: [PrintLoggerPlugin(level: .trace), StageRevertDataPlugin()])
Expand All @@ -69,8 +70,6 @@ class StageRevertDataPluginTests: XCTestCase {
viewController.hooks.view.tap { view in
view.hooks.onUpdate.tap { value in
guard view.id == "view-3" else {
(player.state as? InProgressState)?.controllers?.data.set(transaction: ["name": "Test"])
(player.state as? InProgressState)?.controllers?.flow.transition(with: "clear")
return
}

Expand All @@ -82,6 +81,18 @@ class StageRevertDataPluginTests: XCTestCase {
}
}

player.hooks?.flowController.tap({ flowController in
flowController.hooks.flow.tap { flow in
flow.hooks.afterTransition.tap { flowInstance in
guard flowInstance.currentState?.name == "VIEW_3" else {
(player.state as? InProgressState)?.controllers?.data.set(transaction: ["name": "Test"])
flowController.transition(with: "clear")
return
}
}
}
})

player.start(flow: json, completion: {_ in})
wait(for: [expected], timeout: 1)
}
Expand All @@ -94,8 +105,6 @@ class StageRevertDataPluginTests: XCTestCase {
viewController.hooks.view.tap { view in
view.hooks.onUpdate.tap { value in
guard view.id == "view-2" else {
(player.state as? InProgressState)?.controllers?.data.set(transaction: ["name": "Test"])
(player.state as? InProgressState)?.controllers?.flow.transition(with: "commit")
return
}

Expand All @@ -107,6 +116,18 @@ class StageRevertDataPluginTests: XCTestCase {
}
}

player.hooks?.flowController.tap({ flowController in
flowController.hooks.flow.tap { flow in
flow.hooks.afterTransition.tap { flowInstance in
guard flowInstance.currentState?.name == "VIEW_2" else {
(player.state as? InProgressState)?.controllers?.data.set(transaction: ["name": "Test"])
flowController.transition(with: "commit")
return
}
}
}
})

player.start(flow: json, completion: {_ in})
wait(for: [expected], timeout: 1)
}
Expand Down
3 changes: 2 additions & 1 deletion xcode/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ PODS:
- PlayerUI/BeaconPlugin
- PlayerUI/Core
- PlayerUI/SwiftUI
- PlayerUI/SwiftUIPendingTransactionPlugin
- PlayerUI/StageRevertDataPlugin (0.0.1-placeholder):
- PlayerUI/Core
- PlayerUI/SwiftUI (0.0.1-placeholder):
Expand Down Expand Up @@ -133,7 +134,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
EyesXCUI: bbb10a48b8bd1a15d541f2bc1f4d18f4db654ef1
PlayerUI: 7b9bdbf01b4da672a0b6be1281f7b70e134d4e3c
PlayerUI: 904ce444be3bf2cc654a422c616d4612f5b6649d
SwiftHooks: 3ecc67c23da335d44914a8a74bd1dd23c7c149e6
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d
ViewInspector: 53313c757eddc5c4842bc7943a66821a68d02d3e
Expand Down