Skip to content

Commit

Permalink
Add tests for the progress dialog
Browse files Browse the repository at this point in the history
- set the progress dialog to non cancelable

Signed-off-by: Arka Prava Basu <[email protected]>
  • Loading branch information
archie94 committed Oct 20, 2018
1 parent 7f78254 commit 38f975a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ android {
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86"
}

testInstrumentationRunner "android.test.InstrumentationTestRunner"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}


Expand Down Expand Up @@ -150,4 +153,8 @@ dependencies {
kapt "android.arch.persistence.room:compiler:1.1.1"
implementation "android.arch.lifecycle:runtime:1.1.1"
implementation "android.arch.lifecycle:extensions:1.1.1"

testImplementation "junit:junit:4.12"
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
}
58 changes: 58 additions & 0 deletions src/androidTest/java/org/havenapp/main/ListActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.havenapp.main

import android.content.Intent
import android.support.test.annotation.UiThreadTest
import android.support.test.espresso.Espresso
import android.support.test.espresso.assertion.ViewAssertions.doesNotExist
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.support.test.espresso.matcher.ViewMatchers.withText
import android.support.v4.content.LocalBroadcastManager
import android.test.ActivityInstrumentationTestCase2
import junit.framework.Assert
import org.havenapp.main.database.DB_INIT_END
import org.havenapp.main.database.DB_INIT_START
import org.havenapp.main.database.DB_INIT_STATUS

/**
* Created by Arka Prava Basu <[email protected]> on 20/10/18.
*/
class ListActivityTest : ActivityInstrumentationTestCase2<ListActivity>(ListActivity::class.java) {
private var listActivity: ListActivity? = null

override fun setUp() {
super.setUp()
listActivity = activity
}

fun testCheckActivityNotNull() {
Assert.assertNotNull(listActivity)
}

/**
* Test that we show a progress dialog while database init/migration is in process.
* Test that we remove that on db init/migration success
*/
@UiThreadTest
fun testCheckProgressBarShownOnBroadcast() {
Assert.assertNotNull(listActivity)

var dbIntent = Intent()
dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_START)
dbIntent.action = DB_INIT_STATUS
LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent)

Espresso.onView(withText(R.string.please_wait)).check(matches(isDisplayed()))
Espresso.onView(withText(R.string.migrating_data)).check(matches(isDisplayed()))

Thread.sleep(5000) // keeping a waiting time to check the view

dbIntent = Intent()
dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_END)
dbIntent.action = DB_INIT_STATUS
LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent)

Espresso.onView(withText(R.string.please_wait)).check(doesNotExist())
Espresso.onView(withText(R.string.migrating_data)).check(doesNotExist())
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/havenapp/main/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public void onReceive(Context context, Intent intent) {
progressDialog = new ProgressDialog(ListActivity.this);
progressDialog.setTitle(getString(R.string.please_wait));
progressDialog.setMessage(getString(R.string.migrating_data));
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
} else if (intent.getIntExtra(DB_INIT_STATUS, 0) == DB_INIT_END) {
if (progressDialog != null)
Expand Down

0 comments on commit 38f975a

Please sign in to comment.