@@ -2,7 +2,6 @@ package com.woocommerce.android.ui.bookings.note
22
33import androidx.lifecycle.SavedStateHandle
44import com.woocommerce.android.R
5- import com.woocommerce.android.ui.bookings.Booking
65import com.woocommerce.android.ui.bookings.BookingsRepository
76import com.woocommerce.android.util.getOrAwaitValue
87import com.woocommerce.android.viewmodel.BaseUnitTest
@@ -30,9 +29,31 @@ import java.time.Instant
3029class BookingNoteViewModelTest : BaseUnitTest () {
3130
3231 private val bookingId = 42L
33- private val initialNote = " Initial note"
3432
35- private val booking = sampleBooking(bookingId, note = initialNote)
33+ private val booking = BookingEntity (
34+ id = LocalOrRemoteId .RemoteId (bookingId),
35+ localSiteId = LocalOrRemoteId .LocalId (1 ),
36+ start = Instant .now(),
37+ end = Instant .now() + Duration .ofDays(1 ),
38+ allDay = false ,
39+ status = BookingEntity .Status .Confirmed ,
40+ cost = " 100.00" ,
41+ currency = " USD" ,
42+ customerId = 1L ,
43+ productId = 1L ,
44+ resourceId = 1L ,
45+ dateCreated = Instant .now(),
46+ dateModified = Instant .now(),
47+ googleCalendarEventId = " " ,
48+ orderId = bookingId,
49+ orderItemId = 1L ,
50+ parentId = 0L ,
51+ personCounts = listOf (1L ),
52+ localTimezone = " " ,
53+ attendanceStatus = BookingEntity .AttendanceStatus .Booked ,
54+ note = " Initial note" ,
55+ order = BookingOrderInfo ()
56+ )
3657
3758 private val savedStateHandle: SavedStateHandle = BookingNoteFragmentArgs (bookingId).toSavedStateHandle()
3859
@@ -48,8 +69,8 @@ class BookingNoteViewModelTest : BaseUnitTest() {
4869
4970 // Then
5071 val state = viewModel.state.getOrAwaitValue()
51- assertThat(state.initialNote).isEqualTo(initialNote )
52- assertThat(state.editedNote).isEqualTo(initialNote )
72+ assertThat(state.initialNote).isEqualTo(booking.note )
73+ assertThat(state.editedNote).isEqualTo(booking.note )
5374 // save not visible when same (after trim)
5475 assertThat(state.isSaveVisible).isFalse()
5576 assertThat(state.isSaveEnabled).isTrue()
@@ -76,11 +97,11 @@ class BookingNoteViewModelTest : BaseUnitTest() {
7697 val state = viewModel.state.getOrAwaitValue()
7798
7899 // When: whitespace-only change should not make save visible
79- state.onNoteChange(" $initialNote " )
100+ state.onNoteChange(" ${booking.note} " )
80101 val updated1 = viewModel.state.getOrAwaitValue()
81102
82103 // Then
83- assertThat(updated1.editedNote).isEqualTo(" $initialNote " )
104+ assertThat(updated1.editedNote).isEqualTo(" ${booking.note} " )
84105 assertThat(updated1.isSaveVisible).isFalse()
85106
86107 // When: real change
@@ -169,31 +190,4 @@ class BookingNoteViewModelTest : BaseUnitTest() {
169190 state.observeForever { }
170191 }
171192 }
172-
173- private fun sampleBooking (id : Long , note : String ): Booking {
174- return BookingEntity (
175- id = LocalOrRemoteId .RemoteId (id),
176- localSiteId = LocalOrRemoteId .LocalId (1 ),
177- start = Instant .now(),
178- end = Instant .now() + Duration .ofDays(1 ),
179- allDay = false ,
180- status = BookingEntity .Status .Confirmed ,
181- cost = " 100.00" ,
182- currency = " USD" ,
183- customerId = 1L ,
184- productId = 1L ,
185- resourceId = 1L ,
186- dateCreated = Instant .now(),
187- dateModified = Instant .now(),
188- googleCalendarEventId = " " ,
189- orderId = id,
190- orderItemId = 1L ,
191- parentId = 0L ,
192- personCounts = listOf (1L ),
193- localTimezone = " " ,
194- attendanceStatus = BookingEntity .AttendanceStatus .Booked ,
195- note = note,
196- order = BookingOrderInfo ()
197- )
198- }
199193}
0 commit comments