Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
- name: Run Playwright tests
run: |
chmod +x "${{ runner.temp }}/sqlpage-bin/sqlpage"
SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test
AXE_FIXTURES=1 SQLPAGE_BINARY="${{ runner.temp }}/sqlpage-bin/sqlpage" npx playwright test
- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
Expand Down
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ reference material in the official documentation site. Do not duplicate it here.

## Changes and validation

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

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## unreleased

- Standard alert descriptions have higher text contrast.
- 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))
- 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))
- The `table` component can fetch and display HTML fragments in selected columns using `embed`.
Expand All @@ -15,6 +16,7 @@
- Disabled buttons expose their state to assistive technology and cannot be activated.
- Tracking blocks without links now expose their titles to screen readers.
- The `shell` sidebar now uses `navbar_title` and preserves the colors of the supplied logo in dark mode.
- Keyboard users no longer encounter empty home links in the `shell` navigation. Logo-only home links have an accessible name.
- 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.
- Map marker popups follow the surrounding theme so their titles and links stay readable. Map attribution links are underlined.
- 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.
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ template properties.
Run `npx playwright test --grep @accessibility` from `tests/end-to-end` to audit
the official site's component documentation and its live examples in SQLPage's
stock light and dark themes with axe-core. The normal Playwright suite also runs it.
CI also audits each browser fixture's initial page once. Run that project locally
with `AXE_FIXTURES=1 npx playwright test --project=fixture-accessibility`.

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
('theme', 'Set to "dark" to use a dark theme.', 'TEXT', TRUE, TRUE),
('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),
('preview_image', 'The URL of an image to display as a link preview when the page is shared on social media', 'URL', TRUE, TRUE),
('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),
('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),
('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),
('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)
) x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ VALUES (
(
'alert',
'color',
'The color theme for the alert message.',
'The color theme for the alert message. The default is `info`.',
'COLOR',
TRUE,
TRUE
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/sqlpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
--tblr-navbar-color: rgba(var(--tblr-body-color-rgb), 0.8);
}

.alert-description {
color: var(--tblr-body-color);
}

[data-bs-theme="dark"] .alert:not(.alert-important) {
/* See https://github.com/tabler/tabler/issues/1607 */
background-color: var(--tblr-bg-surface);
Expand Down
14 changes: 10 additions & 4 deletions sqlpage/templates/shell.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@
<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'}}">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand d-inline ps-2 text-truncate" href="{{#if link}}{{link}}{{else}}/{{/if}}">
{{#if (any image icon (default navbar_title title))}}
<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}}>
{{#if image}}
<img src="{{image}}" alt="{{#unless (default navbar_title title)}}{{default title 'Home'}}{{/unless}}" height="32" class="navbar-brand-image">
<img src="{{image}}" alt="" height="32" class="navbar-brand-image">
{{/if}}
{{#if icon}}
{{~icon_img icon~}}
{{/if}}
<span class="pe-2 pe-lg-0 align-middle">{{default navbar_title title}}</span>
</a>
{{/if}}
<div class="navbar-collapse collapse" id="sidebar-menu">
{{> menu-items menu_item=menu_item}}
</div>
Expand All @@ -191,16 +193,20 @@
{{else}}
<nav class="navbar navbar-expand-md navbar-light{{#if fixed_top_menu}} fixed-top{{/if}}">
<div class="container-fluid gap-2 justify-content-start" style="min-width:0">
<a class="navbar-brand" href="{{#if link}}{{link}}{{else}}/{{/if}}">
{{#if (any image icon)}}
<a class="navbar-brand" href="{{#if link}}{{link}}{{else}}/{{/if}}" aria-label="{{#if title}}{{title}}{{else}}Home{{/if}}">
{{#if image}}
<img src="{{image}}" alt="{{title}}" width="32" height="32" class="navbar-brand-image">
<img src="{{image}}" alt="" width="32" height="32" class="navbar-brand-image">
{{/if}}
{{#if icon}}
{{~icon_img icon~}}
{{/if}}
</a>
{{/if}}
<span class="mb-0 fs-2 text-truncate flex-grow-1" style="flex-basis:0">
{{#if (default navbar_title title)}}
<a class="text-decoration-none text-body" href="{{#if link}}{{link}}{{else}}/{{/if}}">{{default navbar_title title}}</a>
{{/if}}
</span>
{{#if (or menu_item search_target)}}
<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'}}">
Expand Down
7 changes: 7 additions & 0 deletions tests/end-to-end/accessibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const wcagTags = [
"wcag2a",
"wcag2aa",
"wcag21a",
"wcag21aa",
"wcag22aa",
];
188 changes: 54 additions & 134 deletions tests/end-to-end/component-assertions.ts
Original file line number Diff line number Diff line change
@@ -1,112 +1,50 @@
import { expect, type Locator, type Page } from "@playwright/test";
import { expect, type Page } from "@playwright/test";

// Shared assertions keep documentation page smokes and component fragments aligned.
export async function checkToastNotifications(page: Page) {
const automatic = page.locator("#toast-auto");
await expect(automatic).toBeVisible();
await expect(automatic).toHaveAttribute("data-bs-delay", "5000");
await expect(automatic).toHaveAttribute("data-bs-autohide", "true");
await expect(
automatic.getByRole("button", { name: "Close notification" }),
).toBeVisible();
await expect(page.locator(".toast.show")).toHaveCount(1);
const automaticHandle = await automatic.elementHandle();
await automatic.getByRole("button", { name: "Close notification" }).click();
await expect(automatic).toBeHidden();
await expect(page.locator("main")).toBeFocused();

const stackOne = page.locator("#toast-stack-one");
const stackTwo = page.locator("#toast-stack-two");
await expect(stackOne).toBeHidden();
await page.evaluate(() => {
document.addEventListener("shown.bs.toast", (event) => {
const toast = event.target;
if (!(toast instanceof HTMLElement)) throw new Error("Missing toast");
toast.dataset.shownCount = String(
Number(toast.dataset.shownCount ?? 0) + 1,
);
});
});
await page.getByRole("button", { name: "Show queued notifications" }).click();
await expect(stackOne).toBeVisible();
await expect(stackTwo).toBeVisible();
await expect(stackOne).toHaveAttribute("data-shown-count", "1");
await expect(stackTwo).toHaveAttribute("data-shown-count", "1");
await expect(page.locator("#toast-short")).toHaveAttribute(
"data-shown-count",
"1",
);
await page.evaluate(() =>
document.dispatchEvent(new CustomEvent("fragment-loaded")),
);
await page.waitForTimeout(250);
await expect(page.locator("#toast-short")).toHaveAttribute(
"data-shown-count",
"1",
);
expect(decodeURIComponent(new URL(page.url()).hash)).toBe(
"#queued notifications",
);
const stackContainer = stackOne.locator("xpath=..");
await expect(stackContainer).toHaveAttribute(
"data-sqlpage-toast-position",
"top-end",
);
await expect(stackContainer).toHaveClass(/\bmh-100\b/);
await expect(stackContainer).toHaveClass(/\boverflow-auto\b/);
expect(
await stackContainer.evaluate(
(container) => container.parentElement === document.body,
),
).toBe(true);
expect(
await stackTwo
.locator("xpath=..")
.getAttribute("data-sqlpage-toast-position"),
).toBe("top-end");
const firstBox = await stackOne.boundingBox();
const secondBox = await stackTwo.boundingBox();
expect(firstBox).not.toBeNull();
expect(secondBox).not.toBeNull();
expect(secondBox?.y).toBeGreaterThanOrEqual(
(firstBox?.y ?? 0) + (firstBox?.height ?? 0),
const [firstBox, secondBox] = await Promise.all([
stackOne.boundingBox(),
stackTwo.boundingBox(),
]);
if (!firstBox || !secondBox) throw new Error("Missing queued notifications");
expect(secondBox.y).toBeGreaterThanOrEqual(firstBox.y + firstBox.height);
expect(secondBox.x + secondBox.width).toBeCloseTo(
firstBox.x + firstBox.width,
);

const temporary = page.locator("#toast-short");
await expect(temporary).toHaveAttribute("data-bs-delay", "2000");
await expect(temporary).toBeVisible();
await expect(temporary).toBeHidden({ timeout: 5000 });
await expect(stackOne).toBeVisible();
await expect(automatic).toBeHidden({ timeout: 7000 });
expect(
await automaticHandle?.evaluate((element) => element.isConnected),
).toBe(false);
await page.evaluate(() =>
document.dispatchEvent(new CustomEvent("fragment-loaded")),
);
await expect(temporary).toBeHidden();
await expect(automatic).toBeHidden();

const dismissible = page.locator("#toast-dismissible");
await expect(dismissible).toHaveAttribute("data-bs-delay", "0");
await expect(dismissible).toHaveAttribute("data-bs-autohide", "false");
await page.getByRole("button", { name: "Show dismissible error" }).click();
const closeButton = dismissible.getByRole("button", {
name: "Close notification",
});
await expect(closeButton).toBeVisible();
const closeStyle = await closeButton.evaluate((button) => {
const style = getComputedStyle(button);
const toast = button.closest(".toast");
if (!toast) throw new Error("Missing toast");
const toastStyle = getComputedStyle(toast);
return {
backgroundColor: style.backgroundColor,
color: style.color,
filter: style.filter,
maskImage: style.maskImage,
toastColor: toastStyle.color,
};
});
expect(closeStyle.filter).toBe("none");
expect(closeStyle.maskImage).not.toBe("none");
expect(closeStyle.color).toBe(closeStyle.toastColor);
expect(closeStyle.backgroundColor).toBe(closeStyle.toastColor);
await expect(closeButton).toHaveCSS(
"background-color",
await dismissible.evaluate((toast) => getComputedStyle(toast).color),
);
await page.evaluate(() => {
window.history.replaceState({ toastTest: true }, "", window.location.href);
});
Expand Down Expand Up @@ -146,41 +84,14 @@ export async function checkToastNotifications(page: Page) {
await expect(page.locator("#toast-plain")).toContainText(
"<strong>Plain text stays escaped</strong>",
);
const whiteToast = page.locator("#toast-plain");
const whiteToastStyle = await whiteToast
.locator(".btn-close")
.evaluate((close) => {
const toast = close.closest(".toast");
if (!toast) throw new Error("Missing toast");
const style = getComputedStyle(toast);
const closeStyle = getComputedStyle(close);
const rgba = (color: string) => {
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
if (!context) throw new Error("Canvas 2D context is unavailable");
context.fillStyle = color;
context.fillRect(0, 0, 1, 1);
return Array.from(context.getImageData(0, 0, 1, 1).data);
};
return {
backgroundColor: rgba(style.backgroundColor),
closeColor: rgba(closeStyle.backgroundColor),
color: rgba(style.color),
themeDark: rgba(style.getPropertyValue("--tblr-dark")),
};
});
expect(whiteToastStyle.backgroundColor).toEqual([255, 255, 255, 255]);
expect(whiteToastStyle.color).toEqual(whiteToastStyle.themeDark);
expect(whiteToastStyle.closeColor).toEqual(whiteToastStyle.color);

const bottomContainer = page.locator(
'[data-sqlpage-toast-position="bottom-center"]',
);
await page.getByRole("button", { name: "Show bottom notification" }).click();
await expect(page.locator("#toast-bottom-center")).toBeVisible();
await expect(bottomContainer).toHaveClass(/\bbottom-0\b/);
await expect(bottomContainer).toHaveClass(/\bstart-50\b/);
await expect(bottomContainer).toHaveClass(/\btranslate-middle-x\b/);
const bottom = page.locator("#toast-bottom-center");
await expect(bottom).toBeVisible();
const box = await bottom.boundingBox();
const viewport = page.viewportSize();
if (!box || !viewport) throw new Error("Missing bottom notification");
expect(box.x + box.width / 2).toBeCloseTo(viewport.width / 2);
expect(box.y).toBeGreaterThan(viewport.height / 2);
}

export async function checkTableFiltering(page: Page, fragment = false) {
Expand All @@ -192,49 +103,58 @@ export async function checkTableFiltering(page: Page, fragment = false) {
await tableSection
.locator(".card-body")
.dispatchEvent("fragment-loaded", { bubbles: true });
await expect(page.locator('[data-pre-init="table"]')).not.toHaveCount(0);
const otherTable = page.getByRole("table").filter({
has: page.getByRole("button", { name: "id", exact: true }),
});
await otherTable.getByRole("button", { name: "id", exact: true }).click();
await expect(otherTable.getByRole("cell").first()).toHaveText("31456");
}
const searchInput = tableSection.getByPlaceholder("Search…");
await searchInput.fill("chart");
const chartCell = tableSection.getByRole("cell", { name: "Chart" });
await expect(chartCell).toBeVisible();
await expect(chartCell).toHaveClass(/\b_col_name\b/);
await expect(chartCell).toHaveCSS("vertical-align", "middle");
await expect(
tableSection.getByRole("cell", { name: "Table" }),
).not.toBeVisible();
}

const numbersInColumn = async (table: Locator, cells: string) => {
const texts = await table.locator(cells).allInnerTexts();
expect(texts.length).toBeGreaterThan(1);
return texts.map((text) => Number.parseInt(text.replace(/[^0-9]/g, ""), 10));
};

const ascending = (values: number[]) => [...values].sort((a, b) => a - b);

export async function checkTableSort(
page: Page,
column: "id" | "Amount in stock",
column: string,
reverse = false,
) {
const table = page.locator(".table-responsive", {
const table = page.getByRole("table").filter({
has: page.getByRole("cell", { name: "31456" }),
});
await table.getByRole("button", { name: column }).click();
if (reverse) await table.getByRole("button", { name: column }).click();
const values = await numbersInColumn(
table,
column === "id" ? "td._col_id" : "td._col_Amount_in_stock",
const sort = table.getByRole("button", { name: column, exact: true });
const columns = await table.getByRole("columnheader").allTextContents();
const index = columns.findIndex((name) => name.trim() === column);
expect(index).toBeGreaterThanOrEqual(0);
await sort.click();
if (reverse) await sort.click();
const rows = await table
.getByRole("row")
.filter({ has: page.getByRole("cell") })
.all();
const values = await Promise.all(
rows.map(async (row) =>
Number.parseInt(
(
(await row.getByRole("cell").nth(index).textContent()) ?? ""
).replaceAll(",", ""),
10,
),
),
);
expect(values.length).toBeGreaterThan(1);
expect(values.every(Number.isFinite)).toBe(true);
expect(values).toEqual(
reverse ? ascending(values).reverse() : ascending(values),
[...values].sort(reverse ? (a, b) => b - a : (a, b) => a - b),
);
}

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

Expand Down
Loading
Loading