Skip to content

Commit

Permalink
Add unit tests for the new layout type toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
0nko committed Aug 2, 2024
1 parent 1069ee5 commit ddb4208
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.duckduckgo.app.tabs.model.TabEntity
import com.duckduckgo.app.tabs.model.TabRepository
import com.duckduckgo.app.tabs.model.TabSwitcherData
import com.duckduckgo.app.tabs.model.TabSwitcherData.LayoutType.GRID
import com.duckduckgo.app.tabs.model.TabSwitcherData.LayoutType.LIST
import com.duckduckgo.app.tabs.model.TabSwitcherData.UserState.NEW
import com.duckduckgo.app.tabs.ui.TabSwitcherViewModel.Command
import com.duckduckgo.common.test.CoroutineTestRule
Expand Down Expand Up @@ -418,4 +419,61 @@ class TabSwitcherViewModelTest {
val isVisible = testee.isFeatureAnnouncementVisible.value
assertFalse(isVisible)
}

@Test
fun whenListLayoutTypeToggledCorrectPixelsAreFired() = runTest {
coroutinesTestRule.testScope.launch {
testee.layoutType.collect()
}

testee.onLayoutTypeToggled()

verify(mockPixel).fire(AppPixelName.TAB_MANAGER_VIEW_MODE_TOGGLED_DAILY, emptyMap(), emptyMap(), Pixel.PixelType.DAILY)
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_LIST_VIEW_BUTTON_CLICKED)
}

@Test
fun whenGridLayoutTypeToggledCorrectPixelsAreFired() = runTest {
whenever(mockTabRepository.tabSwitcherData).thenReturn(flowOf(tabSwitcherData.copy(layoutType = LIST)))

// we need to use the new stubbing here
initializeViewModel()

coroutinesTestRule.testScope.launch {
testee.layoutType.collect()
}

testee.onLayoutTypeToggled()

verify(mockPixel).fire(AppPixelName.TAB_MANAGER_VIEW_MODE_TOGGLED_DAILY, emptyMap(), emptyMap(), Pixel.PixelType.DAILY)
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_GRID_VIEW_BUTTON_CLICKED)
}

@Test
fun whenListLayoutTypeToggledTheTypeIsChangedToGrid() = runTest {
coroutinesTestRule.testScope.launch {
testee.layoutType.collect()
}

// the default layout type is GRID
testee.onLayoutTypeToggled()

verify(mockTabRepository).setTabLayoutType(LIST)
}

@Test
fun whenGridLayoutTypeToggledTheTypeIsChangedToList() = runTest {
whenever(mockTabRepository.tabSwitcherData).thenReturn(flowOf(tabSwitcherData.copy(layoutType = LIST)))

// we need to use the new stubbing here
initializeViewModel()

coroutinesTestRule.testScope.launch {
testee.layoutType.collect()
}

testee.onLayoutTypeToggled()

verify(mockTabRepository).setTabLayoutType(GRID)
}
}

0 comments on commit ddb4208

Please sign in to comment.