Skip to content

Commit

Permalink
* Fixes: Unit tests
Browse files Browse the repository at this point in the history
* Fixes: Unit tests in DashboardCardsViewModelSliceTest and
 DashboardItemsViewModelSliceTest.kt
  • Loading branch information
AjeshRPai committed Feb 5, 2024
1 parent 770f9f8 commit 31a3c11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package org.wordpress.android.ui.mysite
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.isActive
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.assertj.core.api.Assertions.assertThat
import org.mockito.kotlin.atMost
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.mock
Expand Down Expand Up @@ -118,10 +118,9 @@ class DashboardCardsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardCardsViewModelSlice.initialize(testScope())
dashboardCardsViewModelSlice.onResume()
dashboardCardsViewModelSlice.onResume(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(jpMigrationSuccessCardViewModelSlice, atMost(1)).buildCard()
Expand All @@ -141,10 +140,9 @@ class DashboardCardsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardCardsViewModelSlice.initialize(testScope())
dashboardCardsViewModelSlice.onResume()
dashboardCardsViewModelSlice.onResume(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(jpMigrationSuccessCardViewModelSlice, never()).buildCard()
Expand All @@ -164,10 +162,9 @@ class DashboardCardsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardCardsViewModelSlice.initialize(testScope())
dashboardCardsViewModelSlice.onRefresh()
dashboardCardsViewModelSlice.onRefresh(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(jpMigrationSuccessCardViewModelSlice, atMost(1)).buildCard()
Expand All @@ -187,10 +184,9 @@ class DashboardCardsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardCardsViewModelSlice.initialize(testScope())
dashboardCardsViewModelSlice.onRefresh()
dashboardCardsViewModelSlice.onRefresh(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(jpMigrationSuccessCardViewModelSlice, never()).buildCard()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class DashboardItemsViewModelSliceTest: BaseUnitTest() {
siteItemsViewModelSlice,
sotw2023NudgeCardViewModelSlice,
jetpackFeatureCardHelper,
selectedSiteRepository,
buildConfigWrapper
)

Expand Down Expand Up @@ -110,10 +109,9 @@ class DashboardItemsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardItemsViewModelSlice.initialize(testScope())
dashboardItemsViewModelSlice.onResume()
dashboardItemsViewModelSlice.onResume(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(siteItemsViewModelSlice, never()).buildSiteItems(any())
Expand All @@ -125,11 +123,10 @@ class DashboardItemsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(false)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardItemsViewModelSlice.initialize(testScope())

dashboardItemsViewModelSlice.onResume()
dashboardItemsViewModelSlice.onResume(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(siteItemsViewModelSlice, atLeastOnce()).buildSiteItems(any())
Expand All @@ -145,10 +142,9 @@ class DashboardItemsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(true)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardItemsViewModelSlice.initialize(testScope())
dashboardItemsViewModelSlice.onRefresh()
dashboardItemsViewModelSlice.onRefresh(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(siteItemsViewModelSlice, never()).buildSiteItems(any())
Expand All @@ -160,11 +156,10 @@ class DashboardItemsViewModelSliceTest: BaseUnitTest() {
val mockSite = mock<SiteModel>()
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
whenever(mockSite.isUsingWpComRestApi).thenReturn(false)
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mockSite)

dashboardItemsViewModelSlice.initialize(testScope())

dashboardItemsViewModelSlice.onRefresh()
dashboardItemsViewModelSlice.onRefresh(mockSite)

verify(selectedSiteRepository).getSelectedSite()
verify(siteItemsViewModelSlice, atLeastOnce()).buildSiteItems(any())
Expand Down

0 comments on commit 31a3c11

Please sign in to comment.