|
| 1 | +package org.havenapp.main |
| 2 | + |
| 3 | +import android.content.Intent |
| 4 | +import android.support.test.annotation.UiThreadTest |
| 5 | +import android.support.test.espresso.Espresso |
| 6 | +import android.support.test.espresso.assertion.ViewAssertions.doesNotExist |
| 7 | +import android.support.test.espresso.assertion.ViewAssertions.matches |
| 8 | +import android.support.test.espresso.matcher.ViewMatchers.isDisplayed |
| 9 | +import android.support.test.espresso.matcher.ViewMatchers.withText |
| 10 | +import android.support.v4.content.LocalBroadcastManager |
| 11 | +import android.test.ActivityInstrumentationTestCase2 |
| 12 | +import junit.framework.Assert |
| 13 | +import org.havenapp.main.database.DB_INIT_END |
| 14 | +import org.havenapp.main.database.DB_INIT_START |
| 15 | +import org.havenapp.main.database.DB_INIT_STATUS |
| 16 | + |
| 17 | +/** |
| 18 | + * Created by Arka Prava Basu <[email protected]> on 20/10/18. |
| 19 | + */ |
| 20 | +class ListActivityTest : ActivityInstrumentationTestCase2<ListActivity>(ListActivity::class.java) { |
| 21 | + private var listActivity: ListActivity? = null |
| 22 | + |
| 23 | + override fun setUp() { |
| 24 | + super.setUp() |
| 25 | + listActivity = activity |
| 26 | + } |
| 27 | + |
| 28 | + fun testCheckActivityNotNull() { |
| 29 | + Assert.assertNotNull(listActivity) |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Test that we show a progress dialog while database init/migration is in process. |
| 34 | + * Test that we remove that on db init/migration success |
| 35 | + */ |
| 36 | + @UiThreadTest |
| 37 | + fun testCheckProgressBarShownOnBroadcast() { |
| 38 | + Assert.assertNotNull(listActivity) |
| 39 | + |
| 40 | + var dbIntent = Intent() |
| 41 | + dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_START) |
| 42 | + dbIntent.action = DB_INIT_STATUS |
| 43 | + LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent) |
| 44 | + |
| 45 | + Espresso.onView(withText(R.string.please_wait)).check(matches(isDisplayed())) |
| 46 | + Espresso.onView(withText(R.string.migrating_data)).check(matches(isDisplayed())) |
| 47 | + |
| 48 | + Thread.sleep(5000) // keeping a waiting time to check the view |
| 49 | + |
| 50 | + dbIntent = Intent() |
| 51 | + dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_END) |
| 52 | + dbIntent.action = DB_INIT_STATUS |
| 53 | + LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent) |
| 54 | + |
| 55 | + Espresso.onView(withText(R.string.please_wait)).check(doesNotExist()) |
| 56 | + Espresso.onView(withText(R.string.migrating_data)).check(doesNotExist()) |
| 57 | + } |
| 58 | +} |
0 commit comments