@@ -11,6 +11,7 @@ import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
11
11
import com.woocommerce.android.extensions.NotificationReceivedEvent
12
12
import com.woocommerce.android.extensions.takeIfNotEqualTo
13
13
import com.woocommerce.android.model.FeatureFeedbackSettings
14
+ import com.woocommerce.android.model.Order
14
15
import com.woocommerce.android.model.RequestResult
15
16
import com.woocommerce.android.notifications.NotificationChannelType
16
17
import com.woocommerce.android.notifications.NotificationChannelsHandler
@@ -997,6 +998,98 @@ class OrderListViewModelTest : BaseUnitTest() {
997
998
assertFalse(isFetchingFirstPage!! )
998
999
}
999
1000
1001
+ @Test
1002
+ fun `when selection count changes to greater than 0, then enter selection mode` () = testBlocking {
1003
+ viewModel.onSelectionChanged(2 )
1004
+
1005
+ assertThat(viewModel.isSelecting()).isTrue()
1006
+ assertThat(viewModel.viewState.selectionCount).isEqualTo(2 )
1007
+ assertThat(viewModel.viewState.isAddOrderButtonVisible).isFalse()
1008
+ assertThat(viewModel.viewState.orderListState).isEqualTo(OrderListViewModel .ViewState .OrderListState .Selecting )
1009
+ }
1010
+
1011
+ @Test
1012
+ fun `when selection count changes to 0, then exit selection mode` () = testBlocking {
1013
+ // First enter selection mode
1014
+ viewModel.onSelectionChanged(2 )
1015
+ assertThat(viewModel.isSelecting()).isTrue()
1016
+
1017
+ // Then exit
1018
+ viewModel.onSelectionChanged(0 )
1019
+
1020
+ assertThat(viewModel.isSelecting()).isFalse()
1021
+ assertThat(viewModel.viewState.selectionCount).isNull()
1022
+ assertThat(viewModel.viewState.isAddOrderButtonVisible).isTrue()
1023
+ assertThat(viewModel.viewState.orderListState).isEqualTo(OrderListViewModel .ViewState .OrderListState .Browsing )
1024
+ }
1025
+
1026
+ @Test
1027
+ fun `when in selection mode and count changes but stays above 0, then update count only` () = testBlocking {
1028
+ // Enter selection mode
1029
+ viewModel.onSelectionChanged(2 )
1030
+ val initialState = viewModel.viewState.orderListState
1031
+
1032
+ // Change count
1033
+ viewModel.onSelectionChanged(3 )
1034
+
1035
+ assertThat(viewModel.viewState.selectionCount).isEqualTo(3 )
1036
+ assertThat(viewModel.viewState.orderListState).isEqualTo(initialState)
1037
+ assertThat(viewModel.isSelecting()).isTrue()
1038
+ }
1039
+
1040
+ @Test
1041
+ fun `when bulk update clicked, then trigger dialog event with status options` () = testBlocking {
1042
+ // Given
1043
+ val statusOptions = listOf (
1044
+ Order .OrderStatus (CoreOrderStatus .COMPLETED .value, " Completed" ),
1045
+ Order .OrderStatus (CoreOrderStatus .PROCESSING .value, " Processing" )
1046
+ )
1047
+ whenever(orderDetailRepository.getOrderStatusOptions()).thenReturn(statusOptions)
1048
+
1049
+ // When
1050
+ viewModel.onBulkUpdateStatusClicked()
1051
+
1052
+ // Then
1053
+ assertThat(viewModel.event.value).isInstanceOf(OrderListEvent .ShowUpdateStatusDialog ::class .java)
1054
+ }
1055
+
1056
+ @Test
1057
+ fun `given offline, when bulk update status requested, then show offline error and exit selection mode` () = testBlocking {
1058
+ whenever(networkStatus.isConnected()).thenReturn(false )
1059
+
1060
+ viewModel.onBulkOrderStatusChanged(listOf (1L , 2L ), Order .Status .Completed )
1061
+
1062
+ assertThat(viewModel.event.value).isInstanceOf(Event .ShowSnackbar ::class .java)
1063
+ assertThat((viewModel.event.value as Event .ShowSnackbar ).message).isEqualTo(R .string.offline_error)
1064
+ assertThat(viewModel.isSelecting()).isFalse()
1065
+ }
1066
+
1067
+ @Test
1068
+ fun `when bulk update fails, then show error message and exit selection` () = testBlocking {
1069
+ whenever(networkStatus.isConnected()).thenReturn(true )
1070
+ whenever(orderListRepository.bulkUpdateOrderStatus(any(), any())).thenReturn(Result .failure(Exception ()))
1071
+
1072
+ viewModel.onBulkOrderStatusChanged(listOf (1L ), Order .Status .Completed )
1073
+
1074
+ assertThat(viewModel.event.value).isInstanceOf(Event .ShowSnackbar ::class .java)
1075
+ assertThat((viewModel.event.value as Event .ShowSnackbar ).message).isEqualTo(R .string.error_generic)
1076
+ assertThat(viewModel.isSelecting()).isFalse()
1077
+ }
1078
+
1079
+ @Test
1080
+ fun `when bulk update completes successfully, then exit selection mode` () = testBlocking {
1081
+ whenever(networkStatus.isConnected()).thenReturn(true )
1082
+ whenever(orderListRepository.bulkUpdateOrderStatus(any(), any())).thenReturn(Result .success(Unit ))
1083
+
1084
+ // First enter selection mode
1085
+ viewModel.onSelectionChanged(1 )
1086
+ assertThat(viewModel.isSelecting()).isTrue()
1087
+
1088
+ viewModel.onBulkOrderStatusChanged(listOf (1L ), Order .Status .Completed )
1089
+
1090
+ assertThat(viewModel.isSelecting()).isFalse()
1091
+ }
1092
+
1000
1093
@Test
1001
1094
fun `when selection count reaches limit, then show error message` () {
1002
1095
// when
0 commit comments