Debian Codegraph @

test/playwright/tests/symbols.spec.mjs

raw
1 import {expect, test} from "@playwright/test";
2 import {login} from "../helpers/auth.mjs";
3
4 test.describe("Symbols", () => {
5 test.beforeEach(async ({page}, testInfo) => {
6 const {enablePassword} = testInfo.project.use.rspamdPasswords;
7 await login(page, enablePassword);
8 await page.locator("#symbols_nav").click();
9 await expect(page.locator("#symbolsTable")).toBeVisible();
10 // Ensure table data has been loaded before running tests
11 await expect(page.locator("#symbolsTable tbody tr").first()).toBeVisible();
12 });
13
14 test("shows list and allows filtering by group", async ({page}) => {
15 // Check filtering by group (if selector exists)
16 const groupSelect = page.locator(".footable-filtering select.form-select").first();
17 if (await groupSelect.count()) {
18 // Ensure there is at least one real group besides "Any group"
19 const optionCount = await groupSelect.evaluate((el) => el.options.length);
20 expect(optionCount).toBeGreaterThan(1);
21
22 // Read target group's value and text BEFORE selection to avoid FooTable redraw races
23 const target = await groupSelect.evaluate((el) => {
24 const [, op] = Array.from(el.options); // first non-default option
25 return {text: op.text, value: op.value};
26 });
27
28 const groupCells = page.locator("#symbolsTable tbody tr td.footable-first-visible");
29 const beforeTexts = await groupCells.allTextContents();
30
31 await groupSelect.selectOption({value: target.value});
32 const selectedGroup = target.text.toLowerCase();
33
34 // Wait until table content updates (using expect.poll with matcher)
35 await expect.poll(async () => {
36 const texts = await groupCells.allTextContents();
37 return texts.join("|");
38 }, {timeout: 5000}).not.toBe(beforeTexts.join("|"));
39
40 const afterTexts = await groupCells.allTextContents();
41
42 // Validate that all visible rows belong to the selected group
43 for (const text of afterTexts) {
44 expect(text.toLowerCase()).toContain(selectedGroup);
45 }
46 }
47 });
48
49 test.describe.configure({mode: "serial"});
50 test("edits score for the first symbol and saves", async ({page}) => {
51 const scoreInput = page.locator("#symbolsTable .scorebar").first();
52 const scoreInputId = await scoreInput.evaluate((element) => element.id);
53 const oldValue = await scoreInput.inputValue();
54
55 // Try to change the score value for the first symbol
56 await scoreInput.fill((parseFloat(oldValue) + 0.01).toFixed(2));
57 await scoreInput.blur();
58
59 // A save notification should appear
60 const saveAlert = page.locator("#save-alert");
61 await expect(saveAlert).toBeVisible();
62
63 // Save changes
64 await saveAlert.getByRole("button", {exact: true, name: "Save"}).click();
65
66 // A success alert should appear (wait for any alert-success)
67 const alertSuccess = page.locator(".alert-success, .alert-modal.alert-success");
68 await expect(alertSuccess).toBeVisible();
69
70 // Revert to the old value (clean up after the test)
71 await expect(alertSuccess).not.toBeVisible({timeout: 10000});
72 const revertedScoreInput = page.locator("#" + scoreInputId);
73 await revertedScoreInput.fill(oldValue);
74 await revertedScoreInput.blur();
75 await saveAlert.getByRole("button", {exact: true, name: "Save"}).click();
76 });
77 });