Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add offline mutate iOS test (#1404)

Leendert de Borst0bc2ff398e40
diff --git a/apps/mobile-app/app/open/[...path].tsx b/apps/mobile-app/app/open/[...path].tsx
index 711a97f11..c7e9fbd21 100644
--- a/apps/mobile-app/app/open/[...path].tsx
+++ b/apps/mobile-app/app/open/[...path].tsx
@@ -1,6 +1,11 @@
import { Href, useRouter, useLocalSearchParams, useGlobalSearchParams } from 'expo-router';
import { useEffect, useState } from 'react';
+import NativeVaultManager from '@/specs/NativeVaultManager';
+
+// Declare __DEV__ global for TypeScript (provided by React Native runtime)
+declare const __DEV__: boolean;
+
/**
* Action-based deep link handler for special actions triggered from outside the app.
*
@@ -8,6 +13,8 @@ import { useEffect, useState } from 'react';
*
* Supported actions:
* - mobile-unlock/[requestId] - Mobile device unlock via QR code
+ * - __debug__/set-offline/[true|false] - (DEV only) Toggle offline mode for E2E testing
+ * - __debug__/set-api-url/[encoded-url] - (DEV only) Set API URL for E2E testing
*
* This route exists to handle deep links that Expo Router processes before our
* Linking.addEventListener can intercept them. It provides proper navigation
@@ -55,6 +62,69 @@ export default function ActionHandler() : null {
break;
}
+ // Debug actions for E2E testing (only work in dev mode)
+ case '__debug__': {
+ if (!__DEV__) {
+ console.warn('[ActionHandler] Debug actions only available in development');
+ router.replace('/(tabs)/items');
+ setHasNavigated(true);
+ return;
+ }
+
+ const [debugAction, ...debugParams] = actionParams;
+
+ switch (debugAction) {
+ case 'set-offline': {
+ // Set offline mode: aliasvault://open/__debug__/set-offline/true
+ const isOffline = debugParams[0] === 'true';
+ console.debug('[ActionHandler] Setting offline mode:', isOffline);
+ NativeVaultManager.setOfflineMode(isOffline)
+ .then(() => {
+ console.debug('[ActionHandler] Offline mode set to:', isOffline);
+ })
+ .catch((error: Error) => {
+ console.error('[ActionHandler] Failed to set offline mode:', error);
+ });
+ router.replace('/(tabs)/items');
+ setHasNavigated(true);
+ break;
+ }
+
+ case 'set-api-url': {
+ // Set API URL: aliasvault://open/__debug__/set-api-url/http%3A%2F%2Flocalhost%3A5092
+ // Note: If slashes in URL aren't encoded, they become separate path segments
+ // So we join all remaining params with '/' to reconstruct the URL
+ if (debugParams.length === 0) {
+ console.error('[ActionHandler] set-api-url requires URL parameter');
+ router.replace('/(tabs)/items');
+ setHasNavigated(true);
+ return;
+ }
+ // Join params back together (handles both encoded and unencoded slashes)
+ const joinedUrl = debugParams.join('/');
+ const url = decodeURIComponent(joinedUrl);
+ console.debug('[ActionHandler] Setting API URL:', url);
+ NativeVaultManager.setApiUrl(url)
+ .then(() => {
+ console.debug('[ActionHandler] API URL set to:', url);
+ })
+ .catch((error: Error) => {
+ console.error('[ActionHandler] Failed to set API URL:', error);
+ });
+ router.replace('/(tabs)/items');
+ setHasNavigated(true);
+ break;
+ }
+
+ default:
+ console.warn('[ActionHandler] Unknown debug action:', debugAction);
+ router.replace('/(tabs)/items');
+ setHasNavigated(true);
+ break;
+ }
+ break;
+ }
+
default:
// Unknown action, log and go to items
console.warn('[ActionHandler] Unknown action:', action);
diff --git a/apps/mobile-app/ios/AliasVaultUITests/AliasVaultUITests.swift b/apps/mobile-app/ios/AliasVaultUITests/AliasVaultUITests.swift
index 8eb6e185f..2387b1c9a 100644
--- a/apps/mobile-app/ios/AliasVaultUITests/AliasVaultUITests.swift
+++ b/apps/mobile-app/ios/AliasVaultUITests/AliasVaultUITests.swift
@@ -246,7 +246,7 @@ final class AliasVaultUITests: XCTestCase {
// Generate unique item name
let uniqueName = TestConfiguration.generateUniqueName(prefix: "E2E Test")
- // Launch the app (it should already be authenticated from test03)
+ // Launch the app (account should already exist)
app.launch()
// Handle unlock screen if it appears (vault may have locked between tests)
@@ -387,6 +387,12 @@ final class AliasVaultUITests: XCTestCase {
func test05OfflineModeAndSync() async throws {
// Ensure we have a test user
let testUser = try await ensureTestUser()
+
+ // Launch the app (account should already exist)
+ app.launch()
+
+ // Handle unlock screen if it appears (vault may have locked between tests)
+ unlockVaultIfNeeded(with: testUser)
// Store the original API URL for restoration
let originalApiUrl = TestConfiguration.apiUrl
@@ -581,9 +587,9 @@ final class AliasVaultUITests: XCTestCase {
"Should show item detail screen"
)
- // Verify email is preserved
+ // Verify email is preserved (use waitForTextContaining for flexible matching)
XCTAssertTrue(
- app.waitForText("[email protected]", timeout: 5),
+ app.waitForTextContaining("[email protected]", timeout: 5),
"Email should be preserved after sync"
)
@@ -745,10 +751,10 @@ final class AliasVaultUITests: XCTestCase {
/// Perform unlock with provided test user password (for locked vault)
@MainActor
private func performUnlock(with testUser: TestUser) {
- // Wait for "Unlock vault" text to appear (indicates form is loaded)
+ // Wait for "Unlock Vault" text to appear (indicates form is loaded)
XCTAssertTrue(
- app.waitForText("Unlock vault", timeout: 15),
- "Unlock vault header should appear"
+ app.waitForText("Unlock Vault", timeout: 15),
+ "Unlock Vault header should appear"
)
// Find password field - React Native renders it as a generic "Other" element
@@ -801,7 +807,7 @@ final class AliasVaultUITests: XCTestCase {
if unlockScreen.waitForExistenceNoIdle(timeout: 3) {
// Wait for the form to be ready (loading state finished)
- _ = app.waitForText("Unlock vault", timeout: 10)
+ _ = app.waitForText("Unlock Vault", timeout: 10)
// Find the password field by testID
let passwordInput = app.findTextField(testID: "unlock-password-input")
diff --git a/apps/mobile-app/ios/AliasVaultUITests/XCUIElementHelpers.swift b/apps/mobile-app/ios/AliasVaultUITests/XCUIElementHelpers.swift
index f76b319aa..53fffc25a 100644
--- a/apps/mobile-app/ios/AliasVaultUITests/XCUIElementHelpers.swift
+++ b/apps/mobile-app/ios/AliasVaultUITests/XCUIElementHelpers.swift
@@ -157,6 +157,14 @@ extension XCUIApplication {
return self.staticTexts[text].waitForExistenceNoIdle(timeout: timeout)
}
+ /// Wait for any element containing the specified text (searches labels and values)
+ @MainActor
+ func waitForTextContaining(_ text: String, timeout: TimeInterval = 10) -> Bool {
+ let predicate = NSPredicate(format: "label CONTAINS[c] %@ OR value CONTAINS[c] %@", text, text)
+ let element = self.descendants(matching: .any).matching(predicate).firstMatch
+ return element.waitForExistenceNoIdle(timeout: timeout)
+ }
+
/// Hide keyboard if visible (uses press to avoid idle wait)
@MainActor
func hideKeyboardIfVisible() {