-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: danthorpe <[email protected]>
- Loading branch information
Showing
10 changed files
with
105 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import ComposableArchitecture | ||
import Testing | ||
import XCTest | ||
|
||
@testable import CommonTestHelpers | ||
@testable import ComposableLoadable | ||
|
||
@Suite("LoadableAction Tests") | ||
struct LoadableActionTests { | ||
final class LoadableActionTests: XCTestCase { | ||
|
||
@Test("Equatable Conformance") | ||
func equatableConformance() { | ||
func test__equatable_conformances() { | ||
typealias Action = LoadingActionWith<String, CounterFeature> | ||
#expect(Action.cancel == Action.cancel) | ||
#expect(Action.refresh == Action.refresh) | ||
#expect(Action.cancel != Action.refresh) | ||
#expect(Action.load("Hello") == Action.load("Hello")) | ||
#expect(Action.load("Hello") != Action.load("Goodbye")) | ||
#expect(Action.finished("Hello", .success(100)) == Action.finished("Hello", .success(100))) | ||
#expect(Action.finished("Hello", .success(100)) != Action.finished("Hello", .success(200))) | ||
#expect(Action.finished("Hello", .success(100)) != Action.finished("Goodbye", .success(100))) | ||
#expect( | ||
XCTAssertEqual(Action.cancel, Action.cancel) | ||
XCTAssertEqual(Action.refresh, Action.refresh) | ||
XCTAssertNotEqual(Action.cancel, Action.refresh) | ||
XCTAssertEqual(Action.load("Hello"), Action.load("Hello")) | ||
XCTAssertNotEqual(Action.load("Hello"), Action.load("Goodbye")) | ||
XCTAssertEqual(Action.finished("Hello", .success(100)), Action.finished("Hello", .success(100))) | ||
XCTAssertNotEqual(Action.finished("Hello", .success(100)), Action.finished("Hello", .success(200))) | ||
XCTAssertNotEqual(Action.finished("Hello", .success(100)), Action.finished("Goodbye", .success(100))) | ||
XCTAssertEqual( | ||
Action.finished("Hello", .failure(EquatableErrorA())), | ||
Action.finished("Hello", .failure(EquatableErrorA())) | ||
== Action.finished("Hello", .failure(EquatableErrorA())) | ||
) | ||
#expect( | ||
Action.finished("Hello", .failure(EquatableErrorA())) | ||
!= Action.finished("Goodbye", .failure(EquatableErrorA())) | ||
XCTAssertNotEqual( | ||
Action.finished("Hello", .failure(EquatableErrorA())), | ||
Action.finished("Goodbye", .failure(EquatableErrorA())) | ||
) | ||
#expect( | ||
Action.finished("Hello", .failure(EquatableErrorA())) | ||
!= Action.finished("Hello", .failure(EquatableErrorB())) | ||
XCTAssertNotEqual( | ||
Action.finished("Hello", .failure(EquatableErrorA())), | ||
Action.finished("Hello", .failure(EquatableErrorB())) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,93 @@ | ||
import Testing | ||
import Foundation | ||
import XCTest | ||
|
||
@testable import CommonTestHelpers | ||
@testable import ComposableLoadable | ||
|
||
@Suite("LoadableState Tests") | ||
struct LoadableStateTests { | ||
final class LoadableStateTests: XCTest { | ||
|
||
@Test("isPending") | ||
func isPending() { | ||
func test__isPending() { | ||
let state = LoadableState<EmptyLoadRequest, TestState>.pending | ||
#expect(state.isPending) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(nil == state.request) | ||
#expect(nil == state.value) | ||
XCTAssertTrue(state.isPending) | ||
XCTAssertFalse(state.isActive) | ||
XCTAssertFalse(state.isFailure) | ||
XCTAssertFalse(state.isSuccess) | ||
XCTAssertNil(state.request) | ||
XCTAssertNil(state.value) | ||
} | ||
|
||
@Test("isActive") | ||
func isActive() { | ||
func test__isActive() { | ||
let state = LoadableState<EmptyLoadRequest, TestState>(current: .active) | ||
#expect(state.isActive) | ||
#expect(false == state.isPending) | ||
#expect(false == state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(state.request == EmptyLoadRequest()) | ||
XCTAssertTrue(state.isActive) | ||
XCTAssertFalse(state.isPending) | ||
XCTAssertFalse(state.isFailure) | ||
XCTAssertFalse(state.isSuccess) | ||
XCTAssertEqual(state.request, EmptyLoadRequest()) | ||
} | ||
|
||
@Test("isLoaded Success") | ||
func isLoadedSuccess() { | ||
func test__isLoadedSuccess() { | ||
let state = LoadableState(success: TestState(value: 100)) | ||
#expect(state.isSuccess) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isPending) | ||
#expect(false == state.isFailure) | ||
#expect(state.request == EmptyLoadRequest()) | ||
#expect(state.wrappedValue == TestState(value: 100)) | ||
XCTAssertTrue(state.isSuccess) | ||
XCTAssertFalse(state.isActive) | ||
XCTAssertFalse(state.isPending) | ||
XCTAssertFalse(state.isFailure) | ||
XCTAssertEqual(state.request, EmptyLoadRequest()) | ||
XCTAssertEqual(state.wrappedValue, TestState(value: 100)) | ||
} | ||
|
||
@Test("isLoaded Failure") | ||
func isLoadedFailure() { | ||
func test__isLoadedFailure() { | ||
var state = LoadableState<EmptyLoadRequest, TestState>(current: .active, previous: .pending) | ||
state.finish(EmptyLoadRequest(), result: .failure(EquatableErrorA())) | ||
#expect(state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isPending) | ||
#expect(state.request == EmptyLoadRequest()) | ||
XCTAssertTrue(state.isFailure) | ||
XCTAssertFalse(state.isSuccess) | ||
XCTAssertFalse(state.isActive) | ||
XCTAssertFalse(state.isPending) | ||
XCTAssertEqual(state.request, EmptyLoadRequest()) | ||
} | ||
|
||
@Test("Set loadedValue to nil") | ||
func setLoadedValueToNil() { | ||
func test__setLoadedValueToNil() { | ||
var state = LoadableState<EmptyLoadRequest, TestState>.pending | ||
state.loadedValue = nil | ||
#expect(state.isPending) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(nil == state.request) | ||
XCTAssertTrue(state.isPending) | ||
XCTAssertFalse(state.isActive) | ||
XCTAssertFalse(state.isFailure) | ||
XCTAssertFalse(state.isSuccess) | ||
XCTAssertNil(state.request) | ||
|
||
state.loadedFailure = nil | ||
#expect(state.isPending) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(nil == state.request) | ||
XCTAssertTrue(state.isPending) | ||
XCTAssertFalse(state.isActive) | ||
XCTAssertFalse(state.isFailure) | ||
XCTAssertFalse(state.isSuccess) | ||
XCTAssertNil(state.request) | ||
} | ||
|
||
@Test("Basic happy path") | ||
func basicHappyPath() { | ||
func test__basicHappyPath() { | ||
var state = LoadableState<EmptyLoadRequest, TestState>.pending | ||
#expect(nil == state.wrappedValue) | ||
#expect(nil == state.loadedValue) | ||
#expect(nil == state.loadedFailure) | ||
XCTAssertNil(state.wrappedValue) | ||
XCTAssertNil(state.loadedValue) | ||
XCTAssertNil(state.loadedFailure) | ||
|
||
state.wrappedValue = nil | ||
#expect(nil == state.wrappedValue) | ||
#expect(nil == state.loadedValue) | ||
#expect(nil == state.loadedFailure) | ||
XCTAssertNil(state.wrappedValue) | ||
XCTAssertNil(state.loadedValue) | ||
XCTAssertNil(state.loadedFailure) | ||
|
||
state.becomeActive() | ||
#expect(state.isActive) | ||
#expect(false == state.isPending) | ||
#expect(false == state.isFailure) | ||
#expect(false == state.isSuccess) | ||
#expect(state.request == EmptyLoadRequest()) | ||
XCTAssertTrue(state.isActive) | ||
XCTAssertNil(state.isPending) | ||
XCTAssertNil(state.isFailure) | ||
XCTAssertNil(state.isSuccess) | ||
XCTAssertEqual(state.request, EmptyLoadRequest()) | ||
|
||
state.wrappedValue = TestState(value: 100) | ||
#expect(state.isSuccess) | ||
#expect(false == state.isActive) | ||
#expect(false == state.isPending) | ||
#expect(false == state.isFailure) | ||
#expect(state.request == EmptyLoadRequest()) | ||
#expect(state.wrappedValue == TestState(value: 100)) | ||
|
||
#expect(state.value == 100) | ||
} | ||
|
||
@Test("Property Wrapper basics") | ||
func propertyWrapperBasics() throws { | ||
@LoadableState<EmptyLoadRequest, TestState> var state | ||
#expect(state == nil) | ||
|
||
$state = .active | ||
#expect(state == nil) | ||
|
||
$state.finish(.success(TestState(value: 42))) | ||
#expect(state?.value == 42) | ||
|
||
$state.becomeActive() | ||
#expect(state?.value == 42) | ||
|
||
$state.finish(.failure(EquatableErrorA())) | ||
#expect(state == nil) | ||
#expect($state.isFailure) | ||
let error = try #require($state.error) | ||
#expect(_isEqual(error, EquatableErrorA())) | ||
XCTAssertTrue(state.isSuccess) | ||
XCTAssertNil(state.isActive) | ||
XCTAssertNil(state.isPending) | ||
XCTAssertNil(state.isFailure) | ||
XCTAssertEqual(state.request, EmptyLoadRequest()) | ||
XCTAssertEqual(state.wrappedValue, TestState(value: 100)) | ||
|
||
XCTAssertEqual(state.value, 100) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.