@@ -35,6 +35,8 @@ import org.junit.Before
3535import org.junit.Test
3636import org.junit.runner.RunWith
3737import org.mockito.Mock
38+ import org.mockito.Mockito.spy
39+ import org.mockito.Mockito.verify
3840import org.powermock.api.mockito.PowerMockito
3941import org.powermock.core.classloader.annotations.PrepareForTest
4042import org.robolectric.RobolectricTestRunner
@@ -94,6 +96,7 @@ open class ItemListPresenterTest {
9496 val sortItemSelectionStub = PublishSubject .create<Setting .ItemListSort >()
9597 val disclaimerActionStub = PublishSubject .create<AlertState >()
9698 val lockNowSelectionStub = PublishSubject .create<Unit >()
99+ val refreshItemListStub = PublishSubject .create<Unit >()
97100
98101 override val itemSelection: Observable <ItemViewModel >
99102 get() = itemSelectedStub
@@ -129,6 +132,14 @@ open class ItemListPresenterTest {
129132 override fun loading (isLoading : Boolean ) {
130133 this .isLoading = isLoading
131134 }
135+
136+ override val refreshItemList: Observable <Unit >
137+ get() = refreshItemListStub
138+
139+ override val isRefreshing: Boolean = false
140+
141+ override fun stopRefreshing () {
142+ }
132143 }
133144
134145 class FakeDataStore : DataStore () {
@@ -150,7 +161,7 @@ open class ItemListPresenterTest {
150161 private val settingStore = FakeSettingStore ()
151162 private val profileStub = PublishSubject .create<Optional <Profile >>()
152163
153- val view = FakeView ()
164+ val view: FakeView = spy( FakeView () )
154165 val dispatcher = Dispatcher ()
155166 val subject = ItemListPresenter (view, dispatcher, dataStore, settingStore, fingerprintStore, accountStore)
156167
@@ -281,4 +292,17 @@ open class ItemListPresenterTest {
281292 dataStore.syncStateStub.onNext(DataStore .SyncState .NotSyncing )
282293 Assert .assertEquals(false , view.isLoading)
283294 }
295+
296+ @Test
297+ fun `stop refreshing when stop syncing after pull to refresh` () {
298+ whenCalled(view.isRefreshing).thenReturn(true )
299+ dataStore.syncStateStub.onNext(DataStore .SyncState .NotSyncing )
300+ verify(view).stopRefreshing()
301+ }
302+
303+ @Test
304+ fun `swipe down calls sync` () {
305+ view.refreshItemListStub.onNext(Unit )
306+ dispatcherObserver.assertLastValue(DataStoreAction .Sync )
307+ }
284308}
0 commit comments