59 lines
4.0 KiB
JavaScript
59 lines
4.0 KiB
JavaScript
// Real notification category persistence and runtime policy; no sound is played and no server is contacted.
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
import { launchApp, waitForAsync } from './lib/electron-app.mjs';
|
|
const args = process.argv.slice(2);
|
|
const option = key => args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : undefined;
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-notifications-qa-'));
|
|
const out = path.resolve(option('out') ?? 'smoke-out/notification-groups');
|
|
mkdirSync(out, { recursive: true });
|
|
const result = { checks: [], errors: [], scope: 'Real category switches, IPC preferences, policy and restart; no Listen click or audible output' };
|
|
let app, page;
|
|
const open = async () => {
|
|
await page.click('#btn-settings');
|
|
await page.click('#settings-nav [data-panel="notifications"]');
|
|
};
|
|
try {
|
|
app = await launchApp({ profile, exe: option('exe') });
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', error => result.errors.push(error.message));
|
|
await page.waitForSelector('#view-onboarding', { state: 'visible' });
|
|
await page.fill('#onboarding-nick', 'Notification QA');
|
|
await page.click('#onboarding-submit');
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await open();
|
|
const group = page.locator('[data-notification-group="messaging"]');
|
|
await group.locator('[data-setting="message_received"] [role="radio"]').nth(2).click();
|
|
await waitForAsync(page, async () => (await window.teamspeach.getPrefs()).notificationStates.message_received === 2);
|
|
await group.getByRole('switch').uncheck();
|
|
await waitForAsync(page, async () => (await window.teamspeach.getPrefs()).notificationStates.group_messaging === 0);
|
|
await group.getByText('All sound notifications in this section are disabled.', { exact: true }).waitFor();
|
|
assert.equal(await group.locator('[data-setting]').count(), 0);
|
|
const muted = await page.evaluate(async () => {
|
|
const n = await import('./js/notifications.js');
|
|
return { item: n.settingState('message_received'), allowed: n.soundAllowed('message_received', 2, { away: true, outputMuted: true }, 'TextMessage.FromAnotherClient') };
|
|
});
|
|
assert.deepEqual(muted, { item: 2, allowed: false });
|
|
await page.screenshot({ path: path.join(out, 'group-disabled.png') });
|
|
result.checks.push('Disabling a category hides its rows and suppresses Important sounds without overwriting their stored state');
|
|
await app.close(); app = null;
|
|
app = await launchApp({ profile, exe: option('exe') });
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', error => result.errors.push(error.message));
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await open();
|
|
const restored = page.locator('[data-notification-group="messaging"]');
|
|
assert.equal(await restored.getByRole('switch').isChecked(), false);
|
|
await restored.getByRole('switch').check();
|
|
await waitForAsync(page, async () => (await window.teamspeach.getPrefs()).notificationStates.group_messaging === 1);
|
|
assert.equal(await restored.locator('[data-setting="message_received"] [role="radio"]').nth(2).getAttribute('aria-checked'), 'true');
|
|
const allowed = await page.evaluate(async () => (await import('./js/notifications.js')).soundAllowed('message_received', 2, { away: true, outputMuted: true }, 'TextMessage.FromAnotherClient'));
|
|
assert.equal(allowed, true);
|
|
result.checks.push('Restart retains category mute; re-enabling restores the saved Important event choice and its actual runtime policy');
|
|
assert.deepEqual(result.errors, []);
|
|
result.ok = true;
|
|
} catch (error) { result.ok = false; result.error = error.stack; process.exitCode = 1; if (page) await page.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {}); }
|
|
finally { if (app) await app.close(); rmSync(profile, { recursive: true, force: true }); writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2)); }
|