e5424cbf7b
新增自绘标题栏、窗口控制和项目标题同步 将泥点账户入口接入标题栏并调整面板描边 收紧本地图片导入类型约束并同步契约文档 补充窗口外壳与泥点面板测试
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { WindowChrome } from '../src/components/WindowChrome';
|
|
import { useWindowChrome } from '../src/components/windowChromeContext';
|
|
|
|
function TitleSetter({ value }: { value: string }) {
|
|
const { setTitle } = useWindowChrome();
|
|
return (
|
|
<button type="button" onClick={() => setTitle(value)}>
|
|
更新标题
|
|
</button>
|
|
);
|
|
}
|
|
|
|
describe('WindowChrome', () => {
|
|
it('renders the陶泥儿 brand, default title, and controls', async () => {
|
|
const user = userEvent.setup();
|
|
render(
|
|
<WindowChrome>
|
|
<div>工作区内容</div>
|
|
</WindowChrome>,
|
|
);
|
|
|
|
expect(screen.getByRole('banner', { name: '窗口标题栏' })).toBeTruthy();
|
|
expect(screen.getByLabelText('陶泥儿 GameAgent')).toBeTruthy();
|
|
expect(screen.queryByLabelText('本地工作区')).toBeNull();
|
|
expect(screen.getByText('创作工作台')).toBeTruthy();
|
|
expect(screen.getByText('工作区内容')).toBeTruthy();
|
|
expect(screen.queryByRole('menubar')).toBeNull();
|
|
|
|
await user.click(screen.getByRole('button', { name: '最小化' }));
|
|
await user.click(screen.getByRole('button', { name: '最大化' }));
|
|
await user.click(screen.getByRole('button', { name: '关闭' }));
|
|
});
|
|
|
|
it('updates the centered title through the shell context', async () => {
|
|
const user = userEvent.setup();
|
|
render(
|
|
<WindowChrome>
|
|
<TitleSetter value="星尘花园" />
|
|
</WindowChrome>,
|
|
);
|
|
|
|
await user.click(screen.getByRole('button', { name: '更新标题' }));
|
|
|
|
expect(screen.getByText('星尘花园')).toBeTruthy();
|
|
expect(screen.getByLabelText('当前工作区:星尘花园')).toBeTruthy();
|
|
});
|
|
|
|
it('restores the default title when a page clears its title', async () => {
|
|
const user = userEvent.setup();
|
|
function ClearTitle() {
|
|
const { setTitle } = useWindowChrome();
|
|
return (
|
|
<button type="button" onClick={() => setTitle(' ')}>
|
|
清空标题
|
|
</button>
|
|
);
|
|
}
|
|
render(
|
|
<WindowChrome>
|
|
<ClearTitle />
|
|
</WindowChrome>,
|
|
);
|
|
|
|
await user.click(screen.getByRole('button', { name: '清空标题' }));
|
|
|
|
expect(screen.getByText('创作工作台')).toBeTruthy();
|
|
});
|
|
|
|
it('closes no menus because the title bar has no application menu bar', () => {
|
|
render(
|
|
<WindowChrome>
|
|
<button type="button">页面按钮</button>
|
|
</WindowChrome>,
|
|
);
|
|
|
|
fireEvent.pointerDown(screen.getByRole('button', { name: '页面按钮' }));
|
|
expect(screen.queryByRole('menu')).toBeNull();
|
|
});
|
|
});
|