Files
corescope-rx/test/appexit.test.mjs
efiten 59169ac69e android: Stop & close button on Home
Back and Home keep capture running in the background, and Disconnect sits on
Settings, so testers had no easy way to end the app. The button (native app
only) asks first while connected, disconnects, then closes the app with
@capacitor/app exitApp. Queued receptions stay and upload on the next connect.
The capture notification now points to the button.
2026-11-14 10:22:12 +01:00

48 lines
1.6 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { stopAndClose, STOP_CONFIRM_TEXT } from '../src/appexit.js';
function deps(over = {}) {
const calls = [];
return {
calls,
args: {
connected: true,
confirm: (text) => { calls.push(['confirm', text]); return true; },
disconnect: async () => { calls.push(['disconnect']); },
exitApp: async () => { calls.push(['exit']); },
...over,
},
};
}
test('connected: asks, then disconnects before it exits', async () => {
const d = deps();
assert.equal(await stopAndClose(d.args), 'closed');
assert.deepEqual(d.calls, [['confirm', STOP_CONFIRM_TEXT], ['disconnect'], ['exit']]);
});
test('connected and the user says no: nothing stops', async () => {
const calls = [];
const d = deps({ confirm: () => { calls.push('confirm'); return false; }, disconnect: async () => calls.push('disconnect'), exitApp: async () => calls.push('exit') });
assert.equal(await stopAndClose(d.args), 'cancelled');
assert.deepEqual(calls, ['confirm']);
});
test('not connected: closes without asking', async () => {
const d = deps({ connected: false });
assert.equal(await stopAndClose(d.args), 'closed');
assert.deepEqual(d.calls, [['disconnect'], ['exit']]);
});
test('a failing disconnect still closes the app', async () => {
let exited = false;
const d = deps({ disconnect: async () => { throw new Error('link gone'); }, exitApp: async () => { exited = true; } });
assert.equal(await stopAndClose(d.args), 'closed');
assert.ok(exited);
});
test('the question says queued receptions are kept', () => {
assert.match(STOP_CONFIRM_TEXT, /kept/);
});