Files
corescope-rx/test/sharelog.test.mjs
efiten 3963704592 fix(native): share the debug log through the Android share sheet
In the Android app the Share button did nothing: the WebView has no
navigator.share, and the download-link fallback is ignored there. The
native app now writes the log to its cache (@capacitor/filesystem 8.1.5)
and opens the share sheet with it as a .txt attachment (@capacitor/share
8.0.3). The web paths are unchanged. pickShareMethod picks 'native' first;
test/sharelog.test.mjs covers it.
2026-11-10 22:20:03 +01:00

32 lines
1.5 KiB
JavaScript

// Debug-log export: capability-based method selection + the mailto fallback.
// Run: node --test
import { test } from 'node:test';
import assert from 'node:assert';
import { pickShareMethod, buildMailto } from '../src/sharelog.js';
test('prefers the Web Share API when files can be shared', () => {
assert.strictEqual(pickShareMethod({ canShareFiles: true, canDownload: true }), 'share');
});
test('the native app uses its own share sheet, whatever the WebView claims', () => {
assert.strictEqual(pickShareMethod({ native: true, canShareFiles: false, canDownload: true }), 'native');
assert.strictEqual(pickShareMethod({ native: true, canShareFiles: true, canDownload: true }), 'native');
assert.strictEqual(pickShareMethod({ native: false, canShareFiles: true, canDownload: true }), 'share');
});
test('falls back to download when share is unavailable', () => {
assert.strictEqual(pickShareMethod({ canShareFiles: false, canDownload: true }), 'download');
});
test('last resort is mailto when neither share nor download is possible', () => {
assert.strictEqual(pickShareMethod({ canShareFiles: false, canDownload: false }), 'mailto');
});
test('mailto encodes subject + body and truncates a long log', () => {
const url = buildMailto('hello world', 'subj');
assert.match(url, /^mailto:\?subject=subj&body=hello%20world$/);
const long = 'x'.repeat(5000);
assert.ok(buildMailto(long).includes('truncated'));
assert.ok(decodeURIComponent(buildMailto(long).split('&body=')[1]).length < long.length);
});