Files
swift-composable-architectu…/Tests/ComposableArchitectureTests/EffectOperationTests.swift
Stephen Celis 195284b94b The Composable Architecture 1.0 (#2318)
* docs

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Fix invalid states count for 3 optionals and typos (#2094)

* wip

* wip

* more dismisseffect docs

* fixed some references

* navigation doc corrections

* more nav docs

* fix cancellation tests in release mode

* wrap some tests in #if DEBUG since they are testing expected failures

* update UUIDs in tests to use shorter initializer

* fixed a todo

* wip

* fix merge errors

* wip

* fix

* wip

* wip

* fixing a bunch of todos

* get rid of rawvalue in StackElementID

* more todos

* NavLinkStore docs

* fix swift 5.6 stuff

* fix some standups tests

* fix

* clean up

* docs fix

* fixes

* wip

* 5.6 fix

* wip

* wip

* dont parallelize tests

* updated demo readmes

* wip

* Use ObservedObject instead of StateObject for alert/dialog modifiers.

* integration tests for bad dismissal behavior

* check for runtime warnings in every integration test

* wip

* wip

* wip

* fix

* wip

* wip

* wip

* wip

* wip

* wip

* Drop a bunch of Hashables.

* some nav bug fixes

* wip

* wip

* wip

* fix

* fix

* wip

* wip

* Simplify recording test.

* add concurrent async test

* fix

* wip

* Refact how detail dismisses itself.

* fix

* 5.6 fix

* wip

* wip

* wip

* wip

* Add TestStore.assert.

* Revert "Add TestStore.assert."

This reverts commit a892cccc66.

* add Ukrainian Readme.md (#2121)

* Add TestStore.assert. (#2123)

* Add TestStore.assert.

* wip

* Update Sources/ComposableArchitecture/TestStore.swift

Co-authored-by: Stephen Celis <stephen@stephencelis.com>

* Update Sources/ComposableArchitecture/Documentation.docc/Extensions/TestStore.md

Co-authored-by: Stephen Celis <stephen@stephencelis.com>

* fix tests

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>

* Run swift-format

* push for store.finish and presentation

* wip

* move docs around

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Add case subscripts

* wip

* wip

* wip

* 5.7-only

* wip

* wip

* wip

* wip

* fix

* revert store.finish task cancellation

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* add test for presentation scope

* wip

* wip

* wip

* wip

* wip

* cleanup

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Rename ReducerProtocol.swift to Reducer.swift (#2206)

* Hard-deprecate old SwitchStore initializers/overloads

* wip

* wip

* Resolve CaseStudies crash (#2258)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Bump timeout for CI

* wip

* Remove old deprecations

* Simplify test store

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* images for tutorials

* wip

* wip

* Remove deprecated alert APIs

* Bump dependencies

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
Co-authored-by: 유재호 <y73447jh@gmail.com>
Co-authored-by: Dmytro <barabashdmyto@gmail.com>
Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
Co-authored-by: mbrandonw <mbrandonw@users.noreply.github.com>
2023-07-30 14:58:40 -07:00

153 lines
3.8 KiB
Swift

#if DEBUG
import XCTest
@testable import ComposableArchitecture
@MainActor
class EffectOperationTests: BaseTCATestCase {
func testMergeDiscardsNones() async {
var effect = Effect<Int>.none
.merge(with: .none)
switch effect.operation {
case .none:
XCTAssertTrue(true)
default:
XCTFail()
}
effect = Effect<Int>.run { send in await send(42) }
.merge(with: .none)
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.none
.merge(with: .run { send in await send(42) })
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.run { await $0(42) }
.merge(with: .none)
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.none
.merge(with: .run { await $0(42) })
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
}
func testConcatenateDiscardsNones() async {
var effect = Effect<Int>.none
.concatenate(with: .none)
switch effect.operation {
case .none:
XCTAssertTrue(true)
default:
XCTFail()
}
effect = Effect<Int>.run { send in await send(42) }
.concatenate(with: .none)
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.none
.concatenate(with: .run { send in await send(42) })
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.run { send in await send(42) }
.concatenate(with: .none)
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
effect = Effect<Int>.none
.concatenate(with: .run { send in await send(42) })
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, 42) }))
default:
XCTFail()
}
}
func testMergeFuses() async {
var values = [Int]()
let effect = Effect<Int>.run { send in
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 10)
await send(42)
}
.merge(
with: .run { send in
try await Task.sleep(nanoseconds: NSEC_PER_SEC / 2)
await send(1729)
}
)
switch effect.operation {
case let .run(_, send):
await send(.init { values.append($0) })
default:
XCTFail()
}
XCTAssertEqual(values, [42, 1729])
}
func testConcatenateFuses() async {
var values = [Int]()
let effect = Effect<Int>.run { send in await send(42) }
.concatenate(with: .run { send in await send(1729) })
switch effect.operation {
case let .run(_, send):
await send(.init(send: { values.append($0) }))
default:
XCTFail()
}
XCTAssertEqual(values, [42, 1729])
}
func testMap() async {
let effect = Effect<Int>.run { send in await send(42) }
.map { "\($0)" }
switch effect.operation {
case let .run(_, send):
await send(.init(send: { XCTAssertEqual($0, "42") }))
default:
XCTFail()
}
}
}
#endif