Merge welcome dismissal while preserving continuous conversation entry

This commit is contained in:
鲨鱼辣椒
2026-09-28 18:06:52 +08:00
5 changed files with 161 additions and 2 deletions

View File

@@ -468,6 +468,73 @@ describe('teacher presence and periodic guidance', () => {
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
});
it('consumes the static greeting when consultation opens through the avatar and remembers it for the project', async () => {
const greeting = '有什么编程问题想一起讨论?';
api.config.mockResolvedValue({ enabled: true, definition: { ...definition, welcome_message: greeting } });
const view = await mount();
expect(screen.getByTestId('teacher-invitation')).toHaveAttribute('data-bubble-kind', 'welcome');
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
expect(within(screen.getByTestId('teacher-chat-panel')).getByText(greeting)).toBeVisible();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
expect(screen.queryByTestId('teacher-chat-panel')).not.toBeInTheDocument();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
expect(screen.getByTestId('teacher-chat-panel')).toBeVisible();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
view.unmount();
const next = await mount();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
await act(async () => next.rerender(<Harness projectId="other" />));
expect(screen.getByTestId('teacher-invitation')).toHaveAttribute('data-bubble-kind', 'welcome');
expect(api.create).not.toHaveBeenCalled();
expect(api.send).not.toHaveBeenCalled();
expect(api.checkIn).not.toHaveBeenCalled();
});
it.each([false, true])('consumes the static greeting when consultation opens before config loads (closed before load: %s)', async (closeBeforeLoad) => {
const config = { enabled: true, definition: { ...definition, welcome_message: '欢迎一起创作' } };
let resolve!: (value: typeof config) => void;
api.config.mockImplementationOnce(() => new Promise<typeof config>((done) => { resolve = done; }));
api.config.mockResolvedValue(config);
const view = await mount();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
if (closeBeforeLoad) {
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
}
await act(async () => resolve(config));
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
if (!closeBeforeLoad) {
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
}
expect(screen.queryByTestId('teacher-chat-panel')).not.toBeInTheDocument();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
view.unmount();
await mount();
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
expect(api.create).not.toHaveBeenCalled();
expect(api.send).not.toHaveBeenCalled();
expect(api.checkIn).not.toHaveBeenCalled();
});
it('consumes only the static greeting on avatar entry and leaves a real unread check-in until explicitly viewed', async () => {
api.config.mockResolvedValue({ enabled: true, definition: { ...definition, welcome_message: '欢迎一起创作' } });
api.list.mockResolvedValue({ items: [{ id: 'topic-project' }], lastSelectedTopicId: 'topic-project' });
api.read.mockResolvedValue(checkInTopic());
await mount();
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
expect(screen.getByTestId('teacher-invitation')).toHaveAttribute('data-bubble-kind', 'check-in');
expect(screen.getByTestId('teacher-invitation')).toHaveTextContent('排行榜');
await act(async () => fireEvent.click(screen.getByRole('button', { name: '看看智能体说的' })));
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
await act(async () => fireEvent.click(screen.getByRole('button', { name: '智能体', exact: true })));
expect(screen.queryByTestId('teacher-invitation')).not.toBeInTheDocument();
expect(api.create).not.toHaveBeenCalled();
expect(api.send).not.toHaveBeenCalled();
expect(api.checkIn).not.toHaveBeenCalled();
});
it('keeps the elapsed interval when the Renderer reloads instead of starting another five-minute wait', async () => {
const first = await mount();
await advance(4 * 60_000);