Skip to content

Commit d2766f6

Browse files
authored
Test browser behavior and audit SQL fixtures with axe (#1701)
* Test observable browser behavior and audit SQL fixtures with axe * Omit empty shell home links and use readable fixture colors * Improve contrast for alert descriptions
1 parent 304a377 commit d2766f6

35 files changed

Lines changed: 432 additions & 607 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ jobs:
259259
- name: Run Playwright tests
260260
run: |
261261
chmod +x "${{ runner.temp }}/sqlpage-bin/sqlpage"
262-
SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test
262+
AXE_FIXTURES=1 SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test
263263
- uses: actions/upload-artifact@v7
264264
if: ${{ !cancelled() }}
265265
with:

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ reference material in the official documentation site. Do not duplicate it here.
3232

3333
## Changes and validation
3434

35-
Keep changes scoped to the task, including formatting. Reuse existing tests and
36-
parameterize repeated setup without removing assertions or scenarios. Run the
37-
relevant tests and the formatting/lint checks in CONTRIBUTING.md before stopping.
35+
Keep edits and formatting scoped. Reuse test setup and preserve distinct scenarios.
36+
Test observable behavior through public interfaces. Avoid internal markup and state.
37+
Run the relevant tests and formatting/lint checks in CONTRIBUTING.md.
3838
Report unavailable checks and failures accurately; a test summary followed by a
3939
hung process is a failure.
4040

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## unreleased
44

5+
- Standard alert descriptions have higher text contrast.
56
- An `alert` without `color` uses the info color again, and its `role` attribute no longer starts with a space. ([#1697](https://github.com/sqlpage/SQLPage/issues/1697))
67
- New `create_new_text` and `no_results_text` properties on `select` fields translate the dropdown texts "Add …" and "No results found". The row that creates a new value is now announced by screen readers when it is the active option. ([#1699](https://github.com/sqlpage/SQLPage/issues/1699))
78
- The `table` component can fetch and display HTML fragments in selected columns using `embed`.
@@ -15,6 +16,7 @@
1516
- Disabled buttons expose their state to assistive technology and cannot be activated.
1617
- Tracking blocks without links now expose their titles to screen readers.
1718
- The `shell` sidebar now uses `navbar_title` and preserves the colors of the supplied logo in dark mode.
19+
- Keyboard users no longer encounter empty home links in the `shell` navigation. Logo-only home links have an accessible name.
1820
- Chart export menus, tooltips, and series colors now follow the theme surrounding each chart, including in custom shells. Chart labels on colored marks have a contrasting outline that carries over to SVG downloads.
1921
- Map marker popups follow the surrounding theme so their titles and links stay readable. Map attribution links are underlined.
2022
- Each `login` component’s labels target its own fields. Set `false AS autofocus` to keep the username field from taking focus when the page opens.

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ template properties.
7474
Run `npx playwright test --grep @accessibility` from `tests/end-to-end` to audit
7575
the official site's component documentation and its live examples in SQLPage's
7676
stock light and dark themes with axe-core. The normal Playwright suite also runs it.
77+
CI also audits each browser fixture's initial page once. Run that project locally
78+
with `AXE_FIXTURES=1 npx playwright test --project=fixture-accessibility`.
7779

7880
To show that an issue exists before you fix it, put the reproduction in a fixture and run it against releases with one command, such as `nix run .#reproduce -- repro_721 postgres v0.35.0 v0.36.1 tree`. The second argument is `sqlite` or `postgres`, and `tree` is your working tree. It prints Playwright's output for each version, then a table you can paste into the issue or pull request. Releases run from their Docker images, from v0.29.0 onwards, and Postgres from `docker compose`. Without Nix, run `npm run reproduce --` in `tests/end-to-end` instead.
7981

‎examples/official-site/sqlpage/migrations/01_documentation.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
15491549
('theme', 'Set to "dark" to use a dark theme.', 'TEXT', TRUE, TRUE),
15501550
('footer', 'Muted text to display in the footer of the page. This can be used to display a link to the terms and conditions of your application, for instance. By default, shows "Built with SQLPage". Supports links with markdown.', 'TEXT', TRUE, TRUE),
15511551
('preview_image', 'The URL of an image to display as a link preview when the page is shared on social media', 'URL', TRUE, TRUE),
1552-
('navbar_title', 'The title shown in the navigation bar or sidebar. Defaults to the page title. Set an empty string to show just the logo.', 'TEXT', TRUE, TRUE),
1552+
('navbar_title', 'The title shown in the navigation bar or sidebar. Defaults to the page title. Set an empty string to show just the logo, if configured. With neither a navigation title nor a logo, there is no home link in the navigation bar.', 'TEXT', TRUE, TRUE),
15531553
('target', 'Where the menu items should open: "_blank" for a new tab, "_self" for the same tab, "_parent" for the parent frame, or "_top" for the full body of the window. Set it inside a "menu_item" json object; it has no effect when set directly on the shell.', 'TEXT', TRUE, TRUE),
15541554
('class', 'class attribute added to the page''s html element. It can be used to apply custom styling to the whole page through css.', 'TEXT', TRUE, TRUE)
15551555
) x;

‎examples/official-site/sqlpage/migrations/03_alert_component.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ VALUES (
3232
(
3333
'alert',
3434
'color',
35-
'The color theme for the alert message.',
35+
'The color theme for the alert message. The default is `info`.',
3636
'COLOR',
3737
TRUE,
3838
TRUE

‎frontend/src/sqlpage.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
--tblr-navbar-color: rgba(var(--tblr-body-color-rgb), 0.8);
44
}
55

6+
.alert-description {
7+
color: var(--tblr-body-color);
8+
}
9+
610
[data-bs-theme="dark"] .alert:not(.alert-important) {
711
/* See https://github.com/tabler/tabler/issues/1607 */
812
background-color: var(--tblr-bg-surface);

‎sqlpage/templates/shell.handlebars‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,17 @@
174174
<button class="navbar-toggler collapsed" type="button" data-bs-target="#sidebar-menu" aria-controls="sidebar-menu" data-bs-toggle="collapse" aria-expanded="false" aria-label="{{default navbar_toggle_label 'Toggle navigation'}}">
175175
<span class="navbar-toggler-icon"></span>
176176
</button>
177-
<a class="navbar-brand d-inline ps-2 text-truncate" href="{{#if link}}{{link}}{{else}}/{{/if}}">
177+
{{#if (any image icon (default navbar_title title))}}
178+
<a class="navbar-brand d-inline ps-2 text-truncate" href="{{#if link}}{{link}}{{else}}/{{/if}}"{{#unless (default navbar_title title)}} aria-label="{{#if title}}{{title}}{{else}}Home{{/if}}"{{/unless}}>
178179
{{#if image}}
179-
<img src="{{image}}" alt="{{#unless (default navbar_title title)}}{{default title 'Home'}}{{/unless}}" height="32" class="navbar-brand-image">
180+
<img src="{{image}}" alt="" height="32" class="navbar-brand-image">
180181
{{/if}}
181182
{{#if icon}}
182183
{{~icon_img icon~}}
183184
{{/if}}
184185
<span class="pe-2 pe-lg-0 align-middle">{{default navbar_title title}}</span>
185186
</a>
187+
{{/if}}
186188
<div class="navbar-collapse collapse" id="sidebar-menu">
187189
{{> menu-items menu_item=menu_item}}
188190
</div>
@@ -191,16 +193,20 @@
191193
{{else}}
192194
<nav class="navbar navbar-expand-md navbar-light{{#if fixed_top_menu}} fixed-top{{/if}}">
193195
<div class="container-fluid gap-2 justify-content-start" style="min-width:0">
194-
<a class="navbar-brand" href="{{#if link}}{{link}}{{else}}/{{/if}}">
196+
{{#if (any image icon)}}
197+
<a class="navbar-brand" href="{{#if link}}{{link}}{{else}}/{{/if}}" aria-label="{{#if title}}{{title}}{{else}}Home{{/if}}">
195198
{{#if image}}
196-
<img src="{{image}}" alt="{{title}}" width="32" height="32" class="navbar-brand-image">
199+
<img src="{{image}}" alt="" width="32" height="32" class="navbar-brand-image">
197200
{{/if}}
198201
{{#if icon}}
199202
{{~icon_img icon~}}
200203
{{/if}}
201204
</a>
205+
{{/if}}
202206
<span class="mb-0 fs-2 text-truncate flex-grow-1" style="flex-basis:0">
207+
{{#if (default navbar_title title)}}
203208
<a class="text-decoration-none text-body" href="{{#if link}}{{link}}{{else}}/{{/if}}">{{default navbar_title title}}</a>
209+
{{/if}}
204210
</span>
205211
{{#if (or menu_item search_target)}}
206212
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false" aria-label="{{default navbar_toggle_label 'Toggle navigation'}}">

‎tests/end-to-end/accessibility.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const wcagTags = [
2+
"wcag2a",
3+
"wcag2aa",
4+
"wcag21a",
5+
"wcag21aa",
6+
"wcag22aa",
7+
];

‎tests/end-to-end/component-assertions.ts‎

Lines changed: 54 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,50 @@
1-
import { expect, type Locator, type Page } from "@playwright/test";
1+
import { expect, type Page } from "@playwright/test";
22

3-
// Shared assertions keep documentation page smokes and component fragments aligned.
43
export async function checkToastNotifications(page: Page) {
54
const automatic = page.locator("#toast-auto");
6-
await expect(automatic).toBeVisible();
7-
await expect(automatic).toHaveAttribute("data-bs-delay", "5000");
8-
await expect(automatic).toHaveAttribute("data-bs-autohide", "true");
9-
await expect(
10-
automatic.getByRole("button", { name: "Close notification" }),
11-
).toBeVisible();
12-
await expect(page.locator(".toast.show")).toHaveCount(1);
13-
const automaticHandle = await automatic.elementHandle();
145
await automatic.getByRole("button", { name: "Close notification" }).click();
156
await expect(automatic).toBeHidden();
167
await expect(page.locator("main")).toBeFocused();
178

189
const stackOne = page.locator("#toast-stack-one");
1910
const stackTwo = page.locator("#toast-stack-two");
2011
await expect(stackOne).toBeHidden();
21-
await page.evaluate(() => {
22-
document.addEventListener("shown.bs.toast", (event) => {
23-
const toast = event.target;
24-
if (!(toast instanceof HTMLElement)) throw new Error("Missing toast");
25-
toast.dataset.shownCount = String(
26-
Number(toast.dataset.shownCount ?? 0) + 1,
27-
);
28-
});
29-
});
3012
await page.getByRole("button", { name: "Show queued notifications" }).click();
3113
await expect(stackOne).toBeVisible();
3214
await expect(stackTwo).toBeVisible();
33-
await expect(stackOne).toHaveAttribute("data-shown-count", "1");
34-
await expect(stackTwo).toHaveAttribute("data-shown-count", "1");
35-
await expect(page.locator("#toast-short")).toHaveAttribute(
36-
"data-shown-count",
37-
"1",
38-
);
39-
await page.evaluate(() =>
40-
document.dispatchEvent(new CustomEvent("fragment-loaded")),
41-
);
42-
await page.waitForTimeout(250);
43-
await expect(page.locator("#toast-short")).toHaveAttribute(
44-
"data-shown-count",
45-
"1",
46-
);
4715
expect(decodeURIComponent(new URL(page.url()).hash)).toBe(
4816
"#queued notifications",
4917
);
50-
const stackContainer = stackOne.locator("xpath=..");
51-
await expect(stackContainer).toHaveAttribute(
52-
"data-sqlpage-toast-position",
53-
"top-end",
54-
);
55-
await expect(stackContainer).toHaveClass(/\bmh-100\b/);
56-
await expect(stackContainer).toHaveClass(/\boverflow-auto\b/);
57-
expect(
58-
await stackContainer.evaluate(
59-
(container) => container.parentElement === document.body,
60-
),
61-
).toBe(true);
62-
expect(
63-
await stackTwo
64-
.locator("xpath=..")
65-
.getAttribute("data-sqlpage-toast-position"),
66-
).toBe("top-end");
67-
const firstBox = await stackOne.boundingBox();
68-
const secondBox = await stackTwo.boundingBox();
69-
expect(firstBox).not.toBeNull();
70-
expect(secondBox).not.toBeNull();
71-
expect(secondBox?.y).toBeGreaterThanOrEqual(
72-
(firstBox?.y ?? 0) + (firstBox?.height ?? 0),
18+
const [firstBox, secondBox] = await Promise.all([
19+
stackOne.boundingBox(),
20+
stackTwo.boundingBox(),
21+
]);
22+
if (!firstBox || !secondBox) throw new Error("Missing queued notifications");
23+
expect(secondBox.y).toBeGreaterThanOrEqual(firstBox.y + firstBox.height);
24+
expect(secondBox.x + secondBox.width).toBeCloseTo(
25+
firstBox.x + firstBox.width,
7326
);
7427

7528
const temporary = page.locator("#toast-short");
76-
await expect(temporary).toHaveAttribute("data-bs-delay", "2000");
7729
await expect(temporary).toBeVisible();
7830
await expect(temporary).toBeHidden({ timeout: 5000 });
7931
await expect(stackOne).toBeVisible();
80-
await expect(automatic).toBeHidden({ timeout: 7000 });
81-
expect(
82-
await automaticHandle?.evaluate((element) => element.isConnected),
83-
).toBe(false);
32+
await page.evaluate(() =>
33+
document.dispatchEvent(new CustomEvent("fragment-loaded")),
34+
);
35+
await expect(temporary).toBeHidden();
36+
await expect(automatic).toBeHidden();
8437

8538
const dismissible = page.locator("#toast-dismissible");
86-
await expect(dismissible).toHaveAttribute("data-bs-delay", "0");
87-
await expect(dismissible).toHaveAttribute("data-bs-autohide", "false");
8839
await page.getByRole("button", { name: "Show dismissible error" }).click();
8940
const closeButton = dismissible.getByRole("button", {
9041
name: "Close notification",
9142
});
9243
await expect(closeButton).toBeVisible();
93-
const closeStyle = await closeButton.evaluate((button) => {
94-
const style = getComputedStyle(button);
95-
const toast = button.closest(".toast");
96-
if (!toast) throw new Error("Missing toast");
97-
const toastStyle = getComputedStyle(toast);
98-
return {
99-
backgroundColor: style.backgroundColor,
100-
color: style.color,
101-
filter: style.filter,
102-
maskImage: style.maskImage,
103-
toastColor: toastStyle.color,
104-
};
105-
});
106-
expect(closeStyle.filter).toBe("none");
107-
expect(closeStyle.maskImage).not.toBe("none");
108-
expect(closeStyle.color).toBe(closeStyle.toastColor);
109-
expect(closeStyle.backgroundColor).toBe(closeStyle.toastColor);
44+
await expect(closeButton).toHaveCSS(
45+
"background-color",
46+
await dismissible.evaluate((toast) => getComputedStyle(toast).color),
47+
);
11048
await page.evaluate(() => {
11149
window.history.replaceState({ toastTest: true }, "", window.location.href);
11250
});
@@ -146,41 +84,14 @@ export async function checkToastNotifications(page: Page) {
14684
await expect(page.locator("#toast-plain")).toContainText(
14785
"<strong>Plain text stays escaped</strong>",
14886
);
149-
const whiteToast = page.locator("#toast-plain");
150-
const whiteToastStyle = await whiteToast
151-
.locator(".btn-close")
152-
.evaluate((close) => {
153-
const toast = close.closest(".toast");
154-
if (!toast) throw new Error("Missing toast");
155-
const style = getComputedStyle(toast);
156-
const closeStyle = getComputedStyle(close);
157-
const rgba = (color: string) => {
158-
const canvas = document.createElement("canvas");
159-
const context = canvas.getContext("2d");
160-
if (!context) throw new Error("Canvas 2D context is unavailable");
161-
context.fillStyle = color;
162-
context.fillRect(0, 0, 1, 1);
163-
return Array.from(context.getImageData(0, 0, 1, 1).data);
164-
};
165-
return {
166-
backgroundColor: rgba(style.backgroundColor),
167-
closeColor: rgba(closeStyle.backgroundColor),
168-
color: rgba(style.color),
169-
themeDark: rgba(style.getPropertyValue("--tblr-dark")),
170-
};
171-
});
172-
expect(whiteToastStyle.backgroundColor).toEqual([255, 255, 255, 255]);
173-
expect(whiteToastStyle.color).toEqual(whiteToastStyle.themeDark);
174-
expect(whiteToastStyle.closeColor).toEqual(whiteToastStyle.color);
175-
176-
const bottomContainer = page.locator(
177-
'[data-sqlpage-toast-position="bottom-center"]',
178-
);
17987
await page.getByRole("button", { name: "Show bottom notification" }).click();
180-
await expect(page.locator("#toast-bottom-center")).toBeVisible();
181-
await expect(bottomContainer).toHaveClass(/\bbottom-0\b/);
182-
await expect(bottomContainer).toHaveClass(/\bstart-50\b/);
183-
await expect(bottomContainer).toHaveClass(/\btranslate-middle-x\b/);
88+
const bottom = page.locator("#toast-bottom-center");
89+
await expect(bottom).toBeVisible();
90+
const box = await bottom.boundingBox();
91+
const viewport = page.viewportSize();
92+
if (!box || !viewport) throw new Error("Missing bottom notification");
93+
expect(box.x + box.width / 2).toBeCloseTo(viewport.width / 2);
94+
expect(box.y).toBeGreaterThan(viewport.height / 2);
18495
}
18596

18697
export async function checkTableFiltering(page: Page, fragment = false) {
@@ -192,49 +103,58 @@ export async function checkTableFiltering(page: Page, fragment = false) {
192103
await tableSection
193104
.locator(".card-body")
194105
.dispatchEvent("fragment-loaded", { bubbles: true });
195-
await expect(page.locator('[data-pre-init="table"]')).not.toHaveCount(0);
106+
const otherTable = page.getByRole("table").filter({
107+
has: page.getByRole("button", { name: "id", exact: true }),
108+
});
109+
await otherTable.getByRole("button", { name: "id", exact: true }).click();
110+
await expect(otherTable.getByRole("cell").first()).toHaveText("31456");
196111
}
197112
const searchInput = tableSection.getByPlaceholder("Search…");
198113
await searchInput.fill("chart");
199114
const chartCell = tableSection.getByRole("cell", { name: "Chart" });
200115
await expect(chartCell).toBeVisible();
201-
await expect(chartCell).toHaveClass(/\b_col_name\b/);
202116
await expect(chartCell).toHaveCSS("vertical-align", "middle");
203117
await expect(
204118
tableSection.getByRole("cell", { name: "Table" }),
205119
).not.toBeVisible();
206120
}
207121

208-
const numbersInColumn = async (table: Locator, cells: string) => {
209-
const texts = await table.locator(cells).allInnerTexts();
210-
expect(texts.length).toBeGreaterThan(1);
211-
return texts.map((text) => Number.parseInt(text.replace(/[^0-9]/g, ""), 10));
212-
};
213-
214-
const ascending = (values: number[]) => [...values].sort((a, b) => a - b);
215-
216122
export async function checkTableSort(
217123
page: Page,
218-
column: "id" | "Amount in stock",
124+
column: string,
219125
reverse = false,
220126
) {
221-
const table = page.locator(".table-responsive", {
127+
const table = page.getByRole("table").filter({
222128
has: page.getByRole("cell", { name: "31456" }),
223129
});
224-
await table.getByRole("button", { name: column }).click();
225-
if (reverse) await table.getByRole("button", { name: column }).click();
226-
const values = await numbersInColumn(
227-
table,
228-
column === "id" ? "td._col_id" : "td._col_Amount_in_stock",
130+
const sort = table.getByRole("button", { name: column, exact: true });
131+
const columns = await table.getByRole("columnheader").allTextContents();
132+
const index = columns.findIndex((name) => name.trim() === column);
133+
expect(index).toBeGreaterThanOrEqual(0);
134+
await sort.click();
135+
if (reverse) await sort.click();
136+
const rows = await table
137+
.getByRole("row")
138+
.filter({ has: page.getByRole("cell") })
139+
.all();
140+
const values = await Promise.all(
141+
rows.map(async (row) =>
142+
Number.parseInt(
143+
(
144+
(await row.getByRole("cell").nth(index).textContent()) ?? ""
145+
).replaceAll(",", ""),
146+
10,
147+
),
148+
),
229149
);
150+
expect(values.length).toBeGreaterThan(1);
151+
expect(values.every(Number.isFinite)).toBe(true);
230152
expect(values).toEqual(
231-
reverse ? ascending(values).reverse() : ascending(values),
153+
[...values].sort(reverse ? (a, b) => b - a : (a, b) => a - b),
232154
);
233155
}
234156

235157
export async function checkModal(page: Page) {
236-
await expect(page.locator("body > #my_modal")).toBeAttached();
237-
await expect(page.locator("body > #my_embed_form_modal")).toBeAttached();
238158
const openButton = page.getByRole("button", { name: "Open a simple modal" });
239159
await openButton.click();
240160

0 commit comments

Comments
 (0)