From e52d0fc8d115c051e827c632667f98c82c029c77 Mon Sep 17 00:00:00 2001 From: Harris Borawski Date: Thu, 25 Aug 2022 11:16:43 -0700 Subject: [PATCH] split out test helper functionality so XCTest isn't a hard requirement --- PlayerUI.podspec | 14 +- generated.bzl | 8 ++ .../Sources/HeadlessPlayerImpl.swift | 3 + .../SwiftUI/ActionAssetTests.swift | 10 +- .../SwiftUI/CollectionAssetTests.swift | 12 +- .../SwiftUI/InfoAssetTests.swift | 14 +- .../SwiftUI/InputAssetTests.swift | 10 +- .../SwiftUI/TextAssetTests.swift | 4 +- .../Sources/AssetTestHelper.swift | 122 ++++++++++++++++++ .../Tests/AssetTestHelperTests.swift | 92 +++++++++++++ .../unit-test/AssetUnitTestCaseBase.swift | 51 -------- .../unit-test/SwiftUIAssetUnitTestCase.swift | 44 ++----- .../unit-test/AssetUnitTestCaseTests.swift | 17 ++- .../SwiftUIAssetUnitTestCaseTests.swift | 12 +- xcode/Podfile | 1 + xcode/Podfile.lock | 9 +- 16 files changed, 294 insertions(+), 129 deletions(-) create mode 100644 ios/packages/test-utils-core/Sources/AssetTestHelper.swift create mode 100644 ios/packages/test-utils-core/Tests/AssetTestHelperTests.swift delete mode 100644 ios/packages/test-utils/Sources/unit-test/AssetUnitTestCaseBase.swift diff --git a/PlayerUI.podspec b/PlayerUI.podspec index 0db350c74..b36873bbc 100644 --- a/PlayerUI.podspec +++ b/PlayerUI.podspec @@ -165,16 +165,26 @@ and display it as a SwiftUI view comprised of registered assets. } end - s.subspec 'TestUtilities' do |utils| + s.subspec 'TestUtilitiesCore' do |utils| utils.dependency 'PlayerUI/Core' utils.dependency 'PlayerUI/SwiftUI' utils.ios.deployment_target = '13.0' - utils.source_files = 'ios/packages/test-utils/Sources/**/*' + utils.source_files = 'ios/packages/test-utils-core/Sources/**/*' utils.resource_bundles = { 'TestUtilities' => ['ios/packages/test-utils/Resources/**/*.js'] } + end + + s.subspec 'TestUtilities' do |utils| + utils.dependency 'PlayerUI/Core' + utils.dependency 'PlayerUI/SwiftUI' + utils.dependency 'PlayerUI/TestUtilitiesCore' + + utils.ios.deployment_target = '13.0' + + utils.source_files = 'ios/packages/test-utils/Sources/**/*' utils.weak_framework = 'XCTest' utils.pod_target_xcconfig = { diff --git a/generated.bzl b/generated.bzl index 8bc20ee99..d1aa48913 100644 --- a/generated.bzl +++ b/generated.bzl @@ -155,6 +155,14 @@ def PlayerUI( "ios/packages/test-utils/Sources/**/*.c", "ios/packages/test-utils/Sources/**/*.cc", "ios/packages/test-utils/Sources/**/*.cpp", + "ios/packages/test-utils-core/Sources/**/*.h", + "ios/packages/test-utils-core/Sources/**/*.hh", + "ios/packages/test-utils-core/Sources/**/*.m", + "ios/packages/test-utils-core/Sources/**/*.mm", + "ios/packages/test-utils-core/Sources/**/*.swift", + "ios/packages/test-utils-core/Sources/**/*.c", + "ios/packages/test-utils-core/Sources/**/*.cc", + "ios/packages/test-utils-core/Sources/**/*.cpp", "ios/plugins/TransitionPlugin/Sources/**/*.h", "ios/plugins/TransitionPlugin/Sources/**/*.hh", "ios/plugins/TransitionPlugin/Sources/**/*.m", diff --git a/ios/packages/internal-test-utils/Sources/HeadlessPlayerImpl.swift b/ios/packages/internal-test-utils/Sources/HeadlessPlayerImpl.swift index 20cb1ed12..5d6e7ff16 100644 --- a/ios/packages/internal-test-utils/Sources/HeadlessPlayerImpl.swift +++ b/ios/packages/internal-test-utils/Sources/HeadlessPlayerImpl.swift @@ -40,14 +40,17 @@ class TestAssetType: PlayerAsset, Decodable { var rawValue: JSValue? var id: String var type: String + var value: String? struct Data: Decodable { var id: String var type: String + var value: String? } required init(from decoder: Decoder) throws { let data = try decoder.singleValueContainer().decode(Data.self) id = data.id type = data.type + value = data.value } } diff --git a/ios/packages/reference-assets/ViewInspector/SwiftUI/ActionAssetTests.swift b/ios/packages/reference-assets/ViewInspector/SwiftUI/ActionAssetTests.swift index eb9aabdba..08ad23fd9 100644 --- a/ios/packages/reference-assets/ViewInspector/SwiftUI/ActionAssetTests.swift +++ b/ios/packages/reference-assets/ViewInspector/SwiftUI/ActionAssetTests.swift @@ -24,7 +24,7 @@ class ActionAssetTests: SwiftUIAssetUnitTestCase { func setup() { XCUIApplication().terminate() } - func testAssetDecoding() throws { + func testAssetDecoding() async throws { let json = """ { "id": "action", @@ -40,7 +40,7 @@ class ActionAssetTests: SwiftUIAssetUnitTestCase { } """ - guard let action: ActionAsset = getAsset(json) else { + guard let action: ActionAsset = await getAsset(json) else { return XCTFail("unable to get asset") } @@ -57,8 +57,8 @@ class ActionAssetTests: SwiftUIAssetUnitTestCase { _ = try view.inspect().button() } - func testViewWithLabel() throws { - guard let text: TextAsset = getAsset(""" + func testViewWithLabel() async throws { + guard let text: TextAsset = await getAsset(""" {"id": "text", "type": "text", "value":"hello world"} """) else { return XCTFail("unable to get asset") } @@ -66,7 +66,7 @@ class ActionAssetTests: SwiftUIAssetUnitTestCase { let model = AssetViewModel(data) - let view = ActionAssetView(model: model) + let view = await ActionAssetView(model: model) _ = try view.inspect().button() diff --git a/ios/packages/reference-assets/ViewInspector/SwiftUI/CollectionAssetTests.swift b/ios/packages/reference-assets/ViewInspector/SwiftUI/CollectionAssetTests.swift index 3d20c334a..f77f3282b 100644 --- a/ios/packages/reference-assets/ViewInspector/SwiftUI/CollectionAssetTests.swift +++ b/ios/packages/reference-assets/ViewInspector/SwiftUI/CollectionAssetTests.swift @@ -21,7 +21,7 @@ class CollectionAssetTests: SwiftUIAssetUnitTestCase { registry.register("text", asset: TextAsset.self) } - func testDecoding() throws { + func testDecoding() async throws { let json = """ { "id": "collection", @@ -45,15 +45,15 @@ class CollectionAssetTests: SwiftUIAssetUnitTestCase { } """ - guard let collection: CollectionAsset = getAsset(json) else { return XCTFail("could not get asset") } + guard let collection: CollectionAsset = await getAsset(json) else { return XCTFail("could not get asset") } _ = try collection.view.inspect().find(CollectionAssetView.self).vStack() } - func testView() throws { + func testView() async throws { guard - let text1: TextAsset = getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}"), - let text2: TextAsset = getAsset("{\"id\": \"text2\", \"type\": \"text\", \"value\":\"goodbye world\"}") + let text1: TextAsset = await getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}"), + let text2: TextAsset = await getAsset("{\"id\": \"text2\", \"type\": \"text\", \"value\":\"goodbye world\"}") else { return XCTFail("could not get assets") } let model = AssetViewModel( CollectionData( @@ -66,7 +66,7 @@ class CollectionAssetTests: SwiftUIAssetUnitTestCase { ) ) - let view = CollectionAssetView(model: model) + let view = await CollectionAssetView(model: model) let stack = try view.inspect().vStack() diff --git a/ios/packages/reference-assets/ViewInspector/SwiftUI/InfoAssetTests.swift b/ios/packages/reference-assets/ViewInspector/SwiftUI/InfoAssetTests.swift index 30e91f0cf..911d6e4ae 100644 --- a/ios/packages/reference-assets/ViewInspector/SwiftUI/InfoAssetTests.swift +++ b/ios/packages/reference-assets/ViewInspector/SwiftUI/InfoAssetTests.swift @@ -22,7 +22,7 @@ class InfoAssetTests: SwiftUIAssetUnitTestCase { registry.register("action", asset: ActionAsset.self) } - func testDecoding() throws { + func testDecoding() async throws { let json = """ { "id": "view-1", @@ -53,16 +53,16 @@ class InfoAssetTests: SwiftUIAssetUnitTestCase { } """ - guard let info: InfoAsset = getAsset(json) else { return XCTFail("could not get asset") } + guard let info: InfoAsset = await getAsset(json) else { return XCTFail("could not get asset") } _ = try info.view.inspect().find(InfoAssetView.self) } - func testView() throws { + func testView() async throws { guard - let title: TextAsset = getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}"), - let action1: ActionAsset = getAsset("{\"id\": \"action1\", \"type\": \"action\", \"value\":\"next\"}"), - let action2: ActionAsset = getAsset("{\"id\": \"action2\", \"type\": \"action\", \"value\":\"prev\"}") + let title: TextAsset = await getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}"), + let action1: ActionAsset = await getAsset("{\"id\": \"action1\", \"type\": \"action\", \"value\":\"next\"}"), + let action2: ActionAsset = await getAsset("{\"id\": \"action2\", \"type\": \"action\", \"value\":\"prev\"}") else { return XCTFail("could not get assets") } let data = InfoData( @@ -75,7 +75,7 @@ class InfoAssetTests: SwiftUIAssetUnitTestCase { ] ) let model = AssetViewModel(data) - let view = InfoAssetView(model: model) + let view = await InfoAssetView(model: model) let stack = try view.inspect().vStack() diff --git a/ios/packages/reference-assets/ViewInspector/SwiftUI/InputAssetTests.swift b/ios/packages/reference-assets/ViewInspector/SwiftUI/InputAssetTests.swift index f9100515b..0d483a5e6 100644 --- a/ios/packages/reference-assets/ViewInspector/SwiftUI/InputAssetTests.swift +++ b/ios/packages/reference-assets/ViewInspector/SwiftUI/InputAssetTests.swift @@ -24,7 +24,7 @@ class InputAssetTests: SwiftUIAssetUnitTestCase { registry.register("text", asset: TextAsset.self) } - func testDecoding() throws { + func testDecoding() async throws { let json = """ { "id": "input", @@ -41,7 +41,7 @@ class InputAssetTests: SwiftUIAssetUnitTestCase { } """ - guard let input: InputAsset = getAsset(json) else { return XCTFail("could not get asset") } + guard let input: InputAsset = await getAsset(json) else { return XCTFail("could not get asset") } _ = try input.view.inspect().find(InputAssetView.self).vStack().textField(1) } @@ -123,9 +123,9 @@ class InputAssetTests: SwiftUIAssetUnitTestCase { XCTAssertEqual(Color(red: 0.729, green: 0.745, blue: 0.773), try background.foregroundColor()) } - func testViewWithLabel() throws { + func testViewWithLabel() async throws { guard - let label: TextAsset = getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}") + let label: TextAsset = await getAsset("{\"id\": \"text\", \"type\": \"text\", \"value\":\"hello world\"}") else { return XCTFail("could not get asset") } let val = context.evaluateScript("('a')") let modelRef = ModelReference(rawValue: val) @@ -142,7 +142,7 @@ class InputAssetTests: SwiftUIAssetUnitTestCase { let model = InputAssetViewModel(data) - let view = InputAssetView(model: model) + let view = await InputAssetView(model: model) let stack = try view.inspect().vStack() diff --git a/ios/packages/reference-assets/ViewInspector/SwiftUI/TextAssetTests.swift b/ios/packages/reference-assets/ViewInspector/SwiftUI/TextAssetTests.swift index 2b66db44f..764be3556 100644 --- a/ios/packages/reference-assets/ViewInspector/SwiftUI/TextAssetTests.swift +++ b/ios/packages/reference-assets/ViewInspector/SwiftUI/TextAssetTests.swift @@ -19,7 +19,7 @@ class TextAssetTests: SwiftUIAssetUnitTestCase { override func register(registry: SwiftUIRegistry) { registry.register("text", asset: TextAsset.self) } - func testAssetDecoding() throws { + func testAssetDecoding() async throws { let json = """ { "id": "text", @@ -28,7 +28,7 @@ class TextAssetTests: SwiftUIAssetUnitTestCase { } """ - guard let text: TextAsset = getAsset(json) else { return XCTFail("could not get asset") } + guard let text: TextAsset = await getAsset(json) else { return XCTFail("could not get asset") } _ = try text.view.inspect().find(TextAssetView.self).text() diff --git a/ios/packages/test-utils-core/Sources/AssetTestHelper.swift b/ios/packages/test-utils-core/Sources/AssetTestHelper.swift new file mode 100644 index 000000000..5c70a22b7 --- /dev/null +++ b/ios/packages/test-utils-core/Sources/AssetTestHelper.swift @@ -0,0 +1,122 @@ +import Foundation +import XCTest +import JavaScriptCore + +extension JSContext { + func createAssetJsValue(string: String) -> JSValue { + guard let container = self.evaluateScript("(\(string))") else { fatalError("JSON was malformed") } + return container + } + + func loadMakeFlow() { + guard objectForKeyedSubscript("MakeFlow").isUndefined else { return } + guard + let url = ResourceUtilities.urlForFile( + name: "make-flow.prod", + ext: "js", + bundle: Bundle(for: MakeFlowResourceShim.self), pathComponent: "TestUtilities.bundle"), + let contents = try? String(contentsOf: url) + else { return } + evaluateScript(contents) + } +} + +class MakeFlowResourceShim {} + +open class AssetTestHelper where Registry: BaseAssetRegistry { + + /// The JSContext where utilities are loaded + /// and asset resolution is performed + public var context: JSContext = JSContext() + + /// A closure to create the registry for this instance of the AssetTestHelper + public var makeRegistry: () -> Registry + + /// Create an AssetTestHelper + /// - Parameter makeRegistry: A closure to create the registry + public init(makeRegistry: @escaping () -> Registry) { + self.makeRegistry = makeRegistry + context.loadMakeFlow() + } + + /// Retrieves an asset from the provided JSON string definition + /// This utilizes @player-ui/make-flow to turn a single asset into a flow + /// and then runs that flow in a headless player to allow the registry to resolve asset IDs + /// - Parameters: + /// - json: The JSON Asset definition to decode + /// - plugins: Plugins to include for the headless player that resolves the assets + /// - Returns: The decoded asset if it was decodable + public func getAsset(_ json: String, plugins: [NativePlugin] = []) async -> Asset? { + await Task { @MainActor () -> Asset? in + guard let flow = makeFlow(json) else { return nil } + let player = TestPlayer( + plugins: plugins, + registry: makeRegistry() + ) + + let root: JSValue? = try? await withCheckedThrowingContinuation { result in + player.hooks?.viewController.tap({ (viewController) in + viewController.hooks.view.tap { (view) in + view.hooks.onUpdate.tap { val in + result.resume(returning: val) + } + } + }) + player.start(flow: flow) { res in + guard case .failure(let error) = res else { return } + result.resume(throwing: error) + } + } + + let jsValue = context.createAssetJsValue(string: json) + do { + return try player.assetRegistry.decode(jsValue) as? Asset + } catch { + // If the user passed in an entire flow, decode the asset that was the root of + // the flow + guard let root = root else { return nil } + return try? player.assetRegistry.decode(root) as? Asset + } + }.value + } + + /** + Turns a single Asset JSON definition into a full flow + - parameters: + - json: The JSON definition of a single asset + - returns: A string that is a full JSON flow containing the single asset + */ + public func makeFlow(_ json: String) -> String? { + return context.evaluateScript("JSON.stringify(MakeFlow.makeFlow(\(json)))")?.toString() + } +} + +public typealias SwiftUIAssetTestHelper = AssetTestHelper + +public extension AssetTestHelper where WrapperType == WrappedAsset, Registry == SwiftUIRegistry { + /// An AssetTestHelper for `SwiftUIAsset` + static var swiftui: SwiftUIAssetTestHelper { + AssetTestHelper { SwiftUIRegistry(logger: TapableLogger()) } + } +} + +public extension AssetTestHelper where WrapperType == WrappedAsset { + /** + Wraps a completion handler into a WrappedFunction for using XCTestExpectations to test functions + that are added to assets via a JS transform + - parameters: + - completion: A completion handler to run when the function is invoked + - returns: A WrappedFunction that will call your completion handler + */ + func getWrappedFunction(completion: @escaping () -> Void) -> WrappedFunction? { + let callback: @convention(block) (JSValue) -> JSValue = { value in + completion() + return value + } + + guard + let function = JSValue(object: callback, in: context) + else { return nil } + return WrappedFunction(rawValue: function) + } +} diff --git a/ios/packages/test-utils-core/Tests/AssetTestHelperTests.swift b/ios/packages/test-utils-core/Tests/AssetTestHelperTests.swift new file mode 100644 index 000000000..5e496e7ef --- /dev/null +++ b/ios/packages/test-utils-core/Tests/AssetTestHelperTests.swift @@ -0,0 +1,92 @@ +import XCTest +@testable import PlayerUI + +class AssetTestHelperTests: XCTestCase { + let helper = AssetTestHelper> { + BaseAssetRegistry(logger: TapableLogger()) + } + + struct TestPlugin: NativePlugin { + var pluginName: String = "TestPlugin" + func apply

(player: P) where P: HeadlessPlayer { + guard let player = player as? TestPlayer> else { return } + player.assetRegistry.register("test", asset: TestAssetType.self) + } + } + + var plugins: [NativePlugin] = [ + TestPlugin() + ] + + func testRegistration() { + let player = TestPlayer>( + plugins: plugins, + registry: BaseAssetRegistry(logger: TapableLogger()) + ) + XCTAssertEqual(player.assetRegistry.registeredAssets.count, 1) + } + + func testShouldNotDecode() async { + let assetJSON = """ + { + "id": "test-id", + "type": "test", + "value": 1 + } + """ + let asset: TestAssetType? = await helper.getAsset(assetJSON, plugins: plugins) + + XCTAssertNil(asset) + } + + func testShouldDecode() async { + let assetJSON = """ + { + "id": "test-id", + "type": "test", + "value": "test value" + } + """ + let asset: TestAssetType? = await helper.getAsset(assetJSON, plugins: plugins) + + XCTAssertNotNil(asset) + XCTAssertEqual("test value", asset?.value) + } + + func testShouldDecodeFlow() async { + let assetJSON = """ + { + "id": "generated-flow", + "views": [ + { + "id": "test-id", + "type": "test", + "value": "test value" + } + ], + "data": {}, + "navigation": { + "BEGIN": "FLOW_1", + "FLOW_1": { + "startState": "VIEW_1", + "VIEW_1": { + "state_type": "VIEW", + "ref": "test-id", + "transitions": { + "*": "END_Done" + } + }, + "END_Done": { + "state_type": "END", + "outcome": "done" + } + } + } + } + """ + let asset: TestAssetType? = await helper.getAsset(assetJSON, plugins: plugins) + + XCTAssertNotNil(asset) + XCTAssertEqual("test value", asset?.value) + } +} diff --git a/ios/packages/test-utils/Sources/unit-test/AssetUnitTestCaseBase.swift b/ios/packages/test-utils/Sources/unit-test/AssetUnitTestCaseBase.swift deleted file mode 100644 index d83e24f45..000000000 --- a/ios/packages/test-utils/Sources/unit-test/AssetUnitTestCaseBase.swift +++ /dev/null @@ -1,51 +0,0 @@ -// -// AssetUnitTestCaseBase.swift -// PlayerUI -// -// Created by Harris Borawski on 3/8/21. -// - -import Foundation -import XCTest -import JavaScriptCore - -/** - Shared functionality for Creating flows for unit test cases - */ -open class AssetUnitTestCaseBase: XCTestCase { - // MARK: Private Properties - - /// The context used for makeFlow - public var context: JSContext = JSContext() - - /** - Sets up utilities before tests - */ - open override func setUp() { - guard - let url = ResourceUtilities.urlForFile( - name: "make-flow.prod", - ext: "js", - bundle: Bundle(for: AssetUnitTestCaseBase.self), pathComponent: "TestUtilities.bundle"), - let contents = try? String(contentsOf: url) - else { return } - context.evaluateScript(contents) - } - - /** - Turns a single Asset JSON definition into a full flow - - parameters: - - json: The JSON definition of a single asset - - returns: A string that is a full JSON flow containing the single asset - */ - public func makeFlow(_ json: String) -> String? { - return context.evaluateScript("JSON.stringify(MakeFlow.makeFlow(\(json)))")?.toString() - } -} - -extension JSContext { - func createAssetJsValue(string: String) -> JSValue { - guard let container = self.evaluateScript("(\(string))") else { fatalError("JSON was malformed") } - return container - } -} diff --git a/ios/packages/test-utils/Sources/unit-test/SwiftUIAssetUnitTestCase.swift b/ios/packages/test-utils/Sources/unit-test/SwiftUIAssetUnitTestCase.swift index d253ec74a..684b99954 100644 --- a/ios/packages/test-utils/Sources/unit-test/SwiftUIAssetUnitTestCase.swift +++ b/ios/packages/test-utils/Sources/unit-test/SwiftUIAssetUnitTestCase.swift @@ -9,11 +9,12 @@ import Foundation import JavaScriptCore import SwiftUI import Combine +import XCTest /** A base class to use for SwiftUIAsset unit tests */ -open class SwiftUIAssetUnitTestCase: AssetUnitTestCaseBase, NativePlugin { +open class SwiftUIAssetUnitTestCase: XCTestCase, NativePlugin { // MARK: NativePlugin protocol adherence /// The name of this plugin @@ -44,36 +45,19 @@ open class SwiftUIAssetUnitTestCase: AssetUnitTestCaseBase, NativePlugin { */ open func plugins() -> [NativePlugin] { [] } + public var helper = AssetTestHelper.swiftui + + public var context: JSContext { helper.context } + /** Gets an asset from the given JSON if it is decodable - parameters: - json: The JSON definition for the asset you want to construct + - plugins: Additional plugins to include when resolving the asset - returns: The decoded asset if it was possible to decode */ - public func getAsset(_ json: String, plugins: [NativePlugin] = []) -> T? { - guard let flow = makeFlow(json) else { return nil } - let player = TestPlayer(plugins: plugins + self.plugins() + [self], registry: SwiftUIRegistry(logger: TapableLogger())) - let update = expectation(description: "initial view update") - var rootVal: JSValue? - player.hooks?.viewController.tap({ (viewController) in - viewController.hooks.view.tap { (view) in - view.hooks.onUpdate.tap { val in - rootVal = val - update.fulfill() - } - } - }) - player.start(flow: flow) {_ in } - wait(for: [update], timeout: 2) - let jsValue = context.createAssetJsValue(string: json) - do { - return try player.assetRegistry.decode(jsValue) as? T - } catch { - // If the user passed in an entire flow, decode the asset that was the root of - // the flow - guard let root = rootVal else { return nil } - return try? player.assetRegistry.decode(root) as? T - } + public func getAsset(_ json: String, plugins: [NativePlugin] = []) async -> T? { + await helper.getAsset(json, plugins: plugins + self.plugins() + [self]) } /** @@ -84,14 +68,6 @@ open class SwiftUIAssetUnitTestCase: AssetUnitTestCaseBase, NativePlugin { - returns: A WrappedFunction that will call your completion handler */ public func getWrappedFunction(completion: @escaping () -> Void) -> WrappedFunction? { - let callback: @convention(block) (JSValue) -> JSValue = { value in - completion() - return value - } - - guard - let function = JSValue(object: callback, in: context) - else { return nil } - return WrappedFunction(rawValue: function) + helper.getWrappedFunction(completion: completion) } } diff --git a/ios/packages/test-utils/Tests/unit-test/AssetUnitTestCaseTests.swift b/ios/packages/test-utils/Tests/unit-test/AssetUnitTestCaseTests.swift index b76411f68..57f9d86f8 100644 --- a/ios/packages/test-utils/Tests/unit-test/AssetUnitTestCaseTests.swift +++ b/ios/packages/test-utils/Tests/unit-test/AssetUnitTestCaseTests.swift @@ -30,7 +30,6 @@ class ExampleAsset: UncontrolledAsset { override var view: AnyView { AnyView(ExampleAssetView(model: model)) } } - class AssetUnitTestDefaultTests: SwiftUIAssetUnitTestCase { func testDefaultRegister() { let player = TestPlayer(plugins: [self], registry: SwiftUIRegistry(logger: TapableLogger())) @@ -52,19 +51,19 @@ class AssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { XCTAssertEqual(0, self.plugins().count) } - func testShouldNotDecode() { + func testShouldNotDecode() async { let assetJSON = """ { "id": "test-id", "type": "test" } """ - let asset: ExampleAsset? = getAsset(assetJSON) + let asset: ExampleAsset? = await getAsset(assetJSON) XCTAssertNil(asset) } - func testShouldDecode() { + func testShouldDecode() async { let assetJSON = """ { "id": "test-id", @@ -72,13 +71,13 @@ class AssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { "value": "test value" } """ - let asset: ExampleAsset? = getAsset(assetJSON) + let asset: ExampleAsset? = await getAsset(assetJSON) XCTAssertNotNil(asset) XCTAssertEqual("test value", asset?.model.data.value) } - func testShouldDecodeFlow() { + func testShouldDecodeFlow() async { let assetJSON = """ { "id": "generated-flow", @@ -109,13 +108,13 @@ class AssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { } } """ - let asset: ExampleAsset? = getAsset(assetJSON) + let asset: ExampleAsset? = await getAsset(assetJSON) XCTAssertNotNil(asset) XCTAssertEqual("test value", asset?.model.data.value) } - func testShouldRunFunction() { + func testShouldRunFunction() async { let assetJSON = """ { "id": "test-id", @@ -125,7 +124,7 @@ class AssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { """ let functionExpecation = expectation(description: "FunctionWrapper called") guard - let asset: ExampleAsset = getAsset(assetJSON), + let asset: ExampleAsset = await getAsset(assetJSON), let function: WrappedFunction = getWrappedFunction(completion: { functionExpecation.fulfill() }) diff --git a/ios/packages/test-utils/ViewInspector/unit-test/SwiftUIAssetUnitTestCaseTests.swift b/ios/packages/test-utils/ViewInspector/unit-test/SwiftUIAssetUnitTestCaseTests.swift index eb7cd2219..66d17793c 100644 --- a/ios/packages/test-utils/ViewInspector/unit-test/SwiftUIAssetUnitTestCaseTests.swift +++ b/ios/packages/test-utils/ViewInspector/unit-test/SwiftUIAssetUnitTestCaseTests.swift @@ -59,19 +59,19 @@ class SwiftUIAssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { XCTAssertEqual(0, self.plugins().count) } - func testShouldNotDecode() { + func testShouldNotDecode() async { let assetJSON = """ { "id": "test-id", "type": "test" } """ - let asset: ExampleSwiftUIAsset? = getAsset(assetJSON) + let asset: ExampleSwiftUIAsset? = await getAsset(assetJSON) XCTAssertNil(asset) } - func testShouldDecode() { + func testShouldDecode() async { let assetJSON = """ { "id": "test-id", @@ -79,13 +79,13 @@ class SwiftUIAssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { "value": "test value" } """ - let asset: ExampleSwiftUIAsset? = getAsset(assetJSON) + let asset: ExampleSwiftUIAsset? = await getAsset(assetJSON) XCTAssertNotNil(asset) XCTAssertEqual("test value", asset?.model.data.value) } - func testShouldDecodeFlow() { + func testShouldDecodeFlow() async { let assetJSON = """ { "id": "generated-flow", @@ -116,7 +116,7 @@ class SwiftUIAssetUnitTestCaseTests: SwiftUIAssetUnitTestCase { } } """ - let asset: ExampleSwiftUIAsset? = getAsset(assetJSON) + let asset: ExampleSwiftUIAsset? = await getAsset(assetJSON) XCTAssertNotNil(asset) XCTAssertEqual("test value", asset?.model.data.value) diff --git a/xcode/Podfile b/xcode/Podfile index 4c9c873b7..d12c7aab8 100644 --- a/xcode/Podfile +++ b/xcode/Podfile @@ -10,6 +10,7 @@ target 'PlayerUI_Example' do # Packages pod 'PlayerUI/Core', :path => '../' + pod 'PlayerUI/TestUtilitiesCore', :path => '../' pod 'PlayerUI/TestUtilities', :path => '../' pod 'PlayerUI/ReferenceAssets', :path => '../' pod 'PlayerUI/SwiftUI', :path => '../' diff --git a/xcode/Podfile.lock b/xcode/Podfile.lock index 4a41cb505..57bc28d90 100644 --- a/xcode/Podfile.lock +++ b/xcode/Podfile.lock @@ -53,6 +53,10 @@ PODS: - PlayerUI/TestUtilities (0.0.1-placeholder): - PlayerUI/Core - PlayerUI/SwiftUI + - PlayerUI/TestUtilitiesCore + - PlayerUI/TestUtilitiesCore (0.0.1-placeholder): + - PlayerUI/Core + - PlayerUI/SwiftUI - PlayerUI/TransitionPlugin (0.0.1-placeholder): - PlayerUI/Core - PlayerUI/SwiftUI @@ -93,6 +97,7 @@ DEPENDENCIES: - PlayerUI/ReferenceAssets (from `../`) - PlayerUI/SwiftUI (from `../`) - PlayerUI/TestUtilities (from `../`) + - PlayerUI/TestUtilitiesCore (from `../`) - PlayerUI/TransitionPlugin (from `../`) - PlayerUI/TypesProviderPlugin (from `../`) - PlayerUI/Unit (from `../`) @@ -113,11 +118,11 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: EyesXCUI: bbb10a48b8bd1a15d541f2bc1f4d18f4db654ef1 - PlayerUI: 56261b220ac9bf2aa4620162f97313e3663ac266 + PlayerUI: 09b8d103175ee046a5e081360a332ea2ddc15080 SwiftHooks: 3ecc67c23da335d44914a8a74bd1dd23c7c149e6 SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d ViewInspector: 53313c757eddc5c4842bc7943a66821a68d02d3e -PODFILE CHECKSUM: 987897c2598f00d1d745dbbae904dfdcd919831d +PODFILE CHECKSUM: 6cb074ce93caffedf67f4b2c3a3f608523d73daa COCOAPODS: 1.11.3