Skip to content

Commit 5978603

Browse files
committed
Fix the TabSwichertViewModelTest
1 parent fd4d4c4 commit 5978603

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

app/src/test/java/com/duckduckgo/app/tabs/ui/TabSwitcherViewModelTest.kt

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2222
import androidx.lifecycle.MutableLiveData
2323
import androidx.lifecycle.Observer
2424
import androidx.lifecycle.liveData
25-
import com.duckduckgo.adclick.api.AdClickManager
2625
import com.duckduckgo.app.browser.SwipingTabsFeature
2726
import com.duckduckgo.app.browser.SwipingTabsFeatureProvider
2827
import com.duckduckgo.app.browser.favicon.FaviconManager
29-
import com.duckduckgo.app.browser.session.WebViewSessionStorage
3028
import com.duckduckgo.app.pixels.AppPixelName
3129
import com.duckduckgo.app.statistics.pixels.Pixel
3230
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.Daily
@@ -104,12 +102,6 @@ class TabSwitcherViewModelTest {
104102
@Mock
105103
private lateinit var mockTabRepository: TabRepository
106104

107-
@Mock
108-
private lateinit var mockWebViewSessionStorage: WebViewSessionStorage
109-
110-
@Mock
111-
private lateinit var mockAdClickManager: AdClickManager
112-
113105
@Mock
114106
private lateinit var mockPixel: Pixel
115107

@@ -167,8 +159,6 @@ class TabSwitcherViewModelTest {
167159
private fun initializeViewModel() {
168160
testee = TabSwitcherViewModel(
169161
mockTabRepository,
170-
mockWebViewSessionStorage,
171-
mockAdClickManager,
172162
coroutinesTestRule.testDispatcherProvider,
173163
mockPixel,
174164
swipingTabsFeatureProvider,
@@ -192,7 +182,7 @@ class TabSwitcherViewModelTest {
192182
verify(mockTabRepository).add()
193183
verify(mockCommandObserver).onChanged(commandCaptor.capture())
194184
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_MENU_NEW_TAB_PRESSED)
195-
assertEquals(Command.Close, commandCaptor.lastValue)
185+
assertEquals(Command.Close(), commandCaptor.lastValue)
196186
}
197187

198188
@Test
@@ -201,7 +191,7 @@ class TabSwitcherViewModelTest {
201191
verify(mockTabRepository).add()
202192
verify(mockCommandObserver).onChanged(commandCaptor.capture())
203193
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_NEW_TAB_CLICKED)
204-
assertEquals(Command.Close, commandCaptor.lastValue)
194+
assertEquals(Command.Close(), commandCaptor.lastValue)
205195
}
206196

207197
@Test
@@ -213,7 +203,7 @@ class TabSwitcherViewModelTest {
213203
verify(mockTabRepository).add()
214204
verify(mockCommandObserver).onChanged(commandCaptor.capture())
215205
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_NEW_TAB_CLICKED)
216-
assertEquals(Command.Close, commandCaptor.lastValue)
206+
assertEquals(Command.Close(), commandCaptor.lastValue)
217207
}
218208

219209
@Test
@@ -286,7 +276,7 @@ class TabSwitcherViewModelTest {
286276
verify(mockTabRepository).select(eq("abc"))
287277
verify(mockCommandObserver).onChanged(commandCaptor.capture())
288278
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_SWITCH_TABS)
289-
assertEquals(Command.Close, commandCaptor.lastValue)
279+
assertEquals(Command.Close(), commandCaptor.lastValue)
290280
}
291281

292282
@Test
@@ -496,10 +486,9 @@ class TabSwitcherViewModelTest {
496486

497487
testee.onTabCloseInNormalModeRequested(tab)
498488
verify(mockTabRepository).deleteTabs(listOf(tab.id))
499-
verify(mockAdClickManager).clearTabId(tab.id)
500489

501490
verify(mockCommandObserver).onChanged(commandCaptor.capture())
502-
assertEquals(Command.Close, commandCaptor.lastValue)
491+
assertEquals(Command.Close(), commandCaptor.lastValue)
503492
}
504493

505494
@Test
@@ -512,7 +501,6 @@ class TabSwitcherViewModelTest {
512501
testee.onTabCloseInNormalModeRequested(tab, swipeGestureUsed)
513502

514503
verify(mockTabRepository).markDeletable(tab.tabEntity)
515-
verify(mockAdClickManager, never()).clearTabId(tab.id)
516504
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_CLOSE_TAB_SWIPED)
517505

518506
verify(mockCommandObserver).onChanged(commandCaptor.capture())
@@ -529,38 +517,32 @@ class TabSwitcherViewModelTest {
529517
testee.onTabCloseInNormalModeRequested(tab, swipeGestureUsed)
530518

531519
verify(mockTabRepository).markDeletable(tab.tabEntity)
532-
verify(mockAdClickManager, never()).clearTabId(tab.id)
533520
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_CLOSE_TAB_CLICKED)
534521

535522
verify(mockCommandObserver).onChanged(commandCaptor.capture())
536523
assertEquals(Command.ShowUndoDeleteTabsMessage(listOf(tab.id)), commandCaptor.lastValue)
537524
}
538525

539526
@Test
540-
fun whenUndoDeletableTabThenUndoDeletable() = runTest {
527+
fun whenUndoDeletableTabThenUndoDelete() = runTest {
541528
val entity = TabEntity("abc", "", "", position = 0)
542-
testee.undoDeletableTab(entity)
529+
testee.onUndoDeleteTab(entity)
543530

544531
verify(mockTabRepository).undoDeletable(entity)
545532
}
546533

547534
@Test
548-
fun whenUndoDeletableTabsThenUndoDeletable() = runTest {
535+
fun whenUndoDeletableTabsThenOnUndoDelete() = runTest {
549536
val tabs = tabList.map { it.tabId }
550-
testee.undoDeletableTabs(tabs)
537+
testee.onUndoDeleteTabs(tabs)
551538

552539
verify(mockTabRepository).undoDeletable(tabs)
553540
}
554541

555542
@Test
556543
fun whenPurgeDeletableTabsThenCallRepositoryPurgeDeletableTabs() = runTest {
557-
whenever(mockTabRepository.getDeletableTabIds()).thenReturn(listOf("id_1", "id_2"))
558-
559544
testee.purgeDeletableTabs()
560545

561-
verify(mockTabRepository).getDeletableTabIds()
562-
verify(mockAdClickManager).clearTabId("id_1")
563-
verify(mockAdClickManager).clearTabId("id_2")
564546
verify(mockTabRepository).purgeDeletableTabs()
565547
}
566548

@@ -610,14 +592,12 @@ class TabSwitcherViewModelTest {
610592

611593
tabList.forEach {
612594
verify(mockTabRepository).deleteTabs(tabList.map { it.tabId })
613-
verify(mockAdClickManager).clearTabId(it.tabId)
614-
verify(mockWebViewSessionStorage).deleteSession(it.tabId)
615595
}
616596
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_MENU_CLOSE_ALL_TABS_CONFIRMED)
617597
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_MENU_CLOSE_ALL_TABS_CONFIRMED_DAILY, type = Daily())
618598

619599
verify(mockCommandObserver).onChanged(commandCaptor.capture())
620-
assertEquals(Command.Close, commandCaptor.lastValue)
600+
assertEquals(Command.Close(), commandCaptor.lastValue)
621601
}
622602

623603
@Test
@@ -791,6 +771,7 @@ class TabSwitcherViewModelTest {
791771
val expected = DynamicInterface(
792772
isFireButtonVisible = true,
793773
isNewTabVisible = true,
774+
isDuckChatVisible = true,
794775
isSelectAllVisible = false,
795776
isDeselectAllVisible = false,
796777
isSelectionActionsDividerVisible = false,
@@ -818,6 +799,7 @@ class TabSwitcherViewModelTest {
818799
val expected = DynamicInterface(
819800
isFireButtonVisible = true,
820801
isNewTabVisible = true,
802+
isDuckChatVisible = true,
821803
isSelectAllVisible = false,
822804
isDeselectAllVisible = false,
823805
isSelectionActionsDividerVisible = false,
@@ -845,6 +827,7 @@ class TabSwitcherViewModelTest {
845827
val expected = DynamicInterface(
846828
isFireButtonVisible = true,
847829
isNewTabVisible = true,
830+
isDuckChatVisible = true,
848831
isSelectAllVisible = false,
849832
isDeselectAllVisible = false,
850833
isSelectionActionsDividerVisible = false,
@@ -872,6 +855,7 @@ class TabSwitcherViewModelTest {
872855
val expected = DynamicInterface(
873856
isFireButtonVisible = true,
874857
isNewTabVisible = true,
858+
isDuckChatVisible = true,
875859
isSelectAllVisible = false,
876860
isDeselectAllVisible = false,
877861
isSelectionActionsDividerVisible = false,
@@ -899,6 +883,7 @@ class TabSwitcherViewModelTest {
899883
val expected = DynamicInterface(
900884
isFireButtonVisible = true,
901885
isNewTabVisible = true,
886+
isDuckChatVisible = true,
902887
isSelectAllVisible = false,
903888
isDeselectAllVisible = false,
904889
isSelectionActionsDividerVisible = false,
@@ -929,6 +914,7 @@ class TabSwitcherViewModelTest {
929914
val expected = DynamicInterface(
930915
isFireButtonVisible = false,
931916
isNewTabVisible = false,
917+
isDuckChatVisible = false,
932918
isSelectAllVisible = true,
933919
isDeselectAllVisible = false,
934920
isSelectionActionsDividerVisible = false,
@@ -959,6 +945,7 @@ class TabSwitcherViewModelTest {
959945
val expected = DynamicInterface(
960946
isFireButtonVisible = false,
961947
isNewTabVisible = false,
948+
isDuckChatVisible = false,
962949
isSelectAllVisible = true,
963950
isDeselectAllVisible = false,
964951
isSelectionActionsDividerVisible = true,
@@ -989,6 +976,7 @@ class TabSwitcherViewModelTest {
989976
val expected = DynamicInterface(
990977
isFireButtonVisible = false,
991978
isNewTabVisible = false,
979+
isDuckChatVisible = false,
992980
isSelectAllVisible = true,
993981
isDeselectAllVisible = false,
994982
isSelectionActionsDividerVisible = false,
@@ -1020,6 +1008,7 @@ class TabSwitcherViewModelTest {
10201008
val expected = DynamicInterface(
10211009
isFireButtonVisible = false,
10221010
isNewTabVisible = false,
1011+
isDuckChatVisible = false,
10231012
isSelectAllVisible = true,
10241013
isDeselectAllVisible = false,
10251014
isSelectionActionsDividerVisible = true,
@@ -1050,6 +1039,7 @@ class TabSwitcherViewModelTest {
10501039
val expected = DynamicInterface(
10511040
isFireButtonVisible = false,
10521041
isNewTabVisible = false,
1042+
isDuckChatVisible = false,
10531043
isSelectAllVisible = false,
10541044
isDeselectAllVisible = true,
10551045
isSelectionActionsDividerVisible = true,

0 commit comments

Comments
 (0)