-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial test case * Add a negative test case * Back to Dependency Client style * Move mock to test * Update MyLibrary/Sources/ScheduleFeature/Schedule.swift Co-authored-by: Daiki Matsudate <[email protected]> * Remove testValue = Self() * Create struct for response --------- Co-authored-by: Daiki Matsudate <[email protected]>
- Loading branch information
Showing
8 changed files
with
205 additions
and
20 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 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"configurations" : [ | ||
{ | ||
"id" : "235E58B3-6724-418C-907A-6211C4CC541B", | ||
"name" : "Test Scheme Action", | ||
"options" : { | ||
|
||
} | ||
} | ||
], | ||
"defaultOptions" : { | ||
"codeCoverage" : false, | ||
"targetForVariableExpansion" : { | ||
"containerPath" : "container:App.xcodeproj", | ||
"identifier" : "D563615A2B931FF800E4F789", | ||
"name" : "App" | ||
} | ||
}, | ||
"testTargets" : [ | ||
{ | ||
"target" : { | ||
"containerPath" : "container:..\/MyLibrary", | ||
"identifier" : "ScheduleFeatureTests", | ||
"name" : "ScheduleFeatureTests" | ||
} | ||
} | ||
], | ||
"version" : 1 | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Foundation | ||
import SharedModels | ||
|
||
extension Conference { | ||
static let mock1 = Self( | ||
id: 1, | ||
title: "conference1", | ||
date: Date(timeIntervalSince1970: 1_000), | ||
schedules: [ | ||
.init( | ||
time: Date(timeIntervalSince1970: 10_000), | ||
sessions: [ | ||
.mock1, | ||
.mock2, | ||
] | ||
) | ||
] | ||
) | ||
|
||
static let mock2 = Self( | ||
id: 2, | ||
title: "conference2", | ||
date: Date(timeIntervalSince1970: 2_000), | ||
schedules: [ | ||
.init( | ||
time: Date(timeIntervalSince1970: 20_000), | ||
sessions: [ | ||
.mock1, | ||
.mock2 | ||
] | ||
) | ||
] | ||
) | ||
|
||
static let mock3 = Self( | ||
id: 3, | ||
title: "conference3", | ||
date: Date(timeIntervalSince1970: 3_000), | ||
schedules: [ | ||
.init( | ||
time: Date(timeIntervalSince1970: 30_000), | ||
sessions: [ | ||
.mock1, | ||
.mock2 | ||
] | ||
) | ||
] | ||
) | ||
} | ||
|
||
extension Session { | ||
static let mock1 = Self( | ||
title: "session1", | ||
speakers: [ | ||
.mock1 | ||
], | ||
place: "place1", | ||
description: "description1", | ||
requirements: "requirements1" | ||
) | ||
|
||
static let mock2 = Self( | ||
title: "session2", | ||
speakers: [ | ||
.mock2 | ||
], | ||
place: "place2", | ||
description: "description2", | ||
requirements: "requirements2" | ||
) | ||
} | ||
|
||
extension Speaker { | ||
static let mock1 = Self( | ||
name: "speaker1", | ||
imageName: "image1", | ||
bio: "bio1", | ||
links: [ | ||
.init( | ||
name: "sns1", | ||
url: URL(string: "https://example.com/speaker1")! | ||
) | ||
] | ||
) | ||
|
||
static let mock2 = Self( | ||
name: "speaker2", | ||
imageName: "image2", | ||
bio: "bio2", | ||
links: [ | ||
.init( | ||
name: "sns2", | ||
url: URL(string: "https://example.com/speaker2")! | ||
) | ||
] | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import ComposableArchitecture | ||
import DataClient | ||
import XCTest | ||
|
||
@testable import ScheduleFeature | ||
|
||
final class ScheduleTests: XCTestCase { | ||
@MainActor | ||
func testFetchData() async { | ||
let store = TestStore(initialState: Schedule.State()) { | ||
Schedule() | ||
} withDependencies: { | ||
$0[DataClient.self].fetchDay1 = { @Sendable in .mock1 } | ||
$0[DataClient.self].fetchDay2 = { @Sendable in .mock2 } | ||
$0[DataClient.self].fetchWorkshop = { @Sendable in .mock3 } | ||
} | ||
await store.send(.view(.onAppear)) | ||
await store.receive(\.fetchResponse.success) { | ||
$0.day1 = .mock1 | ||
$0.day2 = .mock2 | ||
$0.workshop = .mock3 | ||
} | ||
} | ||
|
||
@MainActor | ||
func testFetchDataFailure() async { | ||
struct FetchError: Equatable, Error {} | ||
let store = TestStore(initialState: Schedule.State()) { | ||
Schedule() | ||
} withDependencies: { | ||
$0[DataClient.self].fetchDay1 = { @Sendable in throw FetchError() } | ||
$0[DataClient.self].fetchDay2 = { @Sendable in .mock2 } | ||
$0[DataClient.self].fetchWorkshop = { @Sendable in .mock3 } | ||
} | ||
await store.send(.view(.onAppear)) | ||
await store.receive(\.fetchResponse.failure) | ||
} | ||
} |