Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yalishanda42 committed Aug 12, 2023
1 parent 7baa4ef commit e3d79a9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ final class SearchStationDomainTests: XCTestCase {
let query = "соф"

let store = TestStore(
initialState: SearchStationReducer.State(),
reducer: SearchStationReducer(allStations: [.sofia, .dobrich])
)
initialState: SearchStationReducer.State()
) {
SearchStationReducer(allStations: [.sofia, .dobrich])
}

await store.send(.updateQuery(query)) {
$0.query = query
Expand All @@ -23,9 +24,10 @@ final class SearchStationDomainTests: XCTestCase {
let query = "asdfg"

let store = TestStore(
initialState: SearchStationReducer.State(),
reducer: SearchStationReducer(allStations: [.sofia, .dobrich])
)
initialState: SearchStationReducer.State()
) {
SearchStationReducer(allStations: [.sofia, .dobrich])
}

await store.send(.updateQuery(query)) {
$0.query = query
Expand All @@ -40,9 +42,10 @@ final class SearchStationDomainTests: XCTestCase {
]

let store = TestStore(
initialState: SearchStationReducer.State(filteredStations: all),
reducer: SearchStationReducer(allStations: all)
)
initialState: SearchStationReducer.State(filteredStations: all)
) {
SearchStationReducer(allStations: all)
}

await store.send(.updateQuery(query)) // no modification expected
}
Expand All @@ -52,9 +55,10 @@ final class SearchStationDomainTests: XCTestCase {
let store = TestStore(
initialState: SearchStationReducer.State(
locationStatus: .notYetAskedForAuthorization
),
reducer: SearchStationReducer()
)
) {
SearchStationReducer()
} withDependencies: {
$0.locationService.requestAuthorization = {
await serviceSpy.call()
}
Expand All @@ -73,9 +77,10 @@ final class SearchStationDomainTests: XCTestCase {
let store = TestStore(
initialState: SearchStationReducer.State(
locationStatus: .authorized(nearestStation: nil)
),
reducer: SearchStationReducer()
)
) {
SearchStationReducer()
} withDependencies: {
$0.locationService.manuallyRefreshStatus = {
await serviceSpy.call()
}
Expand All @@ -94,9 +99,10 @@ final class SearchStationDomainTests: XCTestCase {
let store = TestStore(
initialState: SearchStationReducer.State(
locationStatus: .denied
),
reducer: SearchStationReducer()
)
) {
SearchStationReducer()
} withDependencies: {
$0.settingsService.openSettings = {
await serviceSpy.call()
}
Expand All @@ -120,9 +126,10 @@ final class SearchStationDomainTests: XCTestCase {
let clock = TestClock()
let counter = Spy()
let store = TestStore(
initialState: SearchStationReducer.State(),
reducer: SearchStationReducer()
initialState: SearchStationReducer.State()
) {
SearchStationReducer()
} withDependencies: {
$0.locationService.statusStream = {
AsyncStream {
for await _ in clock.timer(interval: .seconds(1)) {
Expand Down Expand Up @@ -153,9 +160,10 @@ final class SearchStationDomainTests: XCTestCase {
let expected: [BGStation] = [.dobrich, .povelyanovo, .sofia]

let store = TestStore(
initialState: SearchStationReducer.State(),
reducer: SearchStationReducer()
initialState: SearchStationReducer.State()
) {
SearchStationReducer()
} withDependencies: {
$0.favoritesService.loadFavorites = { expected }
$0.locationService.statusStream = { AsyncStream { _ in /* never */ } }
}
Expand All @@ -173,9 +181,10 @@ final class SearchStationDomainTests: XCTestCase {
let spy = Spy()

let store = TestStore(
initialState: SearchStationReducer.State(),
reducer: SearchStationReducer()
initialState: SearchStationReducer.State()
) {
SearchStationReducer()
} withDependencies: {
$0.favoritesService.saveFavorites = { _ in
await spy.call()
}
Expand Down Expand Up @@ -205,9 +214,10 @@ final class SearchStationDomainTests: XCTestCase {
let store = TestStore(
initialState: SearchStationReducer.State(
favoriteStations: initial
),
reducer: SearchStationReducer()
)
) {
SearchStationReducer()
} withDependencies: {
$0.favoritesService.saveFavorites = { _ in
await spy.call()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ final class StationDomainTests: XCTestCase {
let expected = Self.expectedOne

let store = TestStore(
initialState: .init(station: .sofia),
reducer: StationReducer()
initialState: .init(station: .sofia)
) {
StationReducer()
} withDependencies: {
$0.stationRepository = StationRepository(
fetchTrainsAtStation: { _ in expected }
)
Expand All @@ -39,9 +40,10 @@ final class StationDomainTests: XCTestCase {
loadingState: .loaded,
trains: Self.expectedOne,
lastUpdateTime: Self.dateOne
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.stationRepository = StationRepository(
fetchTrainsAtStation: { _ in throw error }
)
Expand All @@ -66,9 +68,10 @@ final class StationDomainTests: XCTestCase {
loadingState: .loaded,
trains: Self.expectedOne,
lastUpdateTime: Self.dateOne
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.stationRepository = StationRepository(
fetchTrainsAtStation: { _ in expected }
)
Expand All @@ -94,9 +97,10 @@ final class StationDomainTests: XCTestCase {
let store = TestStore(
initialState: .init(
station: .sofia
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.stationRepository = StationRepository(
fetchTrainsAtStation: { _ in
let count = await counter.incremented()
Expand Down Expand Up @@ -139,9 +143,10 @@ final class StationDomainTests: XCTestCase {
initialState: .init(
station: .sofia,
lastUpdateTime: Date(timeIntervalSinceReferenceDate: 51)
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.date.now = dateInNextMinute
$0.calendar = Calendar(identifier: .gregorian)
$0.stationRepository.fetchTrainsAtStation = { _ in [] }
Expand All @@ -165,9 +170,10 @@ final class StationDomainTests: XCTestCase {
initialState: .init(
station: .sofia,
lastUpdateTime: Date(timeIntervalSinceReferenceDate: 51)
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.date.now = Date(timeIntervalSinceReferenceDate: 52)
$0.calendar = Calendar(identifier: .gregorian)
$0.stationRepository.fetchTrainsAtStation = { _ in [] }
Expand All @@ -183,9 +189,10 @@ final class StationDomainTests: XCTestCase {
initialState: .init(
station: .sofia,
lastUpdateTime: nil
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.date.now = dateInNextMinute
$0.calendar = Calendar(identifier: .gregorian)
$0.stationRepository.fetchTrainsAtStation = { _ in [] }
Expand All @@ -212,9 +219,10 @@ final class StationDomainTests: XCTestCase {
station: .sofia,
loadingState: .failed,
lastUpdateTime: Date(timeIntervalSinceReferenceDate: 51)
),
reducer: StationReducer()
)
) {
StationReducer()
} withDependencies: {
$0.date.now = dateInNextMinute
$0.calendar = Calendar(identifier: .gregorian)
$0.stationRepository.fetchTrainsAtStation = { _ in [] }
Expand All @@ -227,9 +235,10 @@ final class StationDomainTests: XCTestCase {
let clock = TestClock()

let store = TestStore(
initialState: .init(station: .sofia),
reducer: StationReducer()
initialState: .init(station: .sofia)
) {
StationReducer()
} withDependencies: {
$0.stationRepository = StationRepository(
fetchTrainsAtStation: { _ in
for await _ in clock.timer(interval: .seconds(1)) {
Expand Down

0 comments on commit e3d79a9

Please sign in to comment.