Files
cinny/src/app/utils/pwaInstall.test.ts
T

35 lines
1.4 KiB
TypeScript
Raw Normal View History

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { INSTALL_HINT_SNOOZE_MS, installHintKind, shouldShowInstallHint } from './pwaInstall';
const base = { isTauri: false, isStandalone: false, visits: 2, dismissedAt: null, now: 1_000_000 };
describe('shouldShowInstallHint', () => {
it('shows from the second visit in a plain browser tab', () => {
assert.equal(shouldShowInstallHint(base), true);
assert.equal(shouldShowInstallHint({ ...base, visits: 1 }), false);
});
it('never shows in the desktop app or an installed PWA', () => {
assert.equal(shouldShowInstallHint({ ...base, isTauri: true }), false);
assert.equal(shouldShowInstallHint({ ...base, isStandalone: true }), false);
});
it('snoozes for 30 days after a dismissal', () => {
const dismissedAt = base.now - INSTALL_HINT_SNOOZE_MS + 1;
assert.equal(shouldShowInstallHint({ ...base, dismissedAt }), false);
assert.equal(
shouldShowInstallHint({ ...base, dismissedAt: base.now - INSTALL_HINT_SNOOZE_MS }),
true,
);
});
});
describe('installHintKind', () => {
it('prefers a real prompt, falls back to iOS instructions, else nothing', () => {
assert.equal(installHintKind(true, true), 'prompt');
assert.equal(installHintKind(false, true), 'ios-share');
assert.equal(installHintKind(false, false), 'none');
});
});