46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { launch, openChart, assertNoPageErrors } from './helpers.mjs';
|
|
|
|
async function chartStartsWithPrefs(stored, expectedTimeframe) {
|
|
const { browser, page } = await launch();
|
|
try {
|
|
await page.addInitScript(value => {
|
|
localStorage.setItem('chart-layer-prefs', value);
|
|
}, stored);
|
|
await openChart(page);
|
|
|
|
assert.equal(
|
|
await page.locator('.timeframes button.active').textContent(),
|
|
expectedTimeframe,
|
|
'the chart did not restore a usable timeframe',
|
|
);
|
|
|
|
await page.locator('details:has(summary:text-is("Layers"))').evaluate(node => { node.open = true; });
|
|
const vwap = page.getByText('Session VWAP').locator('input');
|
|
const before = await vwap.isChecked();
|
|
await vwap.click();
|
|
assert.equal(await vwap.isChecked(), !before, 'the layer control did not toggle');
|
|
|
|
await page.click('.timeframes button:text-is("15m")');
|
|
await page.waitForFunction(
|
|
() => document.querySelector('.timeframes button.active')?.textContent === '15m',
|
|
);
|
|
assertNoPageErrors(page, assert);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
}
|
|
|
|
test('an old partial layer preference cannot prevent chart startup',
|
|
{ timeout: 180000 }, async () => {
|
|
await chartStartsWithPrefs(
|
|
JSON.stringify({ base_tf: '5m', enabled: { manual: false } }),
|
|
'5m',
|
|
);
|
|
});
|
|
|
|
test('malformed layer preferences cannot prevent chart startup',
|
|
{ timeout: 180000 }, async () => {
|
|
await chartStartsWithPrefs('{"enabled":', '1m');
|
|
});
|