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

Report coverage #15

Merged
merged 2 commits into from
May 6, 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var package = Package(
]
),
.testTarget(
name: "ComposableLoadableXCTests",
name: "ComposableLoadableTests",
dependencies: [
"CommonTestHelpers",
"ComposableLoadable",
Expand Down
52 changes: 0 additions & 52 deletions Package@swift-5.10.swift

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# swift-composable-loadable

[![CI/CD](https://github.com/danthorpe/swift-composable-loadable/actions/workflows/main.yml/badge.svg)](https://github.com/danthorpe/swift-composable-loadable/actions/workflows/main.yml)
[![CI/CD](https://github.com/danthorpe/swift-composable-loadable/actions/workflows/main.yml/badge.svg)](https://github.com/danthorpe/swift-composable-loadable/actions/workflows/main.yml) [![codecov](https://codecov.io/github/danthorpe/swift-composable-loadable/graph/badge.svg?token=4RI5GTSZ4F)](https://codecov.io/github/danthorpe/swift-composable-loadable)

A Swift Composable Architecture component for loadable features.

Expand Down
40 changes: 19 additions & 21 deletions Tests/ComposableLoadableTests/LoadableActionTests.swift
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()))
)
}
}
43 changes: 24 additions & 19 deletions Tests/ComposableLoadableTests/LoadableReducerTests.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import ComposableArchitecture
import Testing
import XCTest

@testable import CommonTestHelpers
@testable import ComposableLoadable

@Suite("Reducer Basics")
@MainActor struct ReducerBasicTests {

let request = "Hello"
fileprivate let store = TestStore(initialState: ParentFeature.State()) {
ParentFeature()
} withDependencies: {
$0.testClient.getValue = { input in
#expect(input == "Hello")
return 100
final class ReducerBasicTests: XCTestCase {

@MainActor func test__happy_path() async throws {
let request = "Hello"
let store = TestStore(initialState: ParentFeature.State()) {
ParentFeature()
} withDependencies: {
$0.testClient.getValue = { input in
XCTAssertEqual(input, "Hello")
return 100
}
}
}

@Test("Happy Path Journey")
func happyPath() async throws {

await store.send(.counter(.load(request))) {
$0.$counter.previous = .pending
Expand All @@ -31,7 +28,7 @@ import Testing
}

store.dependencies.testClient.getValue = { input in
#expect(input == request)
XCTAssertEqual(input, request)
return 200
}

Expand All @@ -47,7 +44,7 @@ import Testing

let expectedError = TestFeatureClientError()
store.dependencies.testClient.getValue = { input in
#expect(input == request)
XCTAssertEqual(input, request)
throw expectedError
}

Expand All @@ -62,8 +59,16 @@ import Testing
}
}

@Test("Child Reducer")
func childReducer() async throws {
@MainActor func test__child_reducer() async throws {
let request = "Hello"
let store = TestStore(initialState: ParentFeature.State()) {
ParentFeature()
} withDependencies: {
$0.testClient.getValue = { input in
XCTAssertEqual(input, "Hello")
return 100
}
}

await store.send(.counter(.load(request))) {
$0.$counter.previous = .pending
Expand Down
147 changes: 60 additions & 87 deletions Tests/ComposableLoadableTests/LoadableStateTests.swift
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)
}
}
8 changes: 0 additions & 8 deletions Tests/ComposableLoadableTests/Scaffold.swift

This file was deleted.

Loading