Skip to content

Commit 7fdb940

Browse files
committed
feat: complete Phase 2 account lifecycle and verification
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent d49787f commit 7fdb940

15 files changed

Lines changed: 710 additions & 67 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,45 @@ jobs:
2727
name: qownnotes-mobile-debug-${{ github.sha }}
2828
path: app/build/outputs/apk/debug/app-debug.apk
2929
retention-days: 14
30+
31+
device-test:
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 45
34+
steps:
35+
- uses: actions/checkout@v5
36+
- uses: actions/setup-java@v4
37+
with:
38+
distribution: temurin
39+
java-version: "17"
40+
cache: gradle
41+
- uses: android-actions/setup-android@v3
42+
- name: Install Android SDK
43+
run: sdkmanager "platforms;android-36" "build-tools;35.0.0" "build-tools;36.0.0"
44+
- name: Enable KVM
45+
run: |
46+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
47+
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
48+
sudo udevadm control --reload-rules
49+
sudo udevadm trigger --name-match=kvm
50+
- name: Run Android device tests
51+
uses: reactivecircus/android-emulator-runner@v2
52+
with:
53+
api-level: 36
54+
target: google_apis
55+
arch: x86_64
56+
profile: pixel_6
57+
disable-animations: true
58+
emulator-options: >-
59+
-no-window -no-snapshot -no-boot-anim -noaudio
60+
-gpu swiftshader_indirect -camera-back none
61+
script: ./gradlew --no-daemon --no-configuration-cache connectedDebugAndroidTest
62+
- name: Upload device-test reports
63+
if: always()
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: android-device-test-reports-${{ github.sha }}
67+
path: |
68+
**/build/reports/androidTests/connected/**
69+
**/build/outputs/androidTest-results/connected/**
70+
if-no-files-found: warn
71+
retention-days: 14

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Nextcloud Notes server app with Notes API 1.2 or newer. Downloaded notes and
88
account metadata remain available offline; credentials stay in Nextcloud's SSO
99
integration and are not copied into the QOwnNotes database.
1010

11+
Use **Remove** in an account's note list to delete that account reference, its
12+
synchronization history, and its cached notes from QOwnNotes Mobile. This does
13+
not remove the account from Nextcloud Files or delete notes from the server.
14+
1115
## NixOS Recipes
1216

1317
### Enter The Development Environment
@@ -108,6 +112,10 @@ With an emulator or physical device running:
108112
just device-test
109113
```
110114

115+
CI runs the same instrumentation suite on an API 36 emulator. Real Nextcloud
116+
SSO interoperability remains a manual test because it requires an installed
117+
and authenticated Nextcloud Files app.
118+
111119
### Run All Host-Side Checks
112120

113121
```sh

‎app/build.gradle.kts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ android {
1717
targetSdk = 36
1818
versionCode = 1
1919
versionName = "0.1.0"
20-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
testInstrumentationRunner = "org.qownnotes.mobile.QOwnNotesTestRunner"
2121
}
2222

2323
signingConfigs {
@@ -68,6 +68,7 @@ dependencies {
6868
androidTestImplementation(platform(libs.androidx.compose.bom))
6969
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
7070
androidTestImplementation(libs.androidx.test.ext.junit)
71+
androidTestImplementation(libs.androidx.test.runner)
7172
androidTestImplementation(libs.androidx.test.espresso.core)
7273
}
7374

‎app/src/androidTest/kotlin/org/qownnotes/mobile/AppLaunchTest.kt‎

Lines changed: 176 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,198 @@ package org.qownnotes.mobile
22

33
import androidx.compose.ui.test.assertIsDisplayed
44
import androidx.compose.ui.test.junit4.createAndroidComposeRule
5+
import androidx.compose.ui.test.onAllNodesWithText
6+
import androidx.compose.ui.test.onNodeWithTag
57
import androidx.compose.ui.test.onNodeWithText
8+
import androidx.compose.ui.test.performClick
69
import androidx.test.ext.junit.runners.AndroidJUnit4
10+
import com.nextcloud.android.sso.model.SingleSignOnAccount
11+
import java.io.IOException
12+
import kotlinx.coroutines.CompletableDeferred
13+
import kotlinx.coroutines.runBlocking
14+
import org.junit.Assert.assertEquals
15+
import org.junit.Before
716
import org.junit.Rule
817
import org.junit.Test
918
import org.junit.runner.RunWith
19+
import org.qownnotes.mobile.core.BackendException
20+
import org.qownnotes.mobile.core.PullResult
21+
import org.qownnotes.mobile.core.RemoteNote
1022

1123
@RunWith(AndroidJUnit4::class)
1224
class AppLaunchTest {
1325
@get:Rule val composeRule = createAndroidComposeRule<MainActivity>()
1426

27+
private val application
28+
get() = composeRule.activity.application as TestQOwnNotesApplication
29+
30+
@Before
31+
fun resetApplication() {
32+
runBlocking { application.reset() }
33+
composeRule.waitForIdle()
34+
}
35+
1536
@Test
16-
fun launchesAccountEntryPoint() {
17-
composeRule.onNodeWithText("Add", substring = true).assertIsDisplayed()
37+
fun onboardingImportsAccountAndDisplaysInitialPull() {
38+
val account = testAccount("alice")
39+
application.fakeAccountImporter.enqueue(account)
40+
application.fakeBackend.enqueue(account, pull("Alice note", "etag-1", 10))
41+
42+
composeRule.onNodeWithTag("onboarding").assertIsDisplayed()
43+
composeRule.onNodeWithTag("add-account").performClick()
44+
45+
composeRule.waitForText("Alice note")
46+
composeRule.onNodeWithText("alice @ cloud.example").assertIsDisplayed()
47+
composeRule.onNodeWithText("Alice note").assertIsDisplayed()
1848
}
1949

2050
@Test
2151
fun showsAccountImportFailureOnOnboarding() {
22-
composeRule.runOnUiThread {
23-
val application = composeRule.activity.application as QOwnNotesApplication
24-
application.component.reportImportError(IllegalStateException("Import unavailable"))
25-
}
52+
application.fakeAccountImporter.enqueueFailure(IllegalStateException("Import unavailable"))
2653

54+
composeRule.onNodeWithTag("add-account").performClick()
55+
56+
composeRule.waitForText("Import unavailable")
2757
composeRule.onNodeWithText("Import unavailable").assertIsDisplayed()
2858
}
59+
60+
@Test
61+
fun accountImportSurvivesActivityRecreationDuringValidation() {
62+
val account = testAccount("alice")
63+
val validationGate = CompletableDeferred<Unit>()
64+
application.fakeBackend.validationGate = validationGate
65+
application.fakeAccountImporter.enqueue(account)
66+
application.fakeBackend.enqueue(account, pull("Alice note", "etag-1", 10))
67+
composeRule.onNodeWithTag("add-account").performClick()
68+
composeRule.waitUntil {
69+
application.fakeBackend.validatedAccountIds.isNotEmpty()
70+
}
71+
72+
composeRule.activityRule.scenario.recreate()
73+
validationGate.complete(Unit)
74+
75+
composeRule.waitForText("Alice note")
76+
composeRule.onNodeWithText("Alice note").assertIsDisplayed()
77+
}
78+
79+
@Test
80+
fun cachedNotesRemainVisibleAfterOfflineActivityRestart() {
81+
val account = importAccount("alice", "Cached note", "etag-1", 10)
82+
application.fakeBackend.enqueueFailure(
83+
account,
84+
BackendException.Retryable(IOException("offline"))
85+
)
86+
87+
composeRule.activityRule.scenario.recreate()
88+
89+
composeRule.waitForText("The server could not be reached")
90+
composeRule.onNodeWithText("Cached note").assertIsDisplayed()
91+
}
92+
93+
@Test
94+
fun reconnectPreservesCachedDataAndCheckpoint() {
95+
val account = importAccount("alice", "Cached note", "etag-1", 10)
96+
application.fakeBackend.enqueueFailure(account, BackendException.Authentication())
97+
composeRule.onNodeWithText("Refresh").performClick()
98+
composeRule.waitForText("Reconnect")
99+
100+
application.fakeAccountImporter.enqueue(account)
101+
application.fakeBackend.enqueue(account, pull("Updated note", "etag-2", 20))
102+
composeRule.onNodeWithText("Reconnect").performClick()
103+
104+
composeRule.waitForText("Updated note")
105+
composeRule.onNodeWithText("Cached note").assertDoesNotExist()
106+
val reconnectCheckpoint = application.fakeBackend.checkpoints.last().second
107+
assertEquals("etag-1", reconnectCheckpoint.collectionEtag)
108+
assertEquals(10L, reconnectCheckpoint.lastModifiedEpochSeconds)
109+
assertEquals(2, application.fakeBackend.validatedAccountIds.size)
110+
}
111+
112+
@Test
113+
fun reconnectRejectsADifferentAccount() {
114+
val account = importAccount("alice", "Cached note", "etag-1", 10)
115+
application.fakeBackend.enqueueFailure(account, BackendException.Authentication())
116+
composeRule.onNodeWithText("Refresh").performClick()
117+
composeRule.waitForText("Reconnect")
118+
119+
application.fakeAccountImporter.enqueue(testAccount("bob"))
120+
composeRule.onNodeWithText("Reconnect").performClick()
121+
122+
composeRule.waitForText("Select the same Nextcloud account to reconnect")
123+
composeRule.onNodeWithText("Cached note").assertIsDisplayed()
124+
}
125+
126+
@Test
127+
fun addRejectsAConflictingLocalIdentity() {
128+
importAccount("alice", "Alice note", "etag-1", 10)
129+
application.fakeAccountImporter.enqueue(
130+
SingleSignOnAccount(
131+
"alice",
132+
"someone-else",
133+
"test-token",
134+
"https://other.example",
135+
"nextcloud"
136+
)
137+
)
138+
139+
composeRule.onNodeWithTag("add-account").performClick()
140+
141+
composeRule.waitForText("A different Nextcloud account already uses this local identity")
142+
composeRule.onNodeWithText("Alice note").assertIsDisplayed()
143+
}
144+
145+
@Test
146+
fun switchingAndRemovingAccountsKeepsDataAccountScoped() {
147+
importAccount("alice", "Alice note", "etag-a", 10)
148+
val bob = testAccount("bob")
149+
application.fakeAccountImporter.enqueue(bob)
150+
application.fakeBackend.enqueue(bob, pull("Bob note", "etag-b", 20))
151+
composeRule.onNodeWithTag("add-account").performClick()
152+
composeRule.waitForText("Switch")
153+
composeRule.onNodeWithTag("switch-account").performClick()
154+
composeRule.waitForText("Bob note")
155+
composeRule.onNodeWithText("Alice note").assertDoesNotExist()
156+
157+
composeRule.onNodeWithTag("remove-account").performClick()
158+
composeRule.onNodeWithText("server notes will not be deleted", substring = true)
159+
.assertIsDisplayed()
160+
composeRule.onNodeWithTag("confirm-remove-account").performClick()
161+
composeRule.waitForText("Alice note")
162+
composeRule.onNodeWithText("Bob note").assertDoesNotExist()
163+
164+
composeRule.onNodeWithTag("remove-account").performClick()
165+
composeRule.onNodeWithTag("confirm-remove-account").performClick()
166+
composeRule.waitForText("Your Nextcloud notes, offline")
167+
}
168+
169+
private fun importAccount(
170+
user: String,
171+
title: String,
172+
etag: String,
173+
modified: Long
174+
): SingleSignOnAccount {
175+
val account = testAccount(user)
176+
application.fakeAccountImporter.enqueue(account)
177+
application.fakeBackend.enqueue(account, pull(title, etag, modified))
178+
composeRule.onNodeWithTag("add-account").performClick()
179+
composeRule.waitForText(title)
180+
return account
181+
}
182+
183+
private fun testAccount(user: String) =
184+
SingleSignOnAccount(user, user, "test-token", "https://cloud.example", "nextcloud")
185+
186+
private fun pull(title: String, etag: String, modified: Long) = PullResult(
187+
notes = listOf(RemoteNote(42, etag, title, "# $title", "", modified)),
188+
collectionEtag = etag,
189+
lastModifiedEpochSeconds = modified
190+
)
191+
192+
private fun androidx.compose.ui.test.junit4.AndroidComposeTestRule<*, *>.waitForText(
193+
text: String
194+
) {
195+
waitUntil(timeoutMillis = 10_000) {
196+
onAllNodesWithText(text).fetchSemanticsNodes().isNotEmpty()
197+
}
198+
}
29199
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.qownnotes.mobile
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import androidx.test.runner.AndroidJUnitRunner
6+
7+
class QOwnNotesTestRunner : AndroidJUnitRunner() {
8+
override fun newApplication(
9+
classLoader: ClassLoader,
10+
className: String,
11+
context: Context
12+
): Application =
13+
super.newApplication(classLoader, TestQOwnNotesApplication::class.java.name, context)
14+
}

0 commit comments

Comments
 (0)