Skip to content

Commit 38f975a

Browse files
committed
Add tests for the progress dialog
- set the progress dialog to non cancelable Signed-off-by: Arka Prava Basu <[email protected]>
1 parent 7f78254 commit 38f975a

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ android {
9494
ndk {
9595
abiFilters "armeabi", "armeabi-v7a", "x86"
9696
}
97+
98+
testInstrumentationRunner "android.test.InstrumentationTestRunner"
99+
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
97100
}
98101

99102

@@ -150,4 +153,8 @@ dependencies {
150153
kapt "android.arch.persistence.room:compiler:1.1.1"
151154
implementation "android.arch.lifecycle:runtime:1.1.1"
152155
implementation "android.arch.lifecycle:extensions:1.1.1"
156+
157+
testImplementation "junit:junit:4.12"
158+
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
159+
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
153160
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

src/main/java/org/havenapp/main/ListActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public void onReceive(Context context, Intent intent) {
113113
progressDialog = new ProgressDialog(ListActivity.this);
114114
progressDialog.setTitle(getString(R.string.please_wait));
115115
progressDialog.setMessage(getString(R.string.migrating_data));
116+
progressDialog.setCancelable(false);
117+
progressDialog.setCanceledOnTouchOutside(false);
116118
progressDialog.show();
117119
} else if (intent.getIntExtra(DB_INIT_STATUS, 0) == DB_INIT_END) {
118120
if (progressDialog != null)

0 commit comments

Comments
 (0)