Skip to content

Commit

Permalink
Merge pull request #43 from Maks-Jago/1.4.6
Browse files Browse the repository at this point in the history
1.4.6
  • Loading branch information
Maks-Jago authored Sep 24, 2024
2 parents 657cbf3 + 9a74493 commit e6713c6
Show file tree
Hide file tree
Showing 48 changed files with 634 additions and 270 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Tests/StateCopyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class StateCopyTests: XCTestCase {
}
}

func testStateCopying() async throws {
let store = try await XCTestStore(initial: AppState())
func testStateCopying() async {
let store = await XCTestStore(initial: AppState())
await store.dispatch(Actions.UpdateFormField(keyPath: \SomeForm.item, value: .init(text: "new item text")))

let item = await store.state.someForm.item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class AppStateInitialSetupTests: XCTestCase {
}
}

func test_initialSetups() async throws {
let store = try await XCTestStore(initial: AppState())
func test_initialSetups() async {
let store = await XCTestStore(initial: AppState())

let title = await store.state.form1.title
XCTAssertEqual(title, "new title")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ final class ContainerScopeTests: XCTestCase {
var isUserLoggedIn: Bool = false
}

func test_componentRenderingAfterStateMutation() async throws {
let store = try EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
func test_componentRenderingAfterStateMutation() async {
let store = EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
let itemsContainer = ItemsListContainer()

let window = await MainActor.run {
Expand All @@ -73,8 +73,8 @@ final class ContainerScopeTests: XCTestCase {
XCTAssertEqual(itemsContainer.renderingNumber, 2)
}

func test_rootComponentRendering() async throws {
let store = try EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
func test_rootComponentRendering() async {
let store = EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
let rootContainer = RootContainer()

let window = await MainActor.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ final class ContainerWithAppStateAsScopeTests: XCTestCase {
}
}

func test_rootComponentRendering() async throws {
let store = try EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
func test_rootComponentRendering() async {
let store = EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
let rootContainer = RootContainer()
let window = await createWindow(with: rootContainer)

Expand Down Expand Up @@ -94,8 +94,8 @@ final class ContainerWithAppStateAsScopeTests: XCTestCase {
XCTAssertEqual(rootContainer.renderingNumber, 5)
}

func test_noneScope() async throws {
let store = try EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
func test_noneScope() async {
let store = EnvironmentStore(initial: AppState(), logger: TestStoreLogger())
let noneScopeContainer = NoneScopeContainer()
let window = await createWindow(with: noneScopeContainer)

Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftUI-UDF-ConcurrencyTests/DispatchActionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ final class DispatchActionsTests: XCTestCase {
var title: String = ""
}

func test_UpdateFormFieldDispatch() async throws {
let store = try InternalStore(initial: AppState(), loggers: [])
func test_UpdateFormFieldDispatch() async {
let store = InternalStore(initial: AppState(), loggers: [])
var formTitle = await store.state.plainForm.title
XCTAssertEqual(formTitle, "")

Expand All @@ -39,7 +39,7 @@ final class DispatchActionsTests: XCTestCase {

XCTAssertTrue(messageInternalUnwrappedAction.silent)

let testStore = try await XCTestStore(initial: AppState())
let testStore = await XCTestStore(initial: AppState())
await testStore.dispatch(Actions.Message(id: "1"))
await testStore.dispatch(Actions.Message(id: "2").silent())
await testStore.dispatch(Actions.Message(id: "3"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ final class ConcurrencyMiddlewareCancellationTests: XCTestCase {
}
}

func testObservableMiddlewareCancellation() async throws {
let store = try await XCTestStore(initial: AppState())
func testObservableMiddlewareCancellation() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(ObservableMiddlewareToCancel.self)
await store.dispatch(Actions.Loading())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ final class MiddlewareCancellationTests: XCTestCase {
}
}

func testObservableMiddlewareCancellation() async throws {
let store = try await XCTestStore(initial: AppState())
func testObservableMiddlewareCancellation() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(ObservableMiddlewareToCancel.self)
await store.dispatch(Actions.Loading())

Expand All @@ -70,8 +70,8 @@ final class MiddlewareCancellationTests: XCTestCase {
XCTAssertEqual(middlewareFlow, .didCancel)
}

func testObservableRunMiddlewareToCancel() async throws {
let store = try await XCTestStore(initial: AppState())
func testObservableRunMiddlewareToCancel() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(ObservableRunMiddlewareToCancel.self)
await store.dispatch(Actions.Loading())

Expand All @@ -86,8 +86,8 @@ final class MiddlewareCancellationTests: XCTestCase {
XCTAssertEqual(middlewareFlow, .didCancel)
}

func testReducibleMiddlewareToCancel() async throws {
let store = try await XCTestStore(initial: AppState())
func testReducibleMiddlewareToCancel() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(ReducibleMiddlewareToCancel.self)
await store.dispatch(Actions.Loading())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ final class MiddlewareMapErrorTests: XCTestCase {
}
}

func testMapError() async throws {
let store = try await XCTestStore(initial: AppState())
func testMapError() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(LoadingMiddleware.self)

await store.dispatch(Actions.StartLoading())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fileprivate extension Actions {
@available(iOS 16.0.0, *)
final class MiddlewareSubscriptionTests: XCTestCase {

func testMiddlewareSubscriptions() async throws {
let store = try await XCTestStore(initial: AppState())
func testMiddlewareSubscriptions() async {
let store = await XCTestStore(initial: AppState())

await store.subscribe(build: { store in
ObservableMiddleware.self
Expand All @@ -34,8 +34,8 @@ final class MiddlewareSubscriptionTests: XCTestCase {
XCTAssertEqual(type, .reducible)
}

func testEnvironmentMiddlewareSubscription() async throws {
let store = try await XCTestStore(initial: AppState())
func testEnvironmentMiddlewareSubscription() async {
let store = await XCTestStore(initial: AppState())

await store.subscribe { store in
EnvironmentMiddleware.self
Expand All @@ -46,8 +46,8 @@ final class MiddlewareSubscriptionTests: XCTestCase {
XCTAssertEqual(middlewareId, .testEnvironment)
}

func liveEnvironmentMiddlewareSubscription() async throws {
let store = try await XCTestStore(initial: AppState())
func liveEnvironmentMiddlewareSubscription() async {
let store = await XCTestStore(initial: AppState())

setLiveEnvironment()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ final class NewObservableMiddlewareDDosProtectionTests: XCTestCase {
}
}

func testObservableMiddlewareDDDos() async throws {
let store = try await XCTestStore(initial: AppState())
func testObservableMiddlewareDDDos() async {
let store = await XCTestStore(initial: AppState())

await store.subscribe(SendMessageMiddleware.self)
await store.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ final class NewReducibleMiddlewareTests: XCTestCase {
}
}

func testReducibleMiddleware() async throws {
let store = try await XCTestStore(initial: AppState())
func testReducibleMiddleware() async {
let store = await XCTestStore(initial: AppState())
await store.subscribe(SendMessageMiddleware.self)

var formTitle = await store.state.testForm.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class StoreInitializationTests: XCTestCase {
var store: InternalStore<AppState>!

override func setUpWithError() throws {
store = try InternalStore(initial: AppState(), loggers: [])
store = InternalStore(initial: AppState(), loggers: [])
}

func test_middlewareAsyncSubscription() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
import XCTest
@testable import UDF

fileprivate extension Actions {
struct Message: Action {
public var message: String?
public var id: AnyHashable

public init<Id: Hashable>(message: String? = nil, id: Id) {
self.message = message?.isEmpty == true ? nil : message
self.id = AnyHashable(id)
}
}
}

final class ActionGroupBuilderTests: XCTestCase {

func test_WhenVoid_ActionGroupShouldBeEmpty() {
Expand Down Expand Up @@ -135,4 +123,16 @@ final class ActionGroupBuilderTests: XCTestCase {

XCTAssertEqual(group.actions.count, 5)
}

func test_OptionalAction() {
let optionalActionWithValue: (any Action)? = Actions.Message(message: "m1", id: "m1")
let optionalActionNil: (any Action)? = nil

let group = ActionGroup {
optionalActionWithValue
optionalActionNil
}

XCTAssertEqual(group.actions.count, 1)
}
}
37 changes: 37 additions & 0 deletions Tests/SwiftUI-UDF-Tests/Alert/AlertActionBuilderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import XCTest
@testable import UDF

final class AlertActionBuilderTests: XCTestCase {
func test_WhenVoid_ActionGroupShouldBeEmpty() {
let style = AlertBuilder.AlertStyle.init(title: "", text: "") {
()
}

let alertType = style.type

switch alertType {
case .customActions(_, _, let actions):
XCTAssertTrue(actions().isEmpty, "An Alert should have no action when there is some Void in the builder")

default:
XCTFail("Alert type should be custom")
}
}

func test_AlertButton() {
let style = AlertBuilder.AlertStyle.init(title: "", text: "") {
AlertButton.cancel("Cancel")
}

let alertType = style.type

switch alertType {
case .customActions(_, _, let actions):
XCTAssertEqual(actions().count, 1)

default:
XCTFail("Alert type should be custom")
}
}
}
8 changes: 4 additions & 4 deletions Tests/SwiftUI-UDF-Tests/AlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ fileprivate extension Actions {
extension AlertBuilder.AlertStyle {
static func alertWithAction(_ action: @escaping () -> Void) -> Self {
.init(title: "Custom alert title with action", text: "Custom alert text with action") {
AlertAction(title: "Action button", action: action)
AlertButton(title: "Action button", action: action)

AlertAction(title: "Cancel")
AlertButton(title: "Cancel")
.role(.cancel)
}
}
Expand Down Expand Up @@ -41,8 +41,8 @@ final class AlertTests: XCTestCase {
}
}

func test_WhenAlerBuilderRegistered_AlertCanBePresentedById() async throws {
let store = try await XCTestStore(initial: AppState())
func test_WhenAlerBuilderRegistered_AlertCanBePresentedById() async {
let store = await XCTestStore(initial: AppState())
var status = await store.state.form.alert.status

XCTAssertEqual(status, .dismissed)
Expand Down
16 changes: 8 additions & 8 deletions Tests/SwiftUI-UDF-Tests/Cached/CachedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class CachedTests: XCTestCase {
}
}

func testItemsCaching() async throws {
var store = try await XCTestStore(initial: AppState())
func testItemsCaching() async {
var store = await XCTestStore(initial: AppState())

let items = (0...3).map { Item(id: .init(value: $0)) }
await store.dispatch(Actions.DidLoadItems(items: items, id: "items"))
Expand All @@ -72,7 +72,7 @@ class CachedTests: XCTestCase {

await fulfill(description: "waiting for cache syncing", sleep: 1.5)

store = try await .init(initial: AppState())
store = await .init(initial: AppState())
isEmpty = await store.state.nestedForm.items.isEmpty

XCTAssertFalse(isEmpty)
Expand All @@ -81,8 +81,8 @@ class CachedTests: XCTestCase {
XCTAssertEqual(count, 4)
}

func testResetCache() async throws {
let store = try await XCTestStore(initial: AppState())
func testResetCache() async {
let store = await XCTestStore(initial: AppState())
let items = (0...3).map { Item(id: .init(value: $0)) }
await store.dispatch(Actions.DidLoadItems(items: items, id: "items"))

Expand All @@ -99,8 +99,8 @@ class CachedTests: XCTestCase {
XCTAssertTrue(isEmpty)
}

func testSingleObjectCaching() async throws {
let store = try await XCTestStore(initial: AppState())
func testSingleObjectCaching() async {
let store = await XCTestStore(initial: AppState())

var selectedItem = await store.state.nestedForm.selectedItem
XCTAssertNil(selectedItem)
Expand All @@ -117,7 +117,7 @@ class CachedTests: XCTestCase {
}

func testRemoveItemFromCacheById() async throws {
let store = try await XCTestStore(initial: AppState())
let store = await XCTestStore(initial: AppState())
await store.dispatch(Actions.ResetCache())

let items = [Item(id: .init(value: 0))]
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftUI-UDF-Tests/ContainerLifecycleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ final class ContainerLifecycleTests: XCTestCase {
}

@MainActor
func test_ContainerLifecycle() async throws {
let store = try EnvironmentStore(initial: AppState(), logger: .consoleDebug)
func test_ContainerLifecycle() async {
let store = EnvironmentStore(initial: AppState(), logger: .consoleDebug)
let rootContainer = RootContainer()

var window: UIWindow? = await MainActor.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MergeableAppStateTests: XCTestCase {
}

func testItemMerging() async throws {
let store = try await XCTestStore(initial: AppState())
let store = await XCTestStore(initial: AppState())
var item = Item(id: .init(value: 1), title: "original")
await store.dispatch(Actions.DidLoadItem(item: item))

Expand Down
Loading

0 comments on commit e6713c6

Please sign in to comment.