|
| 1 | +import { waitForApp, waitForAppReady } from '../helpers/app-helpers'; |
| 2 | +import { triggerAuthDeepLinkBypass } from '../helpers/deep-link-helpers'; |
| 3 | +import { |
| 4 | + clickText, |
| 5 | + textExists, |
| 6 | + waitForText, |
| 7 | + waitForWebView, |
| 8 | + waitForWindowVisible, |
| 9 | +} from '../helpers/element-helpers'; |
| 10 | +import { supportsExecuteScript } from '../helpers/platform'; |
| 11 | +import { completeOnboardingIfVisible, navigateViaHash } from '../helpers/shared-flows'; |
| 12 | +import { startMockServer, stopMockServer } from '../mock-server'; |
| 13 | + |
| 14 | +/** |
| 15 | + * Data Management E2E spec (ID 13.5). |
| 16 | + * Covers: |
| 17 | + * - 13.5.1 Clear App Data confirmation |
| 18 | + * - 13.5.2 Cache Reset (via Clear App Data flow) |
| 19 | + * - 13.5.3 Full State Reset |
| 20 | + * |
| 21 | + * Uses isolated OPENHUMAN_WORKSPACE (handled by e2e-run-spec.sh). |
| 22 | + */ |
| 23 | + |
| 24 | +function stepLog(message: string, context?: unknown): void { |
| 25 | + const stamp = new Date().toISOString(); |
| 26 | + if (context === undefined) { |
| 27 | + console.log(`[SettingsDataMgmtE2E][${stamp}] ${message}`); |
| 28 | + return; |
| 29 | + } |
| 30 | + console.log(`[SettingsDataMgmtE2E][${stamp}] ${message}`, JSON.stringify(context, null, 2)); |
| 31 | +} |
| 32 | + |
| 33 | +describe('Settings - Data Management', () => { |
| 34 | + before(async function beforeSuite() { |
| 35 | + if (!supportsExecuteScript()) { |
| 36 | + stepLog('Skipping suite on Mac2 — navigation helpers require browser.execute'); |
| 37 | + this.skip(); |
| 38 | + } |
| 39 | + |
| 40 | + stepLog('starting mock server'); |
| 41 | + await startMockServer(); |
| 42 | + stepLog('waiting for app'); |
| 43 | + await waitForApp(); |
| 44 | + stepLog('triggering auth bypass deep link'); |
| 45 | + await triggerAuthDeepLinkBypass('e2e-data-mgmt'); |
| 46 | + await waitForWindowVisible(25_000); |
| 47 | + await waitForWebView(15_000); |
| 48 | + await waitForAppReady(15_000); |
| 49 | + await completeOnboardingIfVisible('[SettingsDataMgmtE2E]'); |
| 50 | + }); |
| 51 | + |
| 52 | + after(async () => { |
| 53 | + stepLog('stopping mock server'); |
| 54 | + await stopMockServer(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('shows Clear App Data confirmation dialog and handles Cancel (13.5.1)', async () => { |
| 58 | + stepLog('navigating to /settings'); |
| 59 | + await navigateViaHash('/settings'); |
| 60 | + |
| 61 | + await waitForText('Clear App Data', 15_000); |
| 62 | + |
| 63 | + stepLog('clicking Clear App Data'); |
| 64 | + await clickText('Clear App Data'); |
| 65 | + |
| 66 | + await waitForText('This will sign you out and permanently delete local app data', 5_000); |
| 67 | + |
| 68 | + stepLog('clicking Cancel'); |
| 69 | + await clickText('Cancel'); |
| 70 | + |
| 71 | + // Confirm dialog is gone and we are still in settings |
| 72 | + expect(await textExists('This will sign you out and permanently delete local app data')).toBe( |
| 73 | + false |
| 74 | + ); |
| 75 | + expect(await textExists('Clear App Data')).toBe(true); |
| 76 | + }); |
| 77 | + |
| 78 | + it('performs Full State Reset (13.5.3)', async () => { |
| 79 | + // We already confirmed the Cancel flow above. |
| 80 | + // Now we confirm the actual reset. |
| 81 | + stepLog('navigating to /settings (reset flow)'); |
| 82 | + await navigateViaHash('/settings'); |
| 83 | + await waitForText('Clear App Data', 15_000); |
| 84 | + |
| 85 | + stepLog('opening reset modal'); |
| 86 | + await clickText('Clear App Data'); |
| 87 | + await waitForText('This will sign you out', 5_000); |
| 88 | + |
| 89 | + stepLog('clicking confirm Clear App Data'); |
| 90 | + // The button text in the modal is also "Clear App Data". |
| 91 | + // clickText clicks the first one it finds. |
| 92 | + await clickText('Clear App Data'); |
| 93 | + |
| 94 | + // After reset, the app should restart and show the Welcome screen. |
| 95 | + // In E2E tests, the restartApp command might just close the window or |
| 96 | + // the mock server might capture a request. |
| 97 | + // However, the test runner handles the process lifecycle. |
| 98 | + |
| 99 | + // We expect to land back on the login/welcome screen |
| 100 | + await waitForText('Welcome', 25_000); |
| 101 | + expect(await textExists('Sign in')).toBe(true); |
| 102 | + }); |
| 103 | +}); |
0 commit comments