Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ResearchStack 2.0.0-alpha01 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28

defaultConfig {
applicationId "org.researchstack.backboneapp"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -19,12 +19,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'org.researchstack:backbone:1.1.2'
implementation 'org.researchstack:backbone_interop:2.0.0-alpha01'

testImplementation 'junit:junit:4.12'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@ import android.view.ViewGroup
import android.widget.DatePicker
import android.widget.LinearLayout
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.action.ViewActions.swipeDown
import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.PickerActions.setDate
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withSubstring
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.hamcrest.*
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.*
import org.hamcrest.core.*
import org.junit.*
import org.hamcrest.TypeSafeMatcher
import org.hamcrest.core.IsInstanceOf
import org.junit.Rule
import org.junit.Test
import org.researchstack.backboneapp.R.id

@LargeTest
Expand All @@ -43,54 +36,38 @@ class MainActivityTest {
// Launch consent task
onView(withId(R.id.consent_button)).perform(click())

Thread.sleep(3000) // hack to wait for activity to launch
testConsentTask()

Thread.sleep(1000) // hack to wait for activity to launch
// Launch survey task
onView(withId(R.id.survey_button)).perform(click())

Thread.sleep(3000) // hack to wait for activity to launch
testSurvey()
}

private fun testSurvey() {
val appCompatTextView5 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView5.perform(click())

val appCompatEditText2 = onView(
allOf(withId(id.value),
childAtPosition(
allOf(withId(id.rsb_survey_step_body),
childAtPosition(
withId(id.rsb_survey_content_container),
2)),
1),
isDisplayed()))
appCompatEditText2.perform(replaceText("test"), closeSoftKeyboard())

val appCompatTextView6 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView6.perform(click())


onView(withId(id.value))
.perform(click())

onView(isAssignableFrom(DatePicker::class.java))
.perform(setDate(2017, 6, 30));
.perform(setDate(2017, 6, 30))

val appCompatButton4 = onView(
allOf(withId(android.R.id.button1), withText("OK"),
Expand All @@ -103,12 +80,6 @@ class MainActivityTest {

val appCompatTextView7 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView7.perform(click())

Expand All @@ -125,12 +96,6 @@ class MainActivityTest {

val appCompatTextView8 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView8.perform(click())

Expand Down Expand Up @@ -158,12 +123,6 @@ class MainActivityTest {

val appCompatTextView9 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView9.perform(click())

Expand Down Expand Up @@ -244,25 +203,14 @@ class MainActivityTest {
isDisplayed()))
appCompatEditText.perform(replaceText("test"), closeSoftKeyboard())


val appCompatTextView3 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.rsb_submit_bar),
childAtPosition(
withId(id.rsb_current_step),
1)),
2),
isDisplayed()))
appCompatTextView3.perform(click())

val appCompatTextView4 = onView(
allOf(withId(id.bar_submit_postitive), withText("next"),
childAtPosition(
allOf(withId(id.submit_bar),
childAtPosition(
withId(id.rsb_current_step),
3)),
2),
isDisplayed()))

// ConsentSignatureStep
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</activity>

<activity
android:name="org.researchstack.backbone.ui.ViewTaskActivity"
android:name="org.researchstack.backbone.interop.ViewBackboneInteropTaskActivity"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.BackboneApp.Survey"
Copy link
Contributor Author

@liujoshua liujoshua Jan 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although :backbone_interop will merge ViewBackboneInteropTaskActivity into your app's AndroidManifest.xml, you may need to update your app's AndroidManifest.xml if you specified a theme or other custom attribute.

/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.app.Application;

import com.jakewharton.threetenabp.AndroidThreeTen;

import org.researchstack.backbone.StorageAccess;
import org.researchstack.backbone.storage.database.AppDatabase;
import org.researchstack.backbone.storage.database.sqlite.DatabaseHelper;
Expand Down Expand Up @@ -34,6 +36,9 @@ public void onCreate()
null,
DatabaseHelper.DEFAULT_VERSION);

// initialize timezone database for JSR-310 library
AndroidThreeTen.init(this);

StorageAccess.getInstance().init(pinCodeConfig, encryptionProvider, fileAccess, database);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.researchstack.backbone.task.OrderedTask;
import org.researchstack.backbone.task.Task;
import org.researchstack.backbone.ui.PinCodeActivity;
import org.researchstack.backbone.interop.ViewBackboneInteropTaskActivity;
import org.researchstack.backbone.ui.ViewTaskActivity;
import org.researchstack.backbone.ui.step.layout.ConsentSignatureStepLayout;

Expand Down Expand Up @@ -275,8 +276,8 @@ private void launchConsent()
formStep,
signatureStep);

// Launch using hte ViewTaskActivity and make sure to listen for the activity result
Intent intent = ViewTaskActivity.newIntent(this, consentTask);
// Launch using hte ViewBackboneInteropTaskActivity and make sure to listen for the activity result
Intent intent = ViewBackboneInteropTaskActivity.newIntent(this, consentTask);
startActivityForResult(intent, REQUEST_CONSENT);
}

Expand Down Expand Up @@ -358,7 +359,7 @@ private void launchSurvey()
booleanStep, multiStep);

// Create an activity using the task and set a delegate.
Intent intent = ViewTaskActivity.newIntent(this, task);
Intent intent = ViewBackboneInteropTaskActivity.newIntent(this, task);
startActivityForResult(intent, REQUEST_SURVEY);
}

Expand Down Expand Up @@ -424,7 +425,10 @@ private void printSurveyInfo(TextView surveyAnswer)
for(String id : taskResult.getResults().keySet())
{
StepResult stepResult = taskResult.getStepResult(id);
results += id + ": " + stepResult.getResult().toString() + "\n";
// handle stepResults with null results
// we now add an empty stepResult to track step start/end timestamps for when a step
// does not add a result for itself
results += id + ": " + stepResult.getResult() + "\n";
}

surveyAnswer.setText(results);
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ allprojects {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" } // for MPAndroidChart dependency, not on jcenter yet
maven { url "https://dl.bintray.com/researchstack/ResearchStack/" } // 2.0.0-alpha01 is not on jcenter yet
}
}

Expand Down