-
Notifications
You must be signed in to change notification settings - Fork 60
feat: Adds tasks notification #394
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
Changes from all commits
8347a64
cabedcc
3178ecf
bf3c426
214aa96
304a479
ef318ff
0012b37
4a3be48
76ef981
fb794f0
685822c
eb1a5b6
07c5ffc
ee55f39
6876138
04e1d7c
8222482
a184ed7
23cbf22
d4c42d8
32a6782
eda830d
6af9ce2
33f1bee
4ab9ccb
87a932d
8550452
f9961cd
5d6b8c8
cc5f3f0
d9a9317
3fab995
e541868
13889d8
971111b
3090c25
1f45c73
f2d592d
d5f7478
596ee5c
21eb4e1
b45c52a
0b5373a
c5096cc
121f5cb
be2bbd8
fde7541
171b2ee
ca218f8
124da15
386d28c
95bf2ba
6584fb8
b8717a7
8fc8286
db98fda
0c63562
089a1b1
9140d6c
7eac60b
8b752b3
cd73a00
6ccf399
6b9f6d3
a442e79
686ad7c
3c5d9f2
f45d9f4
5f7e21f
a4d54e6
9aad6b9
853f674
c0770f1
e1dd734
46fe25d
23ddaba
0424cc8
9d3bef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package org.medicmobile.webapp.mobile; | ||
|
|
||
| import static androidx.test.espresso.Espresso.onView; | ||
| import static androidx.test.espresso.action.ViewActions.click; | ||
| import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
| import static androidx.test.espresso.action.ViewActions.replaceText; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
| import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
| import static androidx.test.espresso.web.sugar.Web.onWebView; | ||
| import static androidx.test.espresso.web.webdriver.DriverAtoms.clearElement; | ||
| import static androidx.test.espresso.web.webdriver.DriverAtoms.findElement; | ||
| import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick; | ||
| import static junit.framework.TestCase.assertEquals; | ||
|
|
||
| import android.Manifest; | ||
| import android.annotation.SuppressLint; | ||
| import android.content.Context; | ||
|
|
||
| import androidx.test.core.app.ActivityScenario; | ||
| import androidx.test.core.app.ApplicationProvider; | ||
| import androidx.test.espresso.ViewInteraction; | ||
| import androidx.test.espresso.web.webdriver.DriverAtoms; | ||
| import androidx.test.espresso.web.webdriver.Locator; | ||
| import androidx.test.ext.junit.rules.ActivityScenarioRule; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import androidx.test.rule.GrantPermissionRule; | ||
| import androidx.work.WorkInfo; | ||
| import androidx.work.WorkManager; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Ignore; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| @RunWith(AndroidJUnit4.class) | ||
| public class NotificationTest { | ||
| private Context context; | ||
| private static final String TEST_SERVER = ""; | ||
| private static final String TEST_USERNAME = ""; | ||
| private static final String TEST_PASSWORD = ""; | ||
|
|
||
| @Rule | ||
| public ActivityScenarioRule<SettingsDialogActivity> mActivityTestRule = | ||
| new ActivityScenarioRule<>(SettingsDialogActivity.class); | ||
| @Rule | ||
| public GrantPermissionRule permissionRule = | ||
| GrantPermissionRule.grant( | ||
| Manifest.permission.POST_NOTIFICATIONS | ||
| ); | ||
|
|
||
| @After | ||
| public void cleanServerRepo() { | ||
| context.getSharedPreferences("ServerRepo", Context.MODE_PRIVATE) | ||
| .edit().clear().apply(); | ||
| } | ||
|
|
||
| @Ignore("TODO: add TEST_SERVER") | ||
| @SuppressLint("CheckResult") | ||
| @Test | ||
| public void startsNotificationWorkers() throws InterruptedException, ExecutionException { | ||
| context = ApplicationProvider.getApplicationContext(); | ||
| onView(withText("Custom")).perform(click()); | ||
| ViewInteraction textAppUrl = onView(withId(R.id.txtAppUrl)); | ||
| textAppUrl.perform(replaceText(TEST_SERVER), closeSoftKeyboard()); | ||
| onView(withId(R.id.btnSaveSettings)).perform(click()); | ||
|
|
||
| Thread.sleep(4000); | ||
|
|
||
| assertEquals("expect no worker running at login page", 0, getRunningWorkers()); | ||
|
|
||
| onWebView() | ||
| .withNoTimeout() | ||
| .withElement(findElement(Locator.ID, "user")) | ||
| .perform(clearElement()) | ||
| .perform(DriverAtoms.webKeys(TEST_USERNAME)) //to be created first | ||
| .withElement(findElement(Locator.ID, "password")) | ||
| .perform(clearElement()) | ||
| .perform(DriverAtoms.webKeys(TEST_PASSWORD)) | ||
| .withElement(findElement(Locator.ID, "login")) | ||
| .perform(webClick()); | ||
|
|
||
| Thread.sleep(10 * 1000); | ||
|
|
||
| ActivityScenario<EmbeddedBrowserActivity> embeddedScenario = ActivityScenario.launch(EmbeddedBrowserActivity.class); | ||
| assertEquals("expect no work manager while app is in foreground", 0, getRunningWorkers()); | ||
|
|
||
| //close app | ||
| embeddedScenario.onActivity(EmbeddedBrowserActivity::onBackPressed); | ||
| Thread.sleep(1000); | ||
| assertEquals("expect work manager enqueued while app is in background", 1, getRunningWorkers()); | ||
|
|
||
| //reopen app | ||
| embeddedScenario = ActivityScenario.launch(EmbeddedBrowserActivity.class); | ||
| assertEquals("no work manager on app restart", 0, getRunningWorkers()); | ||
| } | ||
|
|
||
| private long getRunningWorkers() throws ExecutionException, InterruptedException { | ||
| List<WorkInfo> workInfos = WorkManager.getInstance(context) | ||
| .getWorkInfosByTag(NotificationWorker.NOTIFICATION_WORK_REQUEST_TAG) | ||
| .get(); | ||
| return workInfos.stream() | ||
| .filter(info -> info.getState() == WorkInfo.State.ENQUEUED || info.getState() == WorkInfo.State.RUNNING) | ||
| .count(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| <uses-feature android:name="android.hardware.location.network" android:required="false"/> | ||
|
|
||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> | ||
| <uses-permission android:name="android.permission.INTERNET"/> | ||
| <uses-permission android:name="android.permission.VIBRATE"/> | ||
| <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> | ||
|
|
@@ -50,7 +51,8 @@ | |
| <action android:name="android.intent.action.VIEW" /> | ||
| <category android:name="android.intent.category.DEFAULT" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <data android:scheme="@string/scheme" android:host="@string/app_host" android:pathPattern=".*"/> | ||
| <data android:scheme="@string/scheme" android:host="@string/app_host" android:pathPattern=".*" | ||
| tools:ignore="AppLinkUrlError" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity android:name="ConnectionErrorActivity" | ||
|
|
@@ -92,6 +94,10 @@ | |
| android:resource="@xml/file_paths"> | ||
| </meta-data> | ||
| </provider> | ||
| <service android:name="androidx.work.impl.background.systemjob.SystemJobService" | ||
| android:permission="android.permission.BIND_JOB_SERVICE" | ||
| android:exported="true" | ||
| tools:targetApi="23" /> | ||
|
Comment on lines
+97
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of defining this service here? I tried removing it and it seems like my notifications still get generated as expected... 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its just for linting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, well I think I was just re-building/running the app when I tried removing it, so maybe there is a deeper linting that will fail if I tried doing the full apk assemble....
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonathanbataire Did you ever figure out if this was required?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </application> | ||
|
|
||
| <queries> | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring this test until a test server with these changes medic/cht-core#9987 is available cc @lorerod @jkuester