-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mbrc-89 #89 Add notification/message on outdated API
- Loading branch information
Showing
14 changed files
with
264 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
app/src/androidTest/kotlin/com/kelsos/mbrc/ui/navigation/main/MainActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.kelsos.mbrc.ui.navigation.main | ||
|
||
import android.app.Application | ||
import android.content.Intent | ||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.espresso.Espresso.onView | ||
import android.support.test.espresso.assertion.ViewAssertions.doesNotExist | ||
import android.support.test.espresso.assertion.ViewAssertions.matches | ||
import android.support.test.espresso.matcher.ViewMatchers.* | ||
import android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE | ||
import android.support.test.filters.LargeTest | ||
import android.support.test.rule.ActivityTestRule | ||
import android.support.test.runner.AndroidJUnit4 | ||
import com.kelsos.mbrc.R | ||
import com.kelsos.mbrc.constants.Protocol | ||
import com.kelsos.mbrc.domain.TrackInfo | ||
import com.kelsos.mbrc.events.bus.RxBus | ||
import com.kelsos.mbrc.model.MainDataModel | ||
import com.kelsos.mbrc.repository.ModelCache | ||
import com.kelsos.mbrc.utilities.SettingsManager | ||
import org.hamcrest.Matchers.allOf | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.RuleChain | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.* | ||
import rx.Completable | ||
import rx.Scheduler | ||
import rx.Single | ||
import rx.schedulers.TestScheduler | ||
import toothpick.Toothpick | ||
import toothpick.config.Module | ||
import toothpick.testing.ToothPickRule | ||
|
||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class MainActivityTest { | ||
|
||
var toothPickRule = ToothPickRule(this) | ||
val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java, true, false) | ||
|
||
@Rule fun chain(): TestRule = RuleChain.outerRule(toothPickRule).around(activityRule) | ||
|
||
|
||
private lateinit var model: MainDataModel | ||
private lateinit var mockBus: RxBus | ||
private lateinit var mockSettingsManager: SettingsManager | ||
private lateinit var mockCache: ModelCache | ||
|
||
@Before | ||
fun setUp() { | ||
mockSettingsManager = mock(SettingsManager::class.java) | ||
mockCache = mock(ModelCache::class.java) | ||
`when`(mockCache.restoreCover()).thenReturn(Single.just("")) | ||
`when`(mockCache.persistCover(anyString())).thenReturn(Completable.complete()) | ||
`when`(mockCache.restoreInfo()).thenReturn(Single.just(TrackInfo())) | ||
`when`(mockSettingsManager.shouldShowPluginUpdate()).thenReturn(Single.just(false)) | ||
mockBus = mock(RxBus::class.java) | ||
|
||
model = MainDataModel(mockBus, mockCache) | ||
|
||
val application = InstrumentationRegistry.getTargetContext().applicationContext as Application | ||
val scope = Toothpick.openScope(application) | ||
scope.installModules(TestModule()) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
Toothpick.reset() | ||
} | ||
|
||
@Test | ||
fun testShowOutdatedPluginSnackBar() { | ||
activityRule.launchActivity(Intent()) | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.plugin_protocol_out_of_date))) | ||
.check(doesNotExist()) | ||
model.pluginProtocol = 1 | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.plugin_protocol_out_of_date))) | ||
.check(matches(withEffectiveVisibility(VISIBLE))) | ||
} | ||
|
||
@Test | ||
fun testShouldNotShowOutdatedPluginSnackBar() { | ||
activityRule.launchActivity(Intent()) | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.plugin_protocol_out_of_date))) | ||
.check(doesNotExist()) | ||
model.pluginProtocol = Protocol.ProtocolVersionNumber | ||
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.plugin_protocol_out_of_date))) | ||
.check(doesNotExist()) | ||
} | ||
|
||
inner class TestModule : Module() { | ||
init { | ||
bind(MainDataModel::class.java).toProviderInstance { model }.providesSingletonInScope() | ||
bind(RxBus::class.java).toProviderInstance { mockBus }.providesSingletonInScope() | ||
bind(SettingsManager::class.java) | ||
.toProviderInstance { mockSettingsManager } | ||
.providesSingletonInScope() | ||
bind(Scheduler::class.java).withName("main").toProviderInstance { TestScheduler() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.