Skip to content

Commit 298385a

Browse files
authored
Remove timeout from POSSettingsLocalCatalogViewModelTests (#16210)
2 parents 0ce61d0 + e17b4d3 commit 298385a

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

Modules/Tests/PointOfSaleTests/Mocks/MockPOSCatalogSettingsService.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ final class MockPOSCatalogSettingsService: POSCatalogSettingsServiceProtocol {
44
var catalogInfoResult: Result<POSCatalogInfo, Error> = .success(
55
.init(productCount: 0, variationCount: 0, lastFullSyncDate: nil, lastIncrementalSyncDate: nil)
66
)
7-
var shouldDelayResponse = false
7+
var onLoadCatalogInfoCalled: (() -> Void)?
88

99
func loadCatalogInfo(for siteID: Int64) async throws -> POSCatalogInfo {
10-
if shouldDelayResponse {
11-
try await Task.sleep(for: .milliseconds(100))
12-
}
10+
onLoadCatalogInfoCalled?()
1311

1412
switch catalogInfoResult {
1513
case .success(let info):

Modules/Tests/PointOfSaleTests/Mocks/MockPOSCatalogSyncCoordinator.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ final class MockPOSCatalogSyncCoordinator: POSCatalogSyncCoordinatorProtocol {
55
var performFullSyncInvocationCount = 0
66
var performFullSyncSiteID: Int64?
77
var performFullSyncResult: Result<Void, Error> = .success(())
8-
var shouldDelayResponse = false
8+
9+
var onPerformFullSyncCalled: (() -> Void)?
910

1011
func performFullSyncIfApplicable(for siteID: Int64, maxAge: TimeInterval) async throws {
11-
if shouldDelayResponse {
12-
try await Task.sleep(for: .milliseconds(100))
13-
}
12+
onPerformFullSyncCalled?()
1413

1514
performFullSyncInvocationCount += 1
1615
performFullSyncSiteID = siteID

Modules/Tests/PointOfSaleTests/Presentation/Settings/POSSettingsLocalCatalogViewModelTests.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,19 @@ struct POSSettingsLocalCatalogViewModelTests {
9191
lastFullSyncDate: nil,
9292
lastIncrementalSyncDate: nil
9393
))
94-
catalogSettingsService.shouldDelayResponse = true
9594

96-
// When
97-
let loadTask = Task {
95+
await confirmation() { confirmation in
96+
catalogSettingsService.onLoadCatalogInfoCalled = {
97+
// At the time loadCatalogInfo is called, loading is set to true
98+
#expect(sut.isLoading == true)
99+
confirmation()
100+
}
101+
102+
// When
98103
await sut.loadCatalogData()
99104
}
100105

101106
// Then
102-
try await Task.sleep(for: .milliseconds(10))
103-
#expect(sut.isLoading == true)
104-
105-
catalogSettingsService.shouldDelayResponse = false
106-
await loadTask.value
107-
108107
#expect(sut.isLoading == false)
109108
}
110109

@@ -137,20 +136,19 @@ struct POSSettingsLocalCatalogViewModelTests {
137136
lastFullSyncDate: nil,
138137
lastIncrementalSyncDate: nil
139138
))
140-
catalogSyncCoordinator.shouldDelayResponse = true
141139

142-
// When
143-
let refreshTask = Task {
140+
await confirmation() { confirmation in
141+
catalogSyncCoordinator.onPerformFullSyncCalled = {
142+
// At the time performFullSyncCalled is called, isRefreshingCatalog is set to true
143+
#expect(sut.isRefreshingCatalog == true)
144+
confirmation()
145+
}
146+
147+
// When
144148
await sut.refreshCatalog()
145149
}
146150

147151
// Then
148-
try await Task.sleep(for: .milliseconds(10))
149-
#expect(sut.isRefreshingCatalog == true)
150-
151-
catalogSyncCoordinator.shouldDelayResponse = false
152-
await refreshTask.value
153-
154152
#expect(sut.isRefreshingCatalog == false)
155153
}
156154

0 commit comments

Comments
 (0)