SPB Git

Repository Public

next-p-db-phones.spec.ts 10.7 KB 112 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Note SPBoucher AI8 * File             : tests/e2e/next-p-db-phones.spec.ts9 * Description      : SP Note Next Generation, Databases Next Generation on10 *                    phones (360 / 375 / 430 px): the 20 000-row database stays11 *                    usable (cards load by pages, the grid is virtualised,12 *                    every view fits), groups collapse, the filter builder13 *                    works from the options sheet, selection + bulk actions and14 *                    row templates have touch-sized controls. No horizontal15 *                    overflow anywhere.16 * Module           : tests17 * Repository       : https://git.spboucher.ai/note-spboucher-ai18 * Project Website  : https://note.spboucher.ai19 * Created          : 2026-11-1920 * Last Modified    : 2026-11-1921 *22 * Author           : Simon-Pierre Boucher23 * Position         : Professor of Finance24 * Institution      : Université du Québec en Outaouais (UQO)25 * Organization     : SP Boucher26 * Website          : https://spboucher.ai27 * Git              : https://git.spboucher.ai28 *29 * Preferred Contact: contact@spboucher.ai30 * Development      : dev@spboucher.ai31 * Support          : support@spboucher.ai32 * Security/Admin   : admin@spboucher.ai33 *34 * Copyright (c) 202635 * Simon-Pierre Boucher36 * All rights reserved where applicable. This file is governed by the37 * applicable project license, copyright notices and relevant law.38 * Existing third-party rights and notices remain unaffected.39 *40 * License          : None specified (no license file in this repository)41 *42 * Do not embed credentials, private keys, access tokens,43 * certificates or confidential personal information.44 *45 * =============================================================================46 * END OF SP BOUCHER SOURCE HEADER47 * =============================================================================48 */4950import { test, expect, type Page } from "@playwright/test";51import fs from "node:fs";52import path from "node:path";53import { execFileSync } from "node:child_process";54import { apiCall, sql, expectNoHorizontalOverflow, removeBench } from "./helpers";5556const DATA = process.env.DATA_DIR ? path.dirname(process.env.DATA_DIR) : "test-results"; const SHOTS = process.env.E2E_SHOTS ?? path.join(DATA, "shots");57const made: string[] = []; let bench: { pageId: string; databaseId: string; views: Record<string, string>; properties: Record<string, string> };58const shot = async (page: Page, name: string, w: number) => { fs.mkdirSync(SHOTS, { recursive: true }); await page.screenshot({ path: path.join(SHOTS, `phone-${w}-${name}.png`) }); };59test.beforeAll(() => { bench = JSON.parse(execFileSync("node", ["node_modules/tsx/dist/cli.mjs", "scripts/db-seed-bench.ts", "20000"], { encoding: "utf8", env: process.env, stdio: ["ignore", "pipe", "pipe"] }).trim().split("\n").pop()!); });60test.afterAll(async () => { await removeBench(bench); if (made.length) { await sql`delete from pages where database_id in (select id from databases where page_id = any(${made}::uuid[]))`; await sql`delete from pages where id = any(${made}::uuid[])`; } });61const tab = async (page: Page, name: string) => { const t = page.getByRole("tab", { name, exact: true }); await t.scrollIntoViewIfNeeded(); if ((await t.getAttribute("aria-selected")) !== "true") await t.click(); await expect(t).toHaveAttribute("aria-selected", "true"); };6263test("20 000 rows on a phone: cards load by pages, every view fits, the grid is virtualised", async ({ page }, t) => {64  const w = t.project.use.viewport!.width; await sql`update database_views set config = config - 'mobileLayout' - 'collapsed' where database_id = ${bench.databaseId}`;65  await page.goto(`/p/${bench.pageId}`); await tab(page, "All rows");66  await expect(page.getByText("20000 rows · 100 loaded")).toBeVisible(); await expect(page.getByRole("button", { name: /^Open / })).toHaveCount(100); await expectNoHorizontalOverflow(page);67  // the next page loads when the end of the list comes into view68  await page.getByTestId("load-more").scrollIntoViewIfNeeded(); await expect(page.getByText(/20000 rows · [2-9]00 loaded/)).toBeVisible(); expect(await page.getByRole("button", { name: /^Open / }).count()).toBeGreaterThanOrEqual(200); await shot(page, "cards-20k", w);69  await page.locator("#main-scroll").evaluate((el) => { el.scrollTop = 0; });70  for (const name of ["Grouped by status", "Board", "Calendar", "Timeline", "Gallery", "List", "Doing, big, by due date"]) {71    await tab(page, name); await page.waitForTimeout(400);72    await test.step(name, async () => { await expectNoHorizontalOverflow(page); await expect(page.locator("main")).not.toContainText(/Could not load|Application error/i); });73  }74  // grouped cards: whole-database counts, a group collapses and stays collapsed75  await tab(page, "Grouped by status"); const [{ n }] = await sql`select count(*)::int as n from database_rows where database_id = ${bench.databaseId} and deleted_at is null and database_rows.values->>${bench.properties.Status} = 'todo'`;76  await expect(page.locator('[data-group-count="todo"]')).toHaveText(String(n)); const collapse = page.getByRole("button", { name: "Collapse group Not started" }); expect((await collapse.boundingBox())!.height).toBeGreaterThanOrEqual(44);77  await collapse.click(); await expect(page.getByRole("button", { name: "Expand group Not started" })).toBeVisible(); await expect(page.getByRole("region", { name: "Not started" }).getByRole("button", { name: /^Open / })).toHaveCount(0); await shot(page, "grouped-collapsed", w);78  await page.getByRole("button", { name: "Expand group Not started" }).click();79  // the real grid: virtualised, scrolls inside itself, the last row is reachable80  await tab(page, "All rows"); await page.getByRole("button", { name: /View options/ }).click(); await page.getByRole("dialog").getByRole("button", { name: /Grid/ }).click(); await page.getByRole("dialog").getByRole("button", { name: "Done", exact: true }).click();81  await expect(page.getByTestId("row-count")).toHaveText("20,000 rows"); expect(await page.locator("[data-row]").count()).toBeLessThan(80); await expectNoHorizontalOverflow(page);82  await page.locator(".db-scroll").evaluate((el) => { el.scrollTop = el.scrollHeight; }); await expect(page.locator('[data-index="19999"]')).toBeVisible(); await expectNoHorizontalOverflow(page); await shot(page, "grid-20k", w);83  await sql`update database_views set config = config - 'mobileLayout' where database_id = ${bench.databaseId}`;84});8586test("phone: filter builder in the options sheet, selection and bulk actions in the grid, row templates — touch-sized, nothing overflows", async ({ page }, t) => {87  const w = t.project.use.viewport!.width; await page.goto("/");88  const c = await apiCall(page, "POST", "/api/pages", { title: `E2E-pdb phone ${w} ${Date.now().toString(36)}`, type: "database", section: "databases" }); expect(c.status).toBe(201); made.push(c.body.id);89  const d = (await apiCall(page, "GET", `/api/databases/${c.body.id}`)).body; const st = (await apiCall(page, "POST", `/api/databases/${d.id}/properties`, { name: "Status", type: "status" })).body; const qty = (await apiCall(page, "POST", `/api/databases/${d.id}/properties`, { name: "Qty", type: "number" })).body;90  const rows = (await apiCall(page, "POST", `/api/databases/${d.id}/rows`, { rows: Array.from({ length: 12 }, (_, i) => ({ title: `phone row ${i + 1} ${i % 2 ? "even" : "odd"}`, values: { [st.id]: i % 3 ? "doing" : "todo", [qty.id]: i } })) })).body;91  expect((await apiCall(page, "POST", `/api/databases/${d.id}/row-templates`, { name: "Preset", fromRowId: rows[1].id })).status).toBe(201);92  await page.goto(`/p/${c.body.id}`); await expect(page.getByText("12 rows")).toBeVisible();93  // filter from the sheet: debounced, saved with the view94  await page.getByRole("button", { name: /View options/ }).click(); const sheet = page.getByRole("dialog"); const fb = sheet.getByTestId("filter-builder");95  await fb.getByRole("button", { name: "Add filter" }).click(); expect((await fb.getByLabel("Value").boundingBox())!.height).toBeGreaterThanOrEqual(44); await fb.getByLabel("Value").fill("even");96  await expect.poll(async () => (await sql`select config from database_views where database_id = ${d.id}`)[0].config.filter).toEqual({ and: [{ property: d.properties[0].id, op: "contains", value: "even" }] });97  await fb.getByRole("button", { name: "Add group" }).click(); await expect(fb.locator('[data-depth="1"]')).toBeVisible(); await expectNoHorizontalOverflow(page); await shot(page, "filter-sheet", w);98  await fb.locator('[data-depth="1"]').getByRole("button", { name: "Remove group" }).click();99  // grid layout: selection + bulk bar100  await sheet.getByRole("button", { name: /Grid/ }).click(); await sheet.getByRole("button", { name: "Done", exact: true }).click(); await expect(page.getByTestId("row-count")).toHaveText("6 rows");101  await page.getByRole("checkbox", { name: "Select all 6 rows" }).check(); const bar = page.getByRole("toolbar", { name: "Selected rows" }); await expect(bar.getByRole("status")).toHaveText("6 selected");102  for (const name of ["Edit property", "Duplicate", "Delete"]) expect((await bar.getByRole("button", { name }).boundingBox())!.height, name).toBeGreaterThanOrEqual(44);103  await expectNoHorizontalOverflow(page); await shot(page, "bulk-bar", w);104  await bar.getByRole("button", { name: "Edit property" }).click(); const ed = page.getByRole("dialog"); await ed.getByLabel("Property to edit").selectOption({ label: "Qty" }); await ed.getByTestId("bulk-value").locator("input").fill("77"); await ed.getByRole("button", { name: "Apply to 6" }).click();105  await expect.poll(async () => (await sql`select count(*)::int as n from database_rows where database_id = ${d.id} and database_rows.values->>${qty.id} = '77'`)[0].n).toBe(6);106  await page.getByRole("button", { name: /^Undo/ }).first().click(); await expect.poll(async () => (await sql`select count(*)::int as n from database_rows where database_id = ${d.id} and database_rows.values->>${qty.id} = '77'`)[0].n).toBe(0);107  // New ▾: the template menu is reachable and creates a row with the preset values108  const more = page.getByRole("button", { name: "New row from a template" }); expect((await more.boundingBox())!.height).toBeGreaterThanOrEqual(44); await more.click(); await page.getByRole("menuitem", { name: /Preset/ }).click();109  await expect(page.getByRole("dialog").getByLabel("Title")).toBeVisible(); await expectNoHorizontalOverflow(page);110  await expect.poll(async () => (await sql`select count(*)::int as n from database_rows where database_id = ${d.id} and deleted_at is null`)[0].n).toBe(13);111});112
Files main
Menu

Theme