Skip to content

Commit

Permalink
Add tests for show hide blaze overlay view
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Jul 26, 2023
1 parent b8eaa92 commit c7a6523
Showing 1 changed file with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.store.MediaStore
import org.wordpress.android.ui.blaze.BlazeFeatureUtils
import org.wordpress.android.ui.blaze.BlazeFlowSource
import org.wordpress.android.ui.blaze.BlazeUiState
import org.wordpress.android.ui.blaze.PageUIModel
import org.wordpress.android.ui.blaze.PostUIModel
import org.wordpress.android.ui.blaze.blazeoverlay.BlazeViewModel
import org.wordpress.android.ui.mysite.SelectedSiteRepository
Expand All @@ -34,6 +37,8 @@ class BlazeViewModelTest : BaseUnitTest() {

private lateinit var blazeViewModel: BlazeViewModel

private lateinit var uiStates: MutableList<BlazeUiState>
private lateinit var promoteUiState: MutableList<BlazeUiState>
@Before
fun setUp() {
blazeViewModel = BlazeViewModel(
Expand All @@ -42,6 +47,14 @@ class BlazeViewModelTest : BaseUnitTest() {
mediaStore,
selectedSiteRepository
)
uiStates = mutableListOf()
promoteUiState = mutableListOf()
blazeViewModel.promoteUiState.observeForever {
promoteUiState.add(it)
}
blazeViewModel.uiState.observeForever {
uiStates.add(it)
}
}

@Test
Expand All @@ -55,4 +68,92 @@ class BlazeViewModelTest : BaseUnitTest() {

Assertions.assertThat(result).isNotNull
}

@Test
fun `given blaze overlay shown is false, when started from post list, then uiState is set to promote post`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

val model = PostUIModel(postId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.POSTS_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.PromotePost::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from post list, then uiState is set to webview screen`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

val model = PostUIModel(postId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.POSTS_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from page list, then uiState is set to promote post`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

val model = PageUIModel(pageId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.PAGES_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.PromotePage::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from page list, then uiState is set to webview screen`() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(mock())
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

val model = PageUIModel(pageId = 1L, title = "title", featuredImageId = 1L,
url = "url", featuredImageUrl = "featuredImageUrl"
)
blazeViewModel.start(BlazeFlowSource.PAGES_LIST, model)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from dashboard card, then uiState is set to site`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

blazeViewModel.start(BlazeFlowSource.DASHBOARD_CARD, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.Site::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from dashboard card, then uiState is set to webview screen`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

blazeViewModel.start(BlazeFlowSource.DASHBOARD_CARD, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}

@Test
fun `given blaze overlay shown is false, when started from no campaigns list, then uiState is set to site`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(false)

blazeViewModel.start(BlazeFlowSource.CAMPAIGN_LISTING_PAGE, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.PromoteScreen.Site::class.java)
}

@Test
fun `given blaze overlay shown is true, when started from no campaigns list, then uiState is set to webview`() {
whenever(blazeFeatureUtils.shouldHideBlazeOverlay()).thenReturn(true)

blazeViewModel.start(BlazeFlowSource.CAMPAIGN_LISTING_PAGE, null)

Assertions.assertThat(uiStates.last()).isInstanceOf(BlazeUiState.WebViewScreen::class.java)
}
}

0 comments on commit c7a6523

Please sign in to comment.