-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBottomTabsControllerTest.kt
More file actions
603 lines (534 loc) · 23.8 KB
/
BottomTabsControllerTest.kt
File metadata and controls
603 lines (534 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
package com.reactnativenavigation.viewcontrollers.bottomtabs
import android.app.Activity
import android.graphics.Color
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.FrameLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation
import com.reactnativenavigation.BaseTest
import com.reactnativenavigation.TestUtils
import com.reactnativenavigation.mocks.ImageLoaderMock.mock
import com.reactnativenavigation.mocks.Mocks
import com.reactnativenavigation.mocks.SimpleViewController
import com.reactnativenavigation.mocks.TypefaceLoaderMock
import com.reactnativenavigation.options.BottomTabsOptions
import com.reactnativenavigation.options.HwBackBottomTabsBehaviour
import com.reactnativenavigation.options.Options
import com.reactnativenavigation.options.params.*
import com.reactnativenavigation.react.CommandListenerAdapter
import com.reactnativenavigation.react.events.EventEmitter
import com.reactnativenavigation.utils.OptionHelper
import com.reactnativenavigation.utils.SystemUiUtils.getStatusBarHeight
import com.reactnativenavigation.utils.SystemUiUtils.saveStatusBarHeight
import com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry
import com.reactnativenavigation.viewcontrollers.fakes.FakeParentController
import com.reactnativenavigation.viewcontrollers.stack.StackController
import com.reactnativenavigation.viewcontrollers.statusbar.StatusBarPresenter
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController
import com.reactnativenavigation.views.bottomtabs.BottomTabs
import com.reactnativenavigation.views.bottomtabs.BottomTabsContainer
import com.reactnativenavigation.views.bottomtabs.BottomTabsLayout
import org.assertj.core.api.Java6Assertions
import org.junit.Ignore
import org.junit.Test
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.times
import java.util.*
class BottomTabsControllerTest : BaseTest() {
private lateinit var activity: Activity
private lateinit var bottomTabs: BottomTabs
private lateinit var bottomTabsContainer: BottomTabsContainer
private lateinit var uut: BottomTabsController
private val initialOptions = Options()
private lateinit var child1: ViewController<*>
private lateinit var child2: ViewController<*>
private lateinit var child3: ViewController<*>
private lateinit var stackChild: ViewController<*>
private lateinit var child4: StackController
private lateinit var child5: ViewController<*>
private val tabOptions = OptionHelper.createBottomTabOptions()
private val imageLoaderMock = mock()
private lateinit var eventEmitter: EventEmitter
private lateinit var childRegistry: ChildControllersRegistry
private lateinit var tabs: MutableList<ViewController<*>>
private lateinit var presenter: BottomTabsPresenter
private lateinit var bottomTabPresenter: BottomTabPresenter
private lateinit var tabsAttacher: BottomTabsAttacher
override fun beforeEach() {
super.beforeEach()
activity = newActivity()
childRegistry = ChildControllersRegistry()
eventEmitter = Mockito.mock(EventEmitter::class.java)
StatusBarPresenter.init(activity)
prepareViewsForTests()
saveStatusBarHeight(63)
}
@Test
fun createView_checkProperStructure() {
idleMainLooper()
Java6Assertions.assertThat(uut.view).isInstanceOf(CoordinatorLayout::class.java)
val tabContainerWrapper = uut.view.getChildAt(uut.view.childCount - 1)
Java6Assertions.assertThat(tabContainerWrapper).isInstanceOf(ViewGroup::class.java)
val tabContainer = (tabContainerWrapper as ViewGroup).getChildAt(0)
Java6Assertions.assertThat(tabContainer).isInstanceOf(BottomTabsContainer::class.java)
Java6Assertions.assertThat((tabContainerWrapper.layoutParams as CoordinatorLayout.LayoutParams).gravity)
.isEqualTo(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
}
@Test
fun createView_tabsWithoutIconsAreAccepted() {
tabOptions.bottomTabOptions.icon = NullText()
prepareViewsForTests()
Java6Assertions.assertThat(uut.bottomTabs.itemsCount).isEqualTo(tabs.size)
}
@Test
fun createView_showTitlesWhenAllTabsDontHaveIcons() {
tabOptions.bottomTabOptions.icon = NullText()
Java6Assertions.assertThat(tabOptions.bottomTabsOptions.titleDisplayMode.hasValue()).isFalse
prepareViewsForTests()
presenter.applyOptions(Options.EMPTY)
Java6Assertions.assertThat(bottomTabsContainer.bottomTabs.titleState).isEqualTo(
AHBottomNavigation.TitleState.ALWAYS_SHOW)
}
@Test(expected = RuntimeException::class)
fun setTabs_ThrowWhenMoreThan5() {
tabs.add(SimpleViewController(activity, childRegistry, "6", tabOptions))
createBottomTabs()
idleMainLooper()
}
@Test
fun parentControllerIsSet() {
uut = createBottomTabs()
for (tab in tabs) {
Java6Assertions.assertThat(tab.parentController).isEqualTo(uut)
}
}
@Test
fun setTabs_allChildViewsAreAttachedToHierarchy() {
uut.onViewWillAppear()
Java6Assertions.assertThat(uut.view.childCount).isEqualTo(6)
for (child in uut.childControllers) {
Java6Assertions.assertThat(child.view.parent).isNotNull
}
}
@Test
fun setTabs_firstChildIsVisibleOtherAreGone() {
uut.onViewWillAppear()
for (i in uut.childControllers.indices) {
Java6Assertions.assertThat(uut.view.getChildAt(i)).isEqualTo(tabs[i].view)
Java6Assertions.assertThat(uut.view.getChildAt(i).visibility)
.isEqualTo(if (i == 0) View.VISIBLE else View.INVISIBLE)
}
}
@Test
fun onTabSelected() {
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.selectedIndex).isZero
Java6Assertions.assertThat(((uut.childControllers as List<*>)[0] as ViewController<*>).view.visibility)
.isEqualTo(
View.VISIBLE
)
uut.onTabSelected(3, false)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
Java6Assertions.assertThat(((uut.childControllers as List<*>)[0] as ViewController<*>).view.visibility)
.isEqualTo(
View.INVISIBLE
)
Java6Assertions.assertThat(((uut.childControllers as List<*>)[3] as ViewController<*>).view.visibility)
.isEqualTo(
View.VISIBLE
)
Mockito.verify(eventEmitter).emitBottomTabSelected(0, 3)
}
@Test
fun onTabReSelected() {
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.selectedIndex).isZero
uut.onTabSelected(0, true)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
Java6Assertions.assertThat(((uut.childControllers as List<*>)[0] as ViewController<*>).view.parent).isNotNull
Mockito.verify(eventEmitter).emitBottomTabSelected(0, 0)
}
@Test
fun handleBack_DelegatesToSelectedChild() {
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isFalse
uut.selectTab(4)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isTrue
Mockito.verify(child5).handleBack(ArgumentMatchers.any())
}
@Test
fun `handleBack - PrevSelection - reselect tab selection history of navigation when root has bottom tabs`() {
val options = Options().apply {
hardwareBack.bottomTabOnPress = HwBackBottomTabsBehaviour.PrevSelection
}
prepareViewsForTests(options = options)
idleMainLooper()
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
uut.selectTab(1)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(1)
uut.selectTab(3)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
uut.selectTab(2)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(2)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isTrue
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isTrue
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(1)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isTrue
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isFalse
}
@Test
fun `handleBack - JumpToFirst - reselect first tab`() {
val options = Options().apply {
hardwareBack.bottomTabOnPress = HwBackBottomTabsBehaviour.JumpToFirst
}
prepareViewsForTests(options = options)
idleMainLooper()
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
uut.selectTab(1)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(1)
uut.selectTab(3)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
uut.selectTab(2)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(2)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isTrue
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isFalse
}
@Test
fun `handleBack - Default - should exit app with no reselection`() {
prepareViewsForTests()
idleMainLooper()
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
uut.selectTab(1)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(1)
uut.selectTab(3)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
uut.selectTab(2)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(2)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isFalse
}
@Test
fun `handleBack - Exit - reselect first tab`() {
val options = Options().apply {
hardwareBack.bottomTabOnPress = HwBackBottomTabsBehaviour.Exit
}
prepareViewsForTests(options = options)
idleMainLooper()
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(0)
uut.selectTab(1)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(1)
uut.selectTab(3)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(3)
uut.selectTab(2)
Java6Assertions.assertThat(uut.selectedIndex).isEqualTo(2)
Java6Assertions.assertThat(uut.handleBack(CommandListenerAdapter())).isFalse
}
@Test
fun applyChildOptions_bottomTabsOptionsAreClearedAfterApply() {
val parent = Mocks.parentController()
uut.parentController = parent
child1.options.bottomTabsOptions.backgroundColor = ThemeColour(Colour(Color.RED))
child1.onViewWillAppear()
val optionsCaptor = ArgumentCaptor.forClass(
Options::class.java
)
Mockito.verify(parent).applyChildOptions(optionsCaptor.capture(), ArgumentMatchers.any())
Java6Assertions.assertThat(optionsCaptor.value.bottomTabsOptions.backgroundColor.hasValue()).isFalse
}
@Test
fun applyOptions_bottomTabsCreateViewOnlyOnce() {
idleMainLooper()
Mockito.verify(presenter).applyOptions(any())
Mockito.verify(bottomTabsContainer.bottomTabs, times(2))
.superCreateItems() // first time when view is created, second time when options are applied
}
@Test
fun onSizeChanged_recreateItemsIfSizeHasChanged() {
val numberOfPreviousInvocations = 1
bottomTabs.onSizeChanged(0, 0, 0, 0)
Mockito.verify(bottomTabs, Mockito.times(numberOfPreviousInvocations)).superCreateItems()
bottomTabs.onSizeChanged(100, 0, 0, 0)
Mockito.verify(bottomTabs, Mockito.times(numberOfPreviousInvocations)).superCreateItems()
bottomTabs.onSizeChanged(1080, 147, 0, 0)
Mockito.verify(bottomTabs, Mockito.times(numberOfPreviousInvocations + 1)).superCreateItems()
bottomTabs.onSizeChanged(1920, 147, 0, 0)
Mockito.verify(bottomTabs, Mockito.times(numberOfPreviousInvocations + 2)).superCreateItems()
Mockito.`when`(bottomTabs.itemsCount).thenReturn(0)
bottomTabs.onSizeChanged(1080, 147, 0, 0)
Mockito.verify(bottomTabs, Mockito.times(numberOfPreviousInvocations + 2)).superCreateItems()
}
@Test
fun mergeOptions_currentTabIndex() {
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.selectedIndex).isZero
val options = Options()
options.bottomTabsOptions.currentTabIndex = Number(1)
uut.mergeOptions(options)
Java6Assertions.assertThat(uut.selectedIndex).isOne
Mockito.verify(eventEmitter, Mockito.times(0)).emitBottomTabSelected(
ArgumentMatchers.any(
Int::class.java
), ArgumentMatchers.any(Int::class.java)
)
}
@Test
fun `mergeOptions - select tab calls onViewWillAppear to apply options on the selected child`(){
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.selectedIndex).isZero
val options = Options()
options.bottomTabsOptions.currentTabIndex = Number(1)
uut.mergeOptions(options)
Java6Assertions.assertThat(uut.selectedIndex).isOne
Mockito.verify(child2).onViewWillAppear()
Mockito.verify(child2).onViewDidAppear()
options.bottomTabsOptions.currentTabIndex = Number(0)
uut.mergeOptions(options)
Java6Assertions.assertThat(uut.selectedIndex).isZero
Mockito.verify(child1).onViewWillAppear()
Mockito.verify(child1).onViewDidAppear()
}
@Test
fun mergeOptions_drawBehind() {
Java6Assertions.assertThat(uut.getBottomInset(child1)).isEqualTo(uut.bottomTabs.height)
val o1 = Options()
o1.bottomTabsOptions.drawBehind = Bool(true)
child1.mergeOptions(o1)
Java6Assertions.assertThat(uut.getBottomInset(child1)).isEqualTo(0)
val o2 = Options()
o2.topBar.title.text = Text("Some text")
child1.mergeOptions(o1)
Java6Assertions.assertThat(uut.getBottomInset(child1)).isEqualTo(0)
}
@Test
fun mergeOptions_drawBehind_stack() {
uut.ensureViewIsCreated()
uut.selectTab(3)
Java6Assertions.assertThat((stackChild.view.layoutParams as MarginLayoutParams).bottomMargin).isEqualTo(
bottomTabs.height
)
val o1 = Options()
o1.bottomTabsOptions.drawBehind = Bool(true)
stackChild.mergeOptions(o1)
Java6Assertions.assertThat((stackChild.view.layoutParams as MarginLayoutParams).bottomMargin).isEqualTo(0)
}
@Test
fun mergeOptions_mergesBottomTabOptions() {
val options = Options()
uut.mergeOptions(options)
Mockito.verify(bottomTabPresenter).mergeOptions(options)
}
@Test
fun applyChildOptions_resolvedOptionsAreUsed() {
val childOptions = Options()
val pushedScreen = SimpleViewController(activity, childRegistry, "child4.1", childOptions)
disablePushAnimation(pushedScreen)
child4 = spyOnStack(pushedScreen)
tabs = ArrayList(listOf(child4))
tabsAttacher = BottomTabsAttacher(tabs, presenter, Options.EMPTY)
initialOptions.bottomTabsOptions.currentTabIndex = Number(0)
val resolvedOptions = Options()
uut = object : BottomTabsController(
activity,
tabs,
childRegistry,
eventEmitter,
imageLoaderMock,
"uut",
initialOptions,
Presenter(activity, Options()),
tabsAttacher,
presenter,
BottomTabPresenter(activity, tabs, mock(), TypefaceLoaderMock(), Options())
) {
override fun resolveCurrentOptions(): Options {
return resolvedOptions
}
override fun createBottomTabs(): BottomTabs {
return object : BottomTabs(activity) {
override fun createItems() {}
}
}
}
activity.setContentView(uut.view)
idleMainLooper()
Mockito.verify(presenter, Mockito.times(2))
.applyChildOptions(eq(resolvedOptions), any())
}
@Test
fun child_mergeOptions_currentTabIndex() {
uut.ensureViewIsCreated()
Java6Assertions.assertThat(uut.selectedIndex).isZero
val options = Options()
options.bottomTabsOptions.currentTabIndex = Number(1)
child1.mergeOptions(options)
Java6Assertions.assertThat(uut.selectedIndex).isOne
}
@Test
fun resolveCurrentOptions_returnsFirstTabIfInvokedBeforeViewIsCreated() {
uut = createBottomTabs()
Java6Assertions.assertThat(uut.currentChild).isEqualTo(tabs[0])
}
@Test
fun buttonPressInvokedOnCurrentTab() {
uut.ensureViewIsCreated()
uut.selectTab(4)
uut.sendOnNavigationButtonPressed("btn1")
Mockito.verify(child5, Mockito.times(1)).sendOnNavigationButtonPressed("btn1")
}
@Test
fun push() {
uut.selectTab(3)
val stackChild2 = SimpleViewController(activity, childRegistry, "stackChild2", Options())
disablePushAnimation(stackChild2)
TestUtils.hideBackButton(stackChild2)
Java6Assertions.assertThat(child4.size()).isEqualTo(1)
child4.push(stackChild2, CommandListenerAdapter())
Java6Assertions.assertThat(child4.size()).isEqualTo(2)
}
@Test
fun oneTimeOptionsAreAppliedOnce() {
val options = Options()
options.bottomTabsOptions.currentTabIndex = Number(1)
Java6Assertions.assertThat(uut.selectedIndex).isZero
uut.mergeOptions(options)
Java6Assertions.assertThat(uut.selectedIndex).isOne
Java6Assertions.assertThat(uut.options.bottomTabsOptions.currentTabIndex.hasValue()).isFalse
Java6Assertions.assertThat(uut.initialOptions.bottomTabsOptions.currentTabIndex.hasValue()).isFalse
}
@Test
fun selectTab() {
uut.selectTab(1)
Mockito.verify(tabsAttacher).onTabSelected(tabs[1])
}
@Test
fun selectTab_onViewDidAppearIsInvokedAfterSelection() {
uut.selectTab(1)
Mockito.verify(child2).onViewDidAppear()
}
@Test
fun creatingTabs_onViewDidAppearInvokedAfterInitialTabIndexSet() {
val options = Options.EMPTY.copy()
options.bottomTabsOptions.currentTabIndex = Number(1)
prepareViewsForTests(options.bottomTabsOptions)
idleMainLooper()
Mockito.verify(tabs[0], Mockito.times(0)).onViewDidAppear()
Mockito.verify(tabs[1], Mockito.times(1)).onViewDidAppear()
Mockito.verify(tabs[2], Mockito.times(0)).onViewDidAppear()
Mockito.verify(tabs[3], Mockito.times(0)).onViewDidAppear()
Mockito.verify(tabs[4], Mockito.times(0)).onViewDidAppear()
}
@Test
fun topInset() {
Java6Assertions.assertThat(child1.topInset).isEqualTo(statusBarHeight)
Java6Assertions.assertThat(child2.topInset).isEqualTo(statusBarHeight)
child1.options.statusBar.drawBehind = Bool(true)
Java6Assertions.assertThat(child1.topInset).isEqualTo(0)
Java6Assertions.assertThat(child2.topInset).isEqualTo(statusBarHeight)
Java6Assertions.assertThat(stackChild.topInset).isEqualTo(statusBarHeight + child4.topBar.height)
}
@Test
fun bottomInset_defaultOptionsAreTakenIntoAccount() {
val defaultOptions = Options()
defaultOptions.bottomTabsOptions.visible = Bool(false)
Java6Assertions.assertThat(uut.getBottomInset(child1)).isEqualTo(bottomTabs.height)
uut.setDefaultOptions(defaultOptions)
Java6Assertions.assertThat(uut.getBottomInset(child1)).isZero
}
@Test
fun destroy() {
uut.destroy()
Mockito.verify(tabsAttacher).destroy()
}
private fun prepareViewsForTests(
bottomTabsOptions: BottomTabsOptions = initialOptions.bottomTabsOptions,
options: Options = initialOptions, defaultOptions: Options = initialOptions
) {
if(::uut.isInitialized){
uut.destroy()
}
// ObjectUtils.perform(uut, { obj: BottomTabsController -> obj.destroy() })
bottomTabs = Mockito.spy(object : BottomTabs(activity) {
override fun superCreateItems() {}
})
bottomTabsContainer = Mockito.spy(BottomTabsContainer(activity, bottomTabs))
createChildren()
tabs = mutableListOf(child1, child2, child3, child4, child5)
defaultOptions.bottomTabsOptions = bottomTabsOptions
presenter = Mockito.spy(BottomTabsPresenter(tabs, defaultOptions, BottomTabsAnimator()))
bottomTabPresenter =
Mockito.spy(BottomTabPresenter(activity, tabs, mock(), TypefaceLoaderMock(), defaultOptions))
tabsAttacher = Mockito.spy(BottomTabsAttacher(tabs, presenter, defaultOptions))
uut = createBottomTabs(options = options, defaultOptions = defaultOptions)
activity.setContentView(FakeParentController(activity, childRegistry, uut).view)
}
private fun createChildren() {
child1 = Mockito.spy(SimpleViewController(activity, childRegistry, "child1", tabOptions))
child2 = Mockito.spy(SimpleViewController(activity, childRegistry, "child2", tabOptions))
child3 = Mockito.spy(SimpleViewController(activity, childRegistry, "child3", tabOptions))
stackChild = Mockito.spy(SimpleViewController(activity, childRegistry, "stackChild", tabOptions))
child4 = spyOnStack(stackChild)
child5 = Mockito.spy(SimpleViewController(activity, childRegistry, "child5", tabOptions))
Mockito.`when`(child5.handleBack(any())).thenReturn(true)
}
private fun spyOnStack(initialChild: ViewController<*>): StackController {
val build = TestUtils.newStackController(activity)
.setInitialOptions(tabOptions)
.build()
val stack = Mockito.spy(build)
disablePushAnimation(initialChild)
stack.ensureViewIsCreated()
stack.push(initialChild, CommandListenerAdapter())
return stack
}
private fun createBottomTabs(
options: Options = initialOptions,
defaultOptions: Options = initialOptions
): BottomTabsController {
val presenter1 = Presenter(activity, defaultOptions)
return object : BottomTabsController(
activity,
tabs,
childRegistry,
eventEmitter,
imageLoaderMock,
"uut",
options,
presenter1,
tabsAttacher,
presenter,
bottomTabPresenter
) {
override fun getTopMostParent(): ViewController<*> {
return Mocks.parentController(null, FrameLayout(activity))
}
override fun ensureViewIsCreated() {
super.ensureViewIsCreated()
uut.view.layout(0, 0, 1000, 1000)
}
override fun createView(): BottomTabsLayout {
val view = super.createView()
this@BottomTabsControllerTest.bottomTabs.layoutParams.height = 100
return view
}
override fun createBottomTabsContainer(): BottomTabsContainer {
return this@BottomTabsControllerTest.bottomTabsContainer
}
override fun createBottomTabs(): BottomTabs {
return this@BottomTabsControllerTest.bottomTabs
}
}
}
private val statusBarHeight: Int
get() = getStatusBarHeight(activity)
}