Skip to content

Commit 645886b

Browse files
committed
test(ai): cover AI menu item sizing
The AI menu had no coverage that could catch this: the one AI screenshot (`ai_menu_scroll_position`) is a `document.body` shot on an 800x400 viewport where the menu is clipped just below the first item, which is why #2909 only needed to update the *slash* menu baselines. Screenshots the AI menu in its prompt and error states. Without the fix the menu is 88px taller, so both fail on all three browsers before pixels are even compared: "Expected image dimensions to be 623x200px, but received 623x288px".
1 parent 7575f08 commit 645886b

7 files changed

Lines changed: 42 additions & 0 deletions
25.7 KB
Loading
25.6 KB
Loading
25.6 KB
Loading
34.7 KB
Loading
35.8 KB
Loading
35.9 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import App from "@examples/09-ai/01-minimal/src/App";
2+
import { beforeEach, describe, test } from "vite-plus/test";
3+
import { render } from "vitest-browser-react";
4+
import { userEvent } from "../../utils/context.js";
5+
import {
6+
EDITOR_SELECTOR,
7+
PARAGRAPH_SELECTOR,
8+
SLASH_MENU_SELECTOR,
9+
} from "../../utils/const.js";
10+
import { expectElement, sleep, waitForSelector } from "../../utils/editor.js";
11+
12+
beforeEach(async () => {
13+
await render(<App />);
14+
await waitForSelector(EDITOR_SELECTOR);
15+
});
16+
17+
describe("AI menu appearance", () => {
18+
// Every AI menu item is `size: "small"`. A `min-height` meant for full-size
19+
// items used to clamp them to the full row height, stretching the whole menu
20+
// (#2909) - these baselines are what catches that.
21+
test("renders compact items while prompting and after an error", async () => {
22+
// Work from the first block, so the menu opens near the top of the tester
23+
// iframe rather than below its fold.
24+
await userEvent.click(
25+
await waitForSelector(`${EDITOR_SELECTOR} ${PARAGRAPH_SELECTOR}`),
26+
);
27+
await userEvent.keyboard("{End}/");
28+
await waitForSelector(SLASH_MENU_SELECTOR);
29+
await userEvent.keyboard("ai{Enter}");
30+
31+
const aiMenu = await waitForSelector(".bn-combobox");
32+
await sleep(500); // The menu's open transition.
33+
await expectElement(aiMenu).toMatchScreenshot("ai-menu-prompt-items");
34+
35+
// The example points at a local AI backend that isn't running in the test
36+
// container, so any prompt fails into the error state (Retry / Cancel).
37+
await userEvent.keyboard("Write a poem{Enter}");
38+
await waitForSelector(".bn-combobox-error", { timeout: 15000 });
39+
await sleep(500);
40+
await expectElement(aiMenu).toMatchScreenshot("ai-menu-error-items");
41+
});
42+
});

0 commit comments

Comments
 (0)