66 lines
3.0 KiB
TypeScript
66 lines
3.0 KiB
TypeScript
import { test } from 'node:test';
|
|||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import fs from 'node:fs';
|
||
|
|
import { parseSettingsSource, searchSettings } from './settingsIndex';
|
||
|
|
import { SettingsPages } from '../pages';
|
||
|
|
|
||
|
|
const general = fs.readFileSync('src/app/features/settings/general/General.tsx', 'utf8');
|
||
|
|
const devices = fs.readFileSync('src/app/features/settings/devices/Devices.tsx', 'utf8');
|
||
|
|
const sys = fs.readFileSync(
|
||
|
|
'src/app/features/settings/notifications/SystemNotification.tsx',
|
||
|
|
'utf8',
|
||
|
|
);
|
||
|
|
const entries = [
|
||
|
|
...parseSettingsSource('src/app/features/settings/general/General.tsx', general),
|
||
|
|
...parseSettingsSource('src/app/features/settings/devices/Devices.tsx', devices),
|
||
|
|
...parseSettingsSource('src/app/features/settings/notifications/SystemNotification.tsx', sys),
|
||
|
|
];
|
||
|
|
const find = (t: string) => entries.find((e) => e.title === t);
|
||
|
|
|
||
|
|
test('[#463] indexes the real settings source with the right pages', () => {
|
||
|
|
assert.equal(find('Push to deafen')?.page, SettingsPages.CallsPage);
|
||
|
|
assert.equal(find('Strip tracking parameters from links')?.page, SettingsPages.DevicesPage);
|
||
|
|
assert.equal(find('Page zoom')?.page, SettingsPages.AppearancePage);
|
||
|
|
assert.equal(find('Enter for a new line')?.page, SettingsPages.MessagesPage);
|
||
|
|
assert.equal(find('Show hidden events')?.page, SettingsPages.DeveloperToolsPage);
|
||
|
|
assert.equal(find('Device verification')?.page, SettingsPages.DevicesPage);
|
||
|
|
assert.equal(find('Quiet hours')?.page, SettingsPages.NotificationPage);
|
||
|
|
assert.equal(find('Launch on login')?.desktopOnly, true);
|
||
|
|
assert.match(find('Strip tracking parameters from links')?.description ?? '', /utm_/);
|
||
|
|
assert.ok(entries.length > 70, `indexed ${entries.length}`);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('[#463] search: words anywhere, title first, desktop-only hidden in a browser', () => {
|
||
|
|
assert.equal(searchSettings(entries, 'deafen')[0]?.title, 'Push to deafen');
|
||
|
|
assert.equal(
|
||
|
|
searchSettings(entries, 'tracking')[0]?.title,
|
||
|
|
'Strip tracking parameters from links',
|
||
|
|
);
|
||
|
|
assert.equal(searchSettings(entries, 'zoom')[0]?.title, 'Page zoom');
|
||
|
|
assert.ok(searchSettings(entries, 'utm').some((e) => e.title.startsWith('Strip tracking')));
|
||
|
|
assert.equal(searchSettings(entries, 'launch on login').length, 0);
|
||
|
|
assert.equal(
|
||
|
|
searchSettings(entries, 'launch on login', { desktop: true })[0]?.title,
|
||
|
|
'Launch on login',
|
||
|
|
);
|
||
|
|
assert.deepEqual(searchSettings(entries, ' '), []);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('[#463] parser handles the attribute forms and skips dynamic titles', () => {
|
||
|
|
const src = `
|
||
|
|
<Text size="L400">Things</Text>
|
||
|
|
<SettingTile title="Plain" description="A & B" after={<Switch value={x} />} />
|
||
|
|
<SettingTile title={'Quoted'} description={\`tick\`} />
|
||
|
|
<SettingTile title={\`Dynamic \${name}\`} />
|
||
|
|
<SettingTile title={someVar} />`;
|
||
|
|
const got = parseSettingsSource('src/app/features/settings/about/About.tsx', src);
|
||
|
|
assert.deepEqual(
|
||
|
|
got.map((e) => [e.title, e.description, e.section]),
|
||
|
|
[
|
||
|
|
['Plain', 'A & B', 'Things'],
|
||
|
|
['Quoted', 'tick', 'Things'],
|
||
|
|
['Things', '', undefined],
|
||
|
|
],
|
||
|
|
);
|
||
|
|
});
|