chart/tests/e2e/drawings.test.mjs

53 lines
2.4 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
withChart, chartBox, at, armTool, drawingIds, assertNoPageErrors,
} from './helpers.mjs';
test('editing a drawing name with Backspace or Delete cannot delete the drawing',
{ timeout: 180000 }, async () => {
await withChart(async page => {
const label = `e2e rename ${Date.now()}`;
const box = await chartBox(page);
await armTool(page, 'Trendline');
await page.fill('input[aria-label="Trendline label"]', label);
const first = at(box, 0.42, 0.55);
const second = at(box, 0.62, 0.40);
await page.mouse.click(first.x, first.y);
await page.waitForTimeout(300);
await page.mouse.click(second.x, second.y);
await page.waitForFunction(name =>
[...document.querySelectorAll('input[aria-label="Drawing name"]')]
.some(input => input.value === name), label);
await page.waitForFunction(name =>
window.__chart.levels.some(level => level.label === name && !level.id.startsWith('tmp_')),
label);
const created = await page.evaluate(name => {
const line = window.__chart.levels.find(
level => level.label === name && !level.id.startsWith('tmp_'),
);
return line?.id || null;
}, label);
assert.ok(created, 'the trendline was not created');
assert.ok((await drawingIds(page)).includes(created), 'the trendline was not persisted');
await page.fill('input[aria-label="Filter drawings by text"]', label);
const input = page.locator('input[aria-label="Drawing name"]');
assert.equal(await input.count(), 1, 'the unique drawing filter did not isolate the test line');
await input.focus();
await input.press('End');
await input.press('Backspace');
assert.equal(await input.inputValue(), label.slice(0, -1), 'Backspace did not edit the name');
await page.waitForTimeout(500);
assert.ok((await drawingIds(page)).includes(created), 'Backspace deleted the drawing');
const beforeDelete = await input.inputValue();
await input.press('Home');
await input.press('Delete');
assert.equal(await input.inputValue(), beforeDelete.slice(1), 'Delete did not edit the name');
await page.waitForTimeout(500);
assert.ok((await drawingIds(page)).includes(created), 'Delete deleted the drawing');
assertNoPageErrors(page, assert);
});
});