Skip to content

Commit ef9828f

Browse files
committed
Update unit tests for coupon list view model
1 parent 4e949ec commit ef9828f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Coupons/CouponListViewModelTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,38 @@ final class CouponListViewModelTests: XCTestCase {
111111
// Then
112112
XCTAssertEqual(sut.state, .empty)
113113
}
114+
115+
func test_refreshCoupon_updates_state_to_refreshing() {
116+
// Given
117+
setUpWithCouponFetched() // we need to have existing data to enter refreshing state
118+
119+
// When
120+
sut.refreshCoupons()
121+
122+
// Then
123+
XCTAssertEqual(sut.state, .refreshing)
124+
}
125+
126+
func test_refreshCoupons_calls_resynchronize_on_syncCoordinator() {
127+
// Given
128+
sut = CouponListViewModel(siteID: 123, syncingCoordinator: mockSyncingCoordinator)
129+
130+
// When
131+
sut.refreshCoupons()
132+
133+
// Then
134+
XCTAssert(mockSyncingCoordinator.spyDidCallResynchronize)
135+
}
136+
137+
func test_handleCouponSyncResult_removes_refreshing_when_refresh_completes() {
138+
// Given
139+
setUpWithCouponFetched()
140+
sut.refreshCoupons()
141+
142+
// When
143+
sut.handleCouponSyncResult(result: .success(false))
144+
145+
// Then
146+
XCTAssertEqual(sut.state, .coupons)
147+
}
114148
}

0 commit comments

Comments
 (0)