@@ -2,6 +2,7 @@ import Foundation
22import SwiftUI
33import Testing
44import enum WooFoundationCore. CurrencyCode
5+ import Yosemite
56@testable import PointOfSale
67
78struct PointOfSaleDashboardViewHelperTests {
@@ -17,7 +18,8 @@ struct PointOfSaleDashboardViewHelperTests {
1718 let result = PointOfSaleDashboardViewHelper . determineViewState (
1819 eligibilityState: eligibilityState,
1920 itemsContainerState: itemsContainerState,
20- horizontalSizeClass: horizontalSizeClass
21+ horizontalSizeClass: horizontalSizeClass,
22+ catalogSyncState: nil
2123 )
2224
2325 // Then
@@ -34,7 +36,8 @@ struct PointOfSaleDashboardViewHelperTests {
3436 let result = PointOfSaleDashboardViewHelper . determineViewState (
3537 eligibilityState: eligibilityState,
3638 itemsContainerState: itemsContainerState,
37- horizontalSizeClass: horizontalSizeClass
39+ horizontalSizeClass: horizontalSizeClass,
40+ catalogSyncState: nil
3841 )
3942
4043 // Then
@@ -53,7 +56,8 @@ struct PointOfSaleDashboardViewHelperTests {
5356 let result = PointOfSaleDashboardViewHelper . determineViewState (
5457 eligibilityState: eligibilityState,
5558 itemsContainerState: itemsContainerState,
56- horizontalSizeClass: horizontalSizeClass
59+ horizontalSizeClass: horizontalSizeClass,
60+ catalogSyncState: nil
5761 )
5862
5963 // Then
@@ -78,7 +82,8 @@ struct PointOfSaleDashboardViewHelperTests {
7882 let result = PointOfSaleDashboardViewHelper . determineViewState (
7983 eligibilityState: eligibilityState,
8084 itemsContainerState: itemsContainerState,
81- horizontalSizeClass: horizontalSizeClass
85+ horizontalSizeClass: horizontalSizeClass,
86+ catalogSyncState: nil
8287 )
8388
8489 // Then
@@ -97,7 +102,8 @@ struct PointOfSaleDashboardViewHelperTests {
97102 let result = PointOfSaleDashboardViewHelper . determineViewState (
98103 eligibilityState: eligibilityState,
99104 itemsContainerState: itemsContainerState,
100- horizontalSizeClass: horizontalSizeClass
105+ horizontalSizeClass: horizontalSizeClass,
106+ catalogSyncState: nil
101107 )
102108
103109 // Then
@@ -114,7 +120,8 @@ struct PointOfSaleDashboardViewHelperTests {
114120 let result = PointOfSaleDashboardViewHelper . determineViewState (
115121 eligibilityState: eligibilityState,
116122 itemsContainerState: itemsContainerState,
117- horizontalSizeClass: horizontalSizeClass
123+ horizontalSizeClass: horizontalSizeClass,
124+ catalogSyncState: nil
118125 )
119126
120127 // Then
@@ -144,7 +151,8 @@ struct PointOfSaleDashboardViewHelperTests {
144151 let result = PointOfSaleDashboardViewHelper . determineViewState (
145152 eligibilityState: eligibilityState,
146153 itemsContainerState: itemsContainerState,
147- horizontalSizeClass: horizontalSizeClass
154+ horizontalSizeClass: horizontalSizeClass,
155+ catalogSyncState: nil
148156 )
149157
150158 // Then
@@ -153,6 +161,25 @@ struct PointOfSaleDashboardViewHelperTests {
153161
154162 // MARK: - Priority Tests
155163
164+ @Test func determineViewState_catalogSync_takes_priority_over_all( ) async throws {
165+ // Given - initial sync should return catalogSyncing regardless of other states
166+ let eligibilityState : POSEligibilityState = . ineligible( reason: . featureSwitchDisabled)
167+ let itemsContainerState : ItemsContainerState = . content
168+ let horizontalSizeClass : UserInterfaceSizeClass = . compact
169+ let catalogSyncState : POSCatalogSyncState = . syncStarted( siteID: 1 , isInitialSync: true )
170+
171+ // When
172+ let result = PointOfSaleDashboardViewHelper . determineViewState (
173+ eligibilityState: eligibilityState,
174+ itemsContainerState: itemsContainerState,
175+ horizontalSizeClass: horizontalSizeClass,
176+ catalogSyncState: catalogSyncState
177+ )
178+
179+ // Then
180+ #expect( result == . catalogSyncing)
181+ }
182+
156183 @Test func determineViewState_horizontalSizeClass_takes_priority_over_eligibility_state( ) async throws {
157184 // Given - compact size class should return unsupportedWidth regardless of eligibility
158185 let eligibilityState : POSEligibilityState = . ineligible( reason: . featureSwitchDisabled)
@@ -163,7 +190,8 @@ struct PointOfSaleDashboardViewHelperTests {
163190 let result = PointOfSaleDashboardViewHelper . determineViewState (
164191 eligibilityState: eligibilityState,
165192 itemsContainerState: itemsContainerState,
166- horizontalSizeClass: horizontalSizeClass
193+ horizontalSizeClass: horizontalSizeClass,
194+ catalogSyncState: nil
167195 )
168196
169197 // Then
@@ -180,7 +208,8 @@ struct PointOfSaleDashboardViewHelperTests {
180208 let result = PointOfSaleDashboardViewHelper . determineViewState (
181209 eligibilityState: eligibilityState,
182210 itemsContainerState: itemsContainerState,
183- horizontalSizeClass: horizontalSizeClass
211+ horizontalSizeClass: horizontalSizeClass,
212+ catalogSyncState: nil
184213 )
185214
186215 // Then
@@ -197,13 +226,113 @@ struct PointOfSaleDashboardViewHelperTests {
197226 let result = PointOfSaleDashboardViewHelper . determineViewState (
198227 eligibilityState: eligibilityState,
199228 itemsContainerState: itemsContainerState,
200- horizontalSizeClass: horizontalSizeClass
229+ horizontalSizeClass: horizontalSizeClass,
230+ catalogSyncState: nil
201231 )
202232
203233 // Then
204234 #expect( result == . ineligible( reason: . featureSwitchDisabled) )
205235 }
206236
237+ // MARK: - Catalog Sync State Tests
238+
239+ @Test func determineViewState_when_catalogSync_with_initialSync_returns_catalogSyncing( ) async throws {
240+ // Given
241+ let eligibilityState : POSEligibilityState = . eligible
242+ let itemsContainerState : ItemsContainerState = . content
243+ let horizontalSizeClass : UserInterfaceSizeClass = . regular
244+ let catalogSyncState : POSCatalogSyncState = . syncStarted( siteID: 1 , isInitialSync: true )
245+
246+ // When
247+ let result = PointOfSaleDashboardViewHelper . determineViewState (
248+ eligibilityState: eligibilityState,
249+ itemsContainerState: itemsContainerState,
250+ horizontalSizeClass: horizontalSizeClass,
251+ catalogSyncState: catalogSyncState
252+ )
253+
254+ // Then
255+ #expect( result == . catalogSyncing)
256+ }
257+
258+ @Test func determineViewState_when_catalogSync_without_initialSync_continues_to_items( ) async throws {
259+ // Given
260+ let eligibilityState : POSEligibilityState = . eligible
261+ let itemsContainerState : ItemsContainerState = . content
262+ let horizontalSizeClass : UserInterfaceSizeClass = . regular
263+ let catalogSyncState : POSCatalogSyncState = . syncStarted( siteID: 1 , isInitialSync: false )
264+
265+ // When
266+ let result = PointOfSaleDashboardViewHelper . determineViewState (
267+ eligibilityState: eligibilityState,
268+ itemsContainerState: itemsContainerState,
269+ horizontalSizeClass: horizontalSizeClass,
270+ catalogSyncState: catalogSyncState
271+ )
272+
273+ // Then
274+ #expect( result == . content)
275+ }
276+
277+ @Test func determineViewState_when_syncNeverDone_returns_catalogSyncing( ) async throws {
278+ // Given
279+ let eligibilityState : POSEligibilityState = . eligible
280+ let itemsContainerState : ItemsContainerState = . content
281+ let horizontalSizeClass : UserInterfaceSizeClass = . regular
282+ let catalogSyncState : POSCatalogSyncState = . syncNeverDone( siteID: 1 )
283+
284+ // When
285+ let result = PointOfSaleDashboardViewHelper . determineViewState (
286+ eligibilityState: eligibilityState,
287+ itemsContainerState: itemsContainerState,
288+ horizontalSizeClass: horizontalSizeClass,
289+ catalogSyncState: catalogSyncState
290+ )
291+
292+ // Then
293+ #expect( result == . catalogSyncing)
294+ }
295+
296+ @Test func determineViewState_when_syncCompleted_checks_items_state( ) async throws {
297+ // Given
298+ let eligibilityState : POSEligibilityState = . eligible
299+ let itemsContainerState : ItemsContainerState = . content
300+ let horizontalSizeClass : UserInterfaceSizeClass = . regular
301+ let catalogSyncState : POSCatalogSyncState = . syncCompleted( siteID: 1 )
302+
303+ // When
304+ let result = PointOfSaleDashboardViewHelper . determineViewState (
305+ eligibilityState: eligibilityState,
306+ itemsContainerState: itemsContainerState,
307+ horizontalSizeClass: horizontalSizeClass,
308+ catalogSyncState: catalogSyncState
309+ )
310+
311+ // Then
312+ #expect( result == . content)
313+ }
314+
315+ @Test func determineViewState_when_syncFailed_returns_error( ) async throws {
316+ // Given
317+ let eligibilityState : POSEligibilityState = . eligible
318+ let itemsContainerState : ItemsContainerState = . content
319+ let horizontalSizeClass : UserInterfaceSizeClass = . regular
320+ let testError = NSError ( domain: " test " , code: 1 )
321+ let catalogSyncState : POSCatalogSyncState = . syncFailed( siteID: 1 , error: testError)
322+
323+ // When
324+ let result = PointOfSaleDashboardViewHelper . determineViewState (
325+ eligibilityState: eligibilityState,
326+ itemsContainerState: itemsContainerState,
327+ horizontalSizeClass: horizontalSizeClass,
328+ catalogSyncState: catalogSyncState
329+ )
330+
331+ // Then
332+ let isError : Bool = if case . error = result { true } else { false }
333+ #expect( isError)
334+ }
335+
207336 // MARK: - Floating Control Tests
208337
209338 @Test ( arguments: [
@@ -218,9 +347,10 @@ struct PointOfSaleDashboardViewHelperTests {
218347
219348 @Test ( arguments: [
220349 ( PointOfSaleDashboardView . ViewState. loading, false ) ,
221- ( PointOfSaleDashboardView . ViewState. ineligible ( reason: . featureSwitchDisabled) , false )
350+ ( PointOfSaleDashboardView . ViewState. ineligible ( reason: . featureSwitchDisabled) , false ) ,
351+ ( PointOfSaleDashboardView . ViewState. catalogSyncing, false )
222352 ] )
223- func showsFloatingControl_when_loading_or_ineligible_returns_false ( viewState: PointOfSaleDashboardView . ViewState , expected: Bool ) async throws {
353+ func showsFloatingControl_when_loading_ineligible_or_catalogSyncing_returns_false ( viewState: PointOfSaleDashboardView . ViewState , expected: Bool ) async throws {
224354 // When & Then
225355 #expect( viewState. showsFloatingControl == expected)
226356 }
0 commit comments