@@ -8,10 +8,15 @@ import org.junit.Test
8
8
import org.mockito.Mock
9
9
import org.mockito.kotlin.any
10
10
import org.mockito.kotlin.anyOrNull
11
+ import org.mockito.kotlin.doAnswer
11
12
import org.mockito.kotlin.mock
13
+ import org.mockito.kotlin.times
14
+ import org.mockito.kotlin.verify
12
15
import org.mockito.kotlin.whenever
13
16
import org.wordpress.android.BaseUnitTest
14
17
import org.wordpress.android.fluxc.Dispatcher
18
+ import org.wordpress.android.fluxc.action.EditorThemeAction
19
+ import org.wordpress.android.fluxc.annotations.action.Action
15
20
import org.wordpress.android.fluxc.model.AccountModel
16
21
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
17
22
import org.wordpress.android.fluxc.model.PostModel
@@ -20,6 +25,7 @@ import org.wordpress.android.fluxc.model.page.PageModel
20
25
import org.wordpress.android.fluxc.model.page.PageStatus
21
26
import org.wordpress.android.fluxc.model.post.PostStatus
22
27
import org.wordpress.android.fluxc.store.AccountStore
28
+ import org.wordpress.android.fluxc.store.EditorThemeStore
23
29
import org.wordpress.android.fluxc.store.MediaStore
24
30
import org.wordpress.android.ui.pages.PageItem
25
31
import org.wordpress.android.ui.pages.PageItem.Divider
@@ -30,6 +36,7 @@ import org.wordpress.android.ui.posts.AuthorFilterSelection
30
36
import org.wordpress.android.ui.posts.AuthorFilterSelection.EVERYONE
31
37
import org.wordpress.android.ui.posts.AuthorFilterSelection.ME
32
38
import org.wordpress.android.util.LocaleManagerWrapper
39
+ import org.wordpress.android.util.config.GlobalStyleSupportFeatureConfig
33
40
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListState
34
41
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType.PUBLISHED
35
42
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase.PostUploadUiState
@@ -68,9 +75,16 @@ class PageListViewModelTest : BaseUnitTest() {
68
75
@Mock
69
76
lateinit var accountStore: AccountStore
70
77
78
+ @Mock
79
+ lateinit var globalStyleSupportFeatureConfig: GlobalStyleSupportFeatureConfig
80
+
81
+ @Mock
82
+ lateinit var editorThemeStore: EditorThemeStore
83
+
71
84
private lateinit var viewModel: PageListViewModel
72
85
private val site = SiteModel ()
73
86
private val pageListState = MutableLiveData <PageListState >()
87
+ private lateinit var actions: MutableList <Action <* >>
74
88
75
89
@Before
76
90
fun setUp () {
@@ -83,7 +97,9 @@ class PageListViewModelTest : BaseUnitTest() {
83
97
dispatcher,
84
98
localeManagerWrapper,
85
99
accountStore,
86
- testDispatcher()
100
+ testDispatcher(),
101
+ globalStyleSupportFeatureConfig,
102
+ editorThemeStore,
87
103
)
88
104
89
105
whenever(pageItemProgressUiStateUseCase.getProgressStateForPage(any())).thenReturn(
@@ -115,6 +131,11 @@ class PageListViewModelTest : BaseUnitTest() {
115
131
116
132
val blazeSiteEligibility = MutableLiveData <Boolean >()
117
133
whenever(pagesViewModel.blazeSiteEligibility).thenReturn(blazeSiteEligibility)
134
+
135
+ doAnswer {
136
+ actions.add(it.getArgument(0 ))
137
+ }.whenever(dispatcher).dispatch(any())
138
+ actions = mutableListOf ()
118
139
}
119
140
120
141
@Test
@@ -475,6 +496,22 @@ class PageListViewModelTest : BaseUnitTest() {
475
496
assertThat(pageItem.author).isNull()
476
497
}
477
498
499
+ @Test
500
+ fun `Should refresh EditorTheme when start is called the first time` () {
501
+ val pages = MutableLiveData <List <PageModel >>()
502
+ whenever(pagesViewModel.pages).thenReturn(pages)
503
+ viewModel.start(PUBLISHED , pagesViewModel)
504
+ assertThat(actions.last().type).isEqualTo(EditorThemeAction .FETCH_EDITOR_THEME )
505
+ }
506
+
507
+ @Test
508
+ fun `Should call EditorThemeStore getIsBlockBasedTheme when start is called the first time` () {
509
+ val pages = MutableLiveData <List <PageModel >>()
510
+ whenever(pagesViewModel.pages).thenReturn(pages)
511
+ viewModel.start(PUBLISHED , pagesViewModel)
512
+ verify(editorThemeStore).getIsBlockBasedTheme(site)
513
+ }
514
+
478
515
private fun buildPageModel (
479
516
id : Int ,
480
517
date : Date = Date (0),
0 commit comments