-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add initial test cases #38
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e36e21
Add initial test case
kvvzr 7ac27fd
Add a negative test case
kvvzr 6f8eb3f
Back to Dependency Client style
kvvzr e13d8b1
Move mock to test
kvvzr bce291a
Update MyLibrary/Sources/ScheduleFeature/Schedule.swift
kvvzr 78a993e
Remove testValue = Self()
kvvzr 27d94be
Create struct for response
kvvzr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -29,7 +29,7 @@ public struct Schedule { | |||||
@Presents var destination: Destination.State? | ||||||
|
||||||
public init() { | ||||||
try! Tips.configure([.displayFrequency(.immediate)]) | ||||||
try? Tips.configure([.displayFrequency(.immediate)]) | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -38,6 +38,7 @@ public struct Schedule { | |||||
case path(StackAction<Path.State, Path.Action>) | ||||||
case destination(PresentationAction<Destination.Action>) | ||||||
case view(View) | ||||||
case fetchResponse(Result<(Conference, Conference, Conference), Error>) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better with creating struct.
Suggested change
The struct may be like below: public struct SchedulesResponse: Equatable {
var day1: Conference
var day2: Conference
var workshop: Conference
} |
||||||
|
||||||
public enum View { | ||||||
case onAppear | ||||||
|
@@ -66,10 +67,12 @@ public struct Schedule { | |||||
Reduce { state, action in | ||||||
switch action { | ||||||
case .view(.onAppear): | ||||||
state.day1 = try! dataClient.fetchDay1() | ||||||
state.day2 = try! dataClient.fetchDay2() | ||||||
state.workshop = try! dataClient.fetchWorkshop() | ||||||
return .none | ||||||
return .send(.fetchResponse(Result { | ||||||
let day1 = try dataClient.fetchDay1() | ||||||
let day2 = try dataClient.fetchDay2() | ||||||
let workshop = try dataClient.fetchWorkshop() | ||||||
return (day1, day2, workshop) | ||||||
})) | ||||||
case let .view(.disclosureTapped(session)): | ||||||
guard let description = session.description, let speakers = session.speakers else { | ||||||
return .none | ||||||
|
@@ -93,6 +96,14 @@ public struct Schedule { | |||||
#elseif os(visionOS) | ||||||
return .run { _ in await openURL(url) } | ||||||
#endif | ||||||
case let .fetchResponse(.success((day1, day2, workshop))): | ||||||
state.day1 = day1 | ||||||
state.day2 = day2 | ||||||
state.workshop = workshop | ||||||
return .none | ||||||
case let .fetchResponse(.failure(error)): | ||||||
print(error) | ||||||
return .none | ||||||
kvvzr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
case .binding, .path, .destination: | ||||||
return .none | ||||||
} | ||||||
|
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) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also macro's roll