162 lines
6.9 KiB
TypeScript
162 lines
6.9 KiB
TypeScript
// R-P11a interim-UI smoke (AD-28, DoD 19): the tenant-wide search lives only
|
|
// in the Spotlight palette. The readiness user is a real indexed entity, so
|
|
// the smoke covers the protected search resource and recent-search write too.
|
|
|
|
import { expect, type Page, test } from "./utils/test";
|
|
import { getTenantCredentials, loginAsTenantUser } from "./utils/auth";
|
|
import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile";
|
|
import { skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
const credentials = getTenantCredentials();
|
|
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH ?? "/app/dashboard";
|
|
const membersPath = process.env.E2E_TENANT_MEMBERS_PATH ?? "/app/settings/team";
|
|
const searchApiPattern = /\/search\/api(?:\.data)?(?:\?.*)?$/u;
|
|
|
|
type SearchApiObservation = {
|
|
getRequests: URL[];
|
|
postRequests: Array<{ body: string; contentType: string }>;
|
|
};
|
|
|
|
test.describe("global Spotlight search (R-P11a)", () => {
|
|
test.beforeEach(() => {
|
|
skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "Skipping authenticated Spotlight search smoke");
|
|
});
|
|
|
|
test("opens with Ctrl/Cmd+K and the desktop header trigger, then records and opens a result", async ({ page }) => {
|
|
const searchApi = observeSearchApi(page);
|
|
await openDashboard(page);
|
|
|
|
const palette = page.locator('[data-ui-id="ui.surface.commandPalette.portal"]');
|
|
const input = page.locator('[data-ui-id="ui.surface.commandPalette.search"]');
|
|
const desktopTrigger = page.locator('[data-ui-id="ui.action.shell.search"]');
|
|
|
|
await expect(desktopTrigger).toBeVisible();
|
|
for (const shortcut of ["Control+K", "Meta+K"] as const) {
|
|
await page.keyboard.press(shortcut);
|
|
await expect(palette).toBeVisible();
|
|
await expect(input).toBeFocused();
|
|
await page.keyboard.press("Escape");
|
|
await expect(palette).toBeHidden();
|
|
await expect(desktopTrigger).toBeFocused();
|
|
}
|
|
|
|
await desktopTrigger.click();
|
|
await expect(palette).toBeVisible();
|
|
await expect(input).toBeFocused();
|
|
await input.fill("Readiness");
|
|
|
|
await expect.poll(() => searchApi.getRequests.filter((url) => url.searchParams.get("q") === "Readiness").length).toBe(1);
|
|
const result = page.locator(
|
|
'[data-ui-id-pattern="ui.surface.commandPalette.result.{entityType}.{entityId}"][data-ui-id-param-entitytype="user"]'
|
|
);
|
|
await expect(result).toBeVisible();
|
|
await expect(result).toContainText("E2E Readiness");
|
|
await result.click();
|
|
|
|
await expect(page).toHaveURL(urlPattern(membersPath));
|
|
await expect(palette).toBeHidden();
|
|
await expect.poll(() => searchApi.postRequests.length).toBe(1);
|
|
expectPostedField(searchApi.postRequests[0]!, "intent", "recordRecent");
|
|
expectPostedField(searchApi.postRequests[0]!, "query", "Readiness");
|
|
expectPostedField(searchApi.postRequests[0]!, "selectedEntityType", "user");
|
|
expectPostedFieldMatches(searchApi.postRequests[0]!, "selectedEntityId", /\S+/u);
|
|
});
|
|
});
|
|
|
|
test.describe("global Spotlight search mobile (R-P11a)", () => {
|
|
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
|
|
test.beforeEach(() => {
|
|
skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "Skipping authenticated mobile Spotlight search smoke");
|
|
});
|
|
|
|
test("opens from the mobile header as a viewport overlay and navigates to the selected result", async ({ page }) => {
|
|
const searchApi = observeSearchApi(page);
|
|
await openDashboard(page);
|
|
|
|
const desktopTrigger = page.locator('[data-ui-id="ui.action.shell.search"]');
|
|
const mobileTrigger = page.locator('[data-ui-id="ui.action.shell.searchMobile"]');
|
|
const palette = page.locator('[data-ui-id="ui.surface.commandPalette.portal"]');
|
|
const input = page.locator('[data-ui-id="ui.surface.commandPalette.search"]');
|
|
|
|
await expect(desktopTrigger).toBeHidden();
|
|
await expect(mobileTrigger).toBeVisible();
|
|
await mobileTrigger.click();
|
|
await expect(palette).toBeVisible();
|
|
await expect(input).toBeFocused();
|
|
|
|
const viewport = page.viewportSize();
|
|
const overlayBox = await palette.boundingBox();
|
|
expect(viewport).not.toBeNull();
|
|
expect(overlayBox).not.toBeNull();
|
|
expect(Math.abs(overlayBox!.x)).toBeLessThanOrEqual(1);
|
|
expect(Math.abs(overlayBox!.y)).toBeLessThanOrEqual(1);
|
|
expect(overlayBox!.width).toBeGreaterThanOrEqual(viewport!.width - 1);
|
|
expect(overlayBox!.height).toBeGreaterThanOrEqual(viewport!.height - 1);
|
|
await expectNoHorizontalOverflow(page);
|
|
|
|
await input.fill("Readiness");
|
|
await expect.poll(() => searchApi.getRequests.filter((url) => url.searchParams.get("q") === "Readiness").length).toBe(1);
|
|
const result = page.locator(
|
|
'[data-ui-id-pattern="ui.surface.commandPalette.result.{entityType}.{entityId}"][data-ui-id-param-entitytype="user"]'
|
|
);
|
|
await expect(result).toBeVisible();
|
|
await result.click();
|
|
|
|
await expect(page).toHaveURL(urlPattern(membersPath));
|
|
await expect.poll(() => searchApi.postRequests.length).toBe(1);
|
|
expectPostedField(searchApi.postRequests[0]!, "query", "Readiness");
|
|
expectPostedField(searchApi.postRequests[0]!, "selectedEntityType", "user");
|
|
expectPostedFieldMatches(searchApi.postRequests[0]!, "selectedEntityId", /\S+/u);
|
|
await expectNoHorizontalOverflow(page);
|
|
});
|
|
});
|
|
|
|
async function openDashboard(page: Page) {
|
|
await loginAsTenantUser(page, credentials!);
|
|
await page.goto(dashboardPath, { waitUntil: "domcontentloaded" });
|
|
await expect(page).toHaveURL(urlPattern(dashboardPath));
|
|
await expect(page.locator('[data-ui-id="ui.surface.shell.header"]')).toBeVisible();
|
|
}
|
|
|
|
function observeSearchApi(page: Page): SearchApiObservation {
|
|
const state: SearchApiObservation = { getRequests: [], postRequests: [] };
|
|
|
|
page.on("request", (request) => {
|
|
const url = new URL(request.url());
|
|
if (!searchApiPattern.test(url.pathname + url.search)) return;
|
|
|
|
if (request.method() === "POST") {
|
|
state.postRequests.push({
|
|
body: request.postData() ?? "",
|
|
contentType: request.headers()["content-type"] ?? "",
|
|
});
|
|
return;
|
|
}
|
|
|
|
state.getRequests.push(url);
|
|
});
|
|
|
|
return state;
|
|
}
|
|
|
|
function expectPostedField(request: SearchApiObservation["postRequests"][number], name: string, value: string) {
|
|
expectPostedFieldMatches(request, name, new RegExp(`^${escapeRegExp(value)}$`, "u"));
|
|
}
|
|
|
|
function expectPostedFieldMatches(request: SearchApiObservation["postRequests"][number], name: string, valuePattern: RegExp) {
|
|
if (request.contentType.includes("application/x-www-form-urlencoded")) {
|
|
expect(new URLSearchParams(request.body).get(name)).toMatch(valuePattern);
|
|
return;
|
|
}
|
|
const match = request.body.match(new RegExp(`name="${escapeRegExp(name)}"\\r?\\n\\r?\\n([^\\r\\n-]+)`, "u"));
|
|
expect(match?.[1]?.trim()).toMatch(valuePattern);
|
|
}
|
|
|
|
function urlPattern(path: string): RegExp {
|
|
return new RegExp(`${escapeRegExp(path)}(?:[?#].*)?$`, "u");
|
|
}
|
|
|
|
function escapeRegExp(value: string): string {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
}
|