Skip to content

Commit 3a69851

Browse files
committed
Add attendance status update fail notice test
1 parent bb662c4 commit 3a69851

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Bookings/BookingDetailsViewModelTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,42 @@ final class BookingDetailsViewModelTests: XCTestCase {
247247
XCTAssertEqual(status, newStatus)
248248
}
249249

250+
func test_error_notice_displayed_when_attendance_staus_update_fails() {
251+
// Given
252+
let booking = Booking.fake()
253+
let viewModel = BookingDetailsViewModel(booking: booking, stores: storesManager)
254+
let newStatus = BookingAttendanceStatus.checkedIn
255+
enum TestError: Error { case generic }
256+
257+
// When
258+
viewModel.updateAttendanceStatus(to: newStatus)
259+
260+
// Then
261+
XCTAssertEqual(storesManager.receivedActions.count, 1)
262+
guard let action = storesManager.receivedActions.first as? BookingAction else {
263+
XCTFail("Incorrect action type dispatched")
264+
return
265+
}
266+
267+
guard case let .updateBookingAttendanceStatus(_, _, _, onCompletion) = action else {
268+
XCTFail("Incorrect action case dispatched")
269+
return
270+
}
271+
272+
onCompletion(TestError.generic)
273+
274+
XCTAssertNotNil(viewModel.notice)
275+
XCTAssertEqual(viewModel.notice?.feedbackType, .error)
276+
277+
let messageFormat = NSLocalizedString(
278+
"BookingDetailsView.attendanceStatus.updateFailed.message",
279+
value: "Unable to change attendance status of Booking #%1$d",
280+
comment: ""
281+
)
282+
let expectedMessage = String(format: messageFormat, booking.bookingID)
283+
XCTAssertEqual(viewModel.notice?.message, expectedMessage)
284+
}
285+
250286
func test_init_whenBookingHasStatusAndAttendanceStatus_updatesHeaderContentWithCorrectLocalizedStrings() {
251287
// Given
252288
let booking = Booking.fake().copy(

0 commit comments

Comments
 (0)