open-design/apps/web/tests/components/HandoffButton.test.tsx
chaoxiaoche fce444bcab
Consolidate chat comments preview on main (#2906)
* feat(web): queue chat sends

* feat(web): render code comment directives

* feat(web): add preview comments and manual edits

* fix(web): polish shared chrome controls

* fix(web): align queued send loading state

* feat(web): open primary project artifacts

* fix(web): keep queued sends and tests aligned

* fix(web): restore docked comment tools layout

* fix(web): align preview comment toolbar

* fix(web): place local cli beside handoff

* fix(web): move agent menu beside handoff

* fix(web): make project instructions a direct header action

* fix(web): compact handoff and toolbar labels

* fix(web): clarify handoff menu and annotation label

* fix(web): restore compact cursor handoff trigger

* fix(web): align agent menu trigger with handoff

* fix(web): add draw toolbar close action

* fix(web): move inspect editing into edit mode

* fix(web): avoid reserving comment sidebar in annotation mode

* fix(web): float preview comments panel

* fix(web): keep edit canvas full width

* fix(web): polish preview annotation tools

* fix(web): highlight active preview comments

* fix(web): open comments panel after annotation save

* fix(web): polish comment handoff controls

* fix(web): remove palette preview tool

* fix(web): simplify draw annotation toolbar

* fix(web): restore queued tasks into composer

* fix(web): restore queued send strip styling

* fix(web): hide internal comment target ids

* fix(web): align manual edit panel header

* test(web): cover visual interaction contracts

* fix(web): address PR feedback regressions

* fix(web): preserve artifact chrome state

* fix(daemon): restore project raw file routes

---------

Co-authored-by: chaoxiaoche <chaoxiaoche@chaoxiaochedeMacBook-Pro.local>
Co-authored-by: mrcfps <mrc@powerformer.com>
2026-05-26 10:31:19 +00:00

74 lines
2.5 KiB
TypeScript

// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import type { HostEditor, HostEditorsResponse } from '@open-design/contracts';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { HandoffButton } from '../../src/components/HandoffButton';
import { I18nProvider, type Locale } from '../../src/i18n';
import { readExpandedIndexCss } from '../helpers/read-expanded-css';
afterEach(() => {
cleanup();
vi.restoreAllMocks();
window.localStorage.clear();
});
function stubEditors(editors: HostEditor[], platform: HostEditorsResponse['platform'] = 'darwin') {
vi.stubGlobal('fetch', vi.fn<typeof fetch>(async (input) => {
if (String(input) === '/api/editors') {
return new Response(JSON.stringify({ editors, platform }), {
status: 200,
headers: { 'content-type': 'application/json' },
});
}
throw new Error(`unexpected fetch ${String(input)}`);
}));
}
function renderLocalized(locale: Locale) {
render(
<I18nProvider initial={locale}>
<HandoffButton projectId="project-1" />
</I18nProvider>,
);
}
describe('HandoffButton i18n', () => {
it('keeps the header trigger as an icon-sized split control', () => {
const css = readExpandedIndexCss();
expect(css).toContain('.app .handoff-split');
expect(css).toContain('border: 1px solid transparent;');
expect(css).toContain('.app .handoff-trigger');
expect(css).toContain('width: 32px;');
expect(css).toContain('height: 30px;');
expect(css).toContain('.app .handoff-caret');
expect(css).toContain('width: 24px;');
});
it('localizes the primary handoff label', async () => {
stubEditors([{ id: 'finder', label: 'Finder', available: true }]);
renderLocalized('en');
const trigger = await screen.findByTestId('handoff-trigger');
expect(trigger.getAttribute('title')).toBe('Open in Finder');
expect(trigger.querySelector('.handoff-trigger-label')?.classList.contains('sr-only')).toBe(true);
});
it('localizes the unavailable editor section', async () => {
stubEditors([
{ id: 'finder', label: 'Finder', available: true },
{ id: 'cursor', label: 'Cursor', available: false },
]);
renderLocalized('zh-CN');
fireEvent.click(await screen.findByTestId('handoff-caret'));
expect(await screen.findByText('未安装')).toBeTruthy();
expect(screen.getByTestId('handoff-menu-item-cursor').getAttribute('title'))
.toBe('Cursor - 未在 $PATH 中检测到');
});
});