11package com.woocommerce.android.ui.woopos.home.items.search
22
33import app.cash.turbine.test
4- import com.woocommerce.android.ui.products.ProductTestUtils
4+ import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModelVersion2
55import com.woocommerce.android.ui.woopos.home.ChildToParentEvent
66import com.woocommerce.android.ui.woopos.home.ParentToChildrenEvent
77import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender
@@ -13,6 +13,7 @@ import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule
1313import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEvent
1414import com.woocommerce.android.ui.woopos.util.analytics.WooPosAnalyticsEventConstant
1515import com.woocommerce.android.ui.woopos.util.format.WooPosFormatPrice
16+ import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
1617import kotlinx.coroutines.ExperimentalCoroutinesApi
1718import kotlinx.coroutines.delay
1819import kotlinx.coroutines.flow.emptyFlow
@@ -51,11 +52,11 @@ class WooPosItemsSearchViewModelTest {
5152 private val mockAnalyticsTracker: WooPosItemsSearchAnalyticsTracker = mock()
5253
5354 private val defaultQuery = " test query"
54- private val defaultProduct = ProductTestUtils .generateProduct (
55+ private val defaultProduct = generateWooPosProduct (
5556 productId = 1 ,
5657 productName = " Test Product" ,
5758 amount = " 10.0" ,
58- productType = " simple "
59+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
5960 )
6061
6162 @Before
@@ -280,13 +281,12 @@ class WooPosItemsSearchViewModelTest {
280281 runTest {
281282 // GIVEN
282283 val variableProduct =
283- ProductTestUtils .generateProduct (
284+ generateWooPosProduct (
284285 productId = 1 ,
285286 productName = " Variable Product" ,
286287 amount = " 10.0" ,
287- productType = " variable" ,
288- isVariable = true ,
289- variationIds = " [101,102,103]"
288+ productType = WooPosProductModelVersion2 .WooPosProductType .VARIABLE ,
289+ variationIds = listOf (101L , 102L , 103L )
290290 )
291291
292292 mockSuccessfulSearch(defaultQuery, listOf (variableProduct))
@@ -312,11 +312,11 @@ class WooPosItemsSearchViewModelTest {
312312 @Test
313313 fun `given content state and more pages available, when end of list reached, then load more data` () = runTest {
314314 // GIVEN
315- val additionalProduct = ProductTestUtils .generateProduct (
315+ val additionalProduct = generateWooPosProduct (
316316 productId = 2 ,
317317 productName = " Test Product 2" ,
318318 amount = " 20.0" ,
319- productType = " simple "
319+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
320320 )
321321
322322 mockSuccessfulSearch(defaultQuery, listOf (defaultProduct))
@@ -346,11 +346,11 @@ class WooPosItemsSearchViewModelTest {
346346 fun `given content state and more pages available, when end of list reached, then track ItemsNextPageLoaded event` () =
347347 runTest {
348348 // GIVEN
349- val additionalProduct = ProductTestUtils .generateProduct (
349+ val additionalProduct = generateWooPosProduct (
350350 productId = 2 ,
351351 productName = " Test Product 2" ,
352352 amount = " 20.0" ,
353- productType = " simple "
353+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
354354 )
355355
356356 mockSuccessfulSearch(defaultQuery, listOf (defaultProduct))
@@ -393,18 +393,18 @@ class WooPosItemsSearchViewModelTest {
393393 @Test
394394 fun `given cached products, when search performed, then cached results shown while loading` () = runTest {
395395 // GIVEN
396- val cachedProduct = ProductTestUtils .generateProduct (
396+ val cachedProduct = generateWooPosProduct (
397397 productId = 1 ,
398398 productName = " Cached Product" ,
399399 amount = " 10.0" ,
400- productType = " simple "
400+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
401401 )
402402
403- val remoteProduct = ProductTestUtils .generateProduct (
403+ val remoteProduct = generateWooPosProduct (
404404 productId = 2 ,
405405 productName = " Remote Product" ,
406406 amount = " 20.0" ,
407- productType = " simple "
407+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
408408 )
409409
410410 mockCachedThenRemoteSearch(defaultQuery, cachedProduct, remoteProduct)
@@ -437,11 +437,11 @@ class WooPosItemsSearchViewModelTest {
437437 whenever(mockEmptyStateProvider.getLastSearches()).thenReturn(emptyList())
438438
439439 val products = listOf (
440- ProductTestUtils .generateProduct (
440+ generateWooPosProduct (
441441 productId = 1 ,
442442 productName = " Test Product" ,
443443 amount = " 10.0" ,
444- productType = " simple "
444+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
445445 )
446446 )
447447
@@ -479,11 +479,11 @@ class WooPosItemsSearchViewModelTest {
479479 // GIVEN
480480 val query = " test query"
481481 val products = listOf (
482- ProductTestUtils .generateProduct (
482+ generateWooPosProduct (
483483 productId = 1 ,
484484 productName = " Test Product" ,
485485 amount = " 10.0" ,
486- productType = " simple "
486+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
487487 )
488488 )
489489
@@ -517,11 +517,11 @@ class WooPosItemsSearchViewModelTest {
517517 // GIVEN
518518 val query = " test query"
519519 val products = listOf (
520- ProductTestUtils .generateProduct (
520+ generateWooPosProduct (
521521 productId = 1 ,
522522 productName = " Test Product" ,
523523 amount = " 10.0" ,
524- productType = " simple "
524+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
525525 )
526526 )
527527
@@ -557,11 +557,11 @@ class WooPosItemsSearchViewModelTest {
557557 // GIVEN
558558 val query = " test query"
559559 val products = listOf (
560- ProductTestUtils .generateProduct (
560+ generateWooPosProduct (
561561 productId = 1 ,
562562 productName = " Test Product" ,
563563 amount = " 10.0" ,
564- productType = " simple "
564+ productType = WooPosProductModelVersion2 . WooPosProductType . SIMPLE
565565 )
566566 )
567567
@@ -784,7 +784,7 @@ class WooPosItemsSearchViewModelTest {
784784 )
785785 }
786786
787- private fun mockSuccessfulSearch (query : String , products : List <com.woocommerce.android.model. Product >) {
787+ private fun mockSuccessfulSearch (query : String , products : List <WooPosProductModelVersion2 >) {
788788 wheneverBlocking { mockDataSource.searchLocalProducts(query) }.thenReturn(emptyList())
789789 wheneverBlocking { mockDataSource.searchRemoteProducts(query) }.thenReturn(Result .success(products))
790790 whenever(mockParentToChildrenEventReceiver.events).thenReturn(
@@ -800,7 +800,7 @@ class WooPosItemsSearchViewModelTest {
800800 )
801801 }
802802
803- private suspend fun mockSuccessfulPagination (query : String , products : List <com.woocommerce.android.model. Product >) {
803+ private suspend fun mockSuccessfulPagination (query : String , products : List <WooPosProductModelVersion2 >) {
804804 whenever(mockDataSource.hasMorePages).thenReturn(true )
805805 whenever(mockDataSource.loadMore(query)).thenReturn(
806806 Result .success(products)
@@ -816,8 +816,8 @@ class WooPosItemsSearchViewModelTest {
816816
817817 private fun mockCachedThenRemoteSearch (
818818 query : String ,
819- cachedProduct : com.woocommerce.android.model. Product ,
820- remoteProduct : com.woocommerce.android.model. Product
819+ cachedProduct : WooPosProductModelVersion2 ,
820+ remoteProduct : WooPosProductModelVersion2
821821 ) {
822822 wheneverBlocking { mockDataSource.searchLocalProducts(query) }.thenReturn(listOf (cachedProduct))
823823 wheneverBlocking {
0 commit comments