Skip to content

Commit

Permalink
Update unit test with a way to check event during full success mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
hafizrahman committed Jan 21, 2025
1 parent 7ec2a8e commit 212b434
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.woocommerce.android.ui.orders

import androidx.lifecycle.MutableLiveData
import androidx.paging.PagedList
import com.google.android.material.snackbar.Snackbar
import com.woocommerce.android.AppPrefsWrapper
import com.woocommerce.android.FeedbackPrefs
Expand Down Expand Up @@ -1126,6 +1127,8 @@ class OrderListViewModelTest : BaseUnitTest() {
whenever(networkStatus.isConnected()).thenReturn(true)
whenever(orderListRepository.bulkUpdateOrderStatus(any(), any()))
.thenReturn(BulkUpdateOrderResult.AllSuccess)
val pagedListData = MutableLiveData<PagedList<OrderListItemUIType>>(mock())
whenever(pagedListWrapper.data).thenReturn(pagedListData)

// First load order to initialize orderPagedListWrapper, then enter selection mode
viewModel.loadOrders()
Expand All @@ -1134,9 +1137,15 @@ class OrderListViewModelTest : BaseUnitTest() {

// When
viewModel.onBulkOrderStatusChanged(listOf(1L, 2L), Order.Status.Completed)
// Sending a different instance of PagedList to trigger the Snackbar
pagedListData.value = mock()

// Then
assertThat(viewModel.isSelecting()).isFalse()
val expectedEvent = OrderListEvent.ShowSnackbarString(
resourceProvider.getString(R.string.orderlist_bulk_update_status_updated)
)
assertThat(viewModel.event.value).isEqualTo(expectedEvent)

// Invoked once during loadOrders() and once during onBulkOrderStatusChanged()
verify(viewModel.ordersPagedListWrapper, times(2))?.fetchFirstPage()
Expand Down

0 comments on commit 212b434

Please sign in to comment.