@@ -220,4 +220,82 @@ final class BookingDetailsViewModelTests: XCTestCase {
220220 // Then
221221 XCTAssertTrue ( viewModel. navigationTitle. contains ( " 12345 " ) )
222222 }
223+
224+ func test_updateAttendanceStatus_whenNewStatusIsProvided_dispatchesUpdateBookingAttendanceStatusAction( ) {
225+ // Given
226+ let booking = Booking . fake ( )
227+ let viewModel = BookingDetailsViewModel ( booking: booking, stores: storesManager)
228+ let newStatus = BookingAttendanceStatus . checkedIn
229+
230+ // When
231+ viewModel. updateAttendanceStatus ( to: newStatus)
232+
233+ // Then
234+ XCTAssertEqual ( storesManager. receivedActions. count, 1 )
235+ guard let action = storesManager. receivedActions. first as? BookingAction else {
236+ XCTFail ( " Incorrect action type dispatched " )
237+ return
238+ }
239+
240+ guard case let . updateBookingAttendanceStatus( siteID, bookingID, status, _) = action else {
241+ XCTFail ( " Incorrect action case dispatched " )
242+ return
243+ }
244+
245+ XCTAssertEqual ( siteID, booking. siteID)
246+ XCTAssertEqual ( bookingID, booking. bookingID)
247+ XCTAssertEqual ( status, newStatus)
248+ }
249+
250+ func test_init_whenBookingHasStatusAndAttendanceStatus_updatesHeaderContentWithCorrectLocalizedStrings( ) {
251+ // Given
252+ let booking = Booking . fake ( ) . copy (
253+ statusKey: " paid " ,
254+ attendanceStatusKey: " checked-in "
255+ )
256+
257+ // When
258+ let viewModel = BookingDetailsViewModel ( booking: booking, stores: storesManager)
259+
260+ // Then
261+ let headerSection = viewModel. sections. first { section in
262+ if case . header = section. content {
263+ return true
264+ }
265+ return false
266+ }
267+
268+ guard let headerSection = headerSection,
269+ case let . header( headerContent) = headerSection. content else {
270+ XCTFail ( " Header section not found " )
271+ return
272+ }
273+ XCTAssertEqual ( headerContent. status, [ " Checked In " , " Paid " ] )
274+ }
275+
276+ func test_init_whenBookingHasAttendanceStatus_updatesAttendanceContentWithCorrectLocalizedString( ) {
277+ // Given
278+ let booking = Booking . fake ( ) . copy (
279+ attendanceStatusKey: " no-show "
280+ )
281+
282+ // When
283+ let viewModel = BookingDetailsViewModel ( booking: booking, stores: storesManager)
284+
285+ // Then
286+ let attendanceSection = viewModel. sections. first { section in
287+ if case . attendance = section. content {
288+ return true
289+ }
290+ return false
291+ }
292+
293+ guard let attendanceSection = attendanceSection,
294+ case let . attendance( attendanceContent) = attendanceSection. content else {
295+ XCTFail ( " Attendance section not found " )
296+ return
297+ }
298+
299+ XCTAssertEqual ( attendanceContent. value, " No Show " )
300+ }
223301}
0 commit comments