From 8415d6d56e986547226c0bcd1ce3cbe464d04be3 Mon Sep 17 00:00:00 2001 From: Cathy Lu Date: Mon, 18 Dec 2023 15:38:01 -0600 Subject: [PATCH] Bug 1858948 - Update ProductNotAvailable test to use initial state --- .../store/ReviewQualityCheckStoreTest.kt | 53 ++++++------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/app/src/test/java/org/mozilla/fenix/shopping/store/ReviewQualityCheckStoreTest.kt b/app/src/test/java/org/mozilla/fenix/shopping/store/ReviewQualityCheckStoreTest.kt index 7833d84c8b..a8132ef96c 100644 --- a/app/src/test/java/org/mozilla/fenix/shopping/store/ReviewQualityCheckStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/shopping/store/ReviewQualityCheckStoreTest.kt @@ -1335,41 +1335,15 @@ class ReviewQualityCheckStoreTest { } @Test - fun `GIVEN deletedProduct is true WHEN report back in stock returns not deleted THEN state is updated to no analysis`() = + fun `GIVEN ProductNotAvailable WHEN report back in stock returns not deleted THEN state is updated to no analysis`() = runTest { val tested = ReviewQualityCheckStore( - middleware = provideReviewQualityCheckMiddleware( - reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(isEnabled = true), - reviewQualityCheckService = FakeReviewQualityCheckService( - productAnalysis = { - ProductAnalysisTestData.productAnalysis( - deletedProduct = true, - deletedProductReported = false, - ) - }, - reanalysis = AnalysisStatusDto.PENDING, - statusProgress = { null }, - report = ReportBackInStockStatusDto.NOT_DELETED, - ), - networkChecker = FakeNetworkChecker(isConnected = true), + initialState = ReviewQualityCheckState.OptedIn( + productReviewState = ReviewQualityCheckState.OptedIn.ProductReviewState.Error.ProductNotAvailable, + productRecommendationsPreference = false, + productRecommendationsExposure = true, + productVendor = ProductVendor.BEST_BUY, ), - ) - tested.waitUntilIdle() - dispatcher.scheduler.advanceUntilIdle() - tested.waitUntilIdle() - tested.dispatch(ReviewQualityCheckAction.FetchProductAnalysis).joinBlocking() - tested.waitUntilIdle() - dispatcher.scheduler.advanceUntilIdle() - - val expected = ReviewQualityCheckState.OptedIn( - productReviewState = ReviewQualityCheckState.OptedIn.ProductReviewState.Error.ProductNotAvailable, - productRecommendationsPreference = false, - productRecommendationsExposure = true, - productVendor = ProductVendor.BEST_BUY, - ) - assertEquals(expected, tested.state) - - val noAnalysisTested = ReviewQualityCheckStore( middleware = provideReviewQualityCheckMiddleware( reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(isEnabled = true), reviewQualityCheckService = FakeReviewQualityCheckService( @@ -1387,15 +1361,20 @@ class ReviewQualityCheckStoreTest { networkChecker = FakeNetworkChecker(isConnected = true), ), ) - - noAnalysisTested.dispatch(ReviewQualityCheckAction.ReportProductBackInStock).joinBlocking() - noAnalysisTested.waitUntilIdle() + tested.waitUntilIdle() + dispatcher.scheduler.advanceUntilIdle() + tested.waitUntilIdle() + tested.dispatch(ReviewQualityCheckAction.ReportProductBackInStock).joinBlocking() + tested.waitUntilIdle() dispatcher.scheduler.advanceUntilIdle() - val reportExpected = expected.copy( + val expected = ReviewQualityCheckState.OptedIn( productReviewState = ProductAnalysisTestData.noAnalysisPresent(progress = -1f), + productRecommendationsPreference = false, + productRecommendationsExposure = true, + productVendor = ProductVendor.BEST_BUY, ) - assertEquals(reportExpected, noAnalysisTested.state) + assertEquals(expected, tested.state) } @Test