test: cover design text context menu

This commit is contained in:
2026-09-07 17:19:04 +08:00
parent 813d1ca02e
commit 6fbb9c077e
2 changed files with 36 additions and 15 deletions

View File

@@ -19,6 +19,9 @@
with the current window lifecycle.
- Restore the smallest Main-owned native text-editing context-menu behavior and add
focused regression coverage at the real window/event seam.
- Verify that the AI Design `design-chat-composer` textarea shares the same
primary Renderer seam, and extend the Electron regression to cover both Code
and Design textarea controls without adding a duplicate listener.
- Update user-facing documentation or Electron E2E coverage only where current
behavior and the shared fixture require it.
@@ -51,9 +54,15 @@
content still produces no menu.
- Registered the listener once during primary-window creation without adding
Renderer, Preload, IPC, Host API, or direct clipboard access.
- Confirmed `DesignConversationPane` renders the AI Design composer as the
ordinary `<textarea id="design-chat-composer">` produced by the shared
`Textarea` component inside that same primary Renderer. The window-level
listener therefore covers both AI Code and AI Design without a second
production listener.
- Added five focused unit cases and an Electron E2E regression that dispatches
a real right-click inside the primary Renderer window and observes one native
menu popup with the expected editing actions.
real right-clicks on Code and Design textarea controls inside the primary
Renderer window and observes two native menu popups with the expected editing
actions.
- Synchronized `README.md` with the restored desktop behavior and ownership
boundary.
@@ -69,7 +78,8 @@
- Green phase:
- `corepack pnpm exec vitest run tests/unit/context-menu.test.ts` — 5 passed.
- `corepack pnpm exec playwright test tests/e2e/context-menu.spec.ts` — 1
passed.
passed, covering both Code and Design textareas with two observed native
popups.
- `corepack pnpm run typecheck` — passed.
- `corepack pnpm exec eslint electron/main/context-menu.ts electron/main/index.ts tests/unit/context-menu.test.ts tests/e2e/context-menu.spec.ts`
— passed.

View File

@@ -47,29 +47,40 @@ async function readContextMenuProbe(app: ElectronApplication): Promise<ContextMe
}
test.describe('Makelore text context menu', () => {
test('opens native editing actions for editable text', async ({ launchElectronApp }) => {
test('opens native editing actions for Code and Design textareas', async ({ launchElectronApp }) => {
const app = await launchElectronApp({ skipSetup: true });
try {
const page = await getStableWindow(app);
await installContextMenuProbe(app);
await page.evaluate(() => {
const input = document.createElement('input');
input.id = 'context-menu-e2e-input';
input.style.position = 'fixed';
input.style.inset = '80px auto auto 80px';
input.style.zIndex = '2147483647';
const composerIds = [
'context-menu-e2e-code-composer',
'design-chat-composer',
];
document.body.append(input);
for (const [index, id] of composerIds.entries()) {
const textarea = document.createElement('textarea');
textarea.id = id;
textarea.style.position = 'fixed';
textarea.style.inset = `${80 + index * 80}px auto auto 80px`;
textarea.style.zIndex = '2147483647';
document.body.append(textarea);
}
});
const input = page.locator('#context-menu-e2e-input');
await input.fill('Makelore');
await input.selectText();
await input.click({ button: 'right' });
for (const selector of [
'#context-menu-e2e-code-composer',
'#design-chat-composer',
]) {
const textarea = page.locator(selector);
await textarea.fill('Makelore');
await textarea.selectText();
await textarea.click({ button: 'right' });
}
await expect.poll(async () => await readContextMenuProbe(app)).toEqual({
popupCount: 1,
popupCount: 2,
template: [
{ label: '剪切', role: 'cut', type: 'normal' },
{ label: '复制', role: 'copy', type: 'normal' },