feat(chat): show playful teacher introductions on hover
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { TeacherChatPanel } from '@/pages/Chat/TeacherChatPanel';
|
||||
import type { TeacherDefinition, TeacherRequest, TeacherSend, TeacherTopic } from '../../shared/coding-teacher';
|
||||
@@ -96,6 +96,24 @@ async function ready() {
|
||||
await waitFor(() => expect(streams.has('first')).toBe(true));
|
||||
}
|
||||
describe('teacher side chat', () => {
|
||||
it('keeps the panel header focused on identity and puts new topics inside expanded history', async () => {
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" />);
|
||||
const history = await screen.findByRole('button', { name: '以往讨论' });
|
||||
const header = screen.getByTestId('teacher-chat-panel').querySelector('header')!;
|
||||
expect(within(header).getByRole('heading', { name: '智能体' })).toBeVisible();
|
||||
expect(within(header).queryByRole('button')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('服务端简介')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: '智能体新话题' })).not.toBeInTheDocument();
|
||||
fireEvent.click(history);
|
||||
const newTopic = screen.getByRole('button', { name: '智能体新话题' });
|
||||
expect(newTopic).toBeEnabled();
|
||||
expect(newTopic).toHaveTextContent('新话题');
|
||||
expect(header.contains(newTopic)).toBe(false);
|
||||
fireEvent.click(newTopic);
|
||||
await waitFor(() => expect(api.create).toHaveBeenCalledWith('p/agent-topics', undefined, undefined, 1));
|
||||
expect(api.send).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('renders the pinned topic icon in the header and assistant messages', async () => {
|
||||
const icon = 'https://yuxi.example.test/api/storage/public/images/topic.png';
|
||||
api.read.mockResolvedValue({ ...first, definition: { ...definition, icon_url: icon }, requests: [request({ response: '继续原来的讨论' })] });
|
||||
@@ -221,16 +239,15 @@ describe('teacher side chat', () => {
|
||||
expect(screen.getByLabelText('向智能体提问')).toHaveValue('解释代码');
|
||||
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
|
||||
await screen.findByText('教学回答');
|
||||
expect(screen.getByText('服务端简介')).toBeVisible();
|
||||
expect(screen.queryByText('服务端简介')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('较长的上下文已节选,智能体可按需读取原文。')).toBeVisible();
|
||||
expect(api.send.mock.calls[0][2].requestId).toBe(api.send.mock.calls[1][2].requestId);
|
||||
expect(bringBack).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole('button', { name: '带回主会话草稿' }));
|
||||
expect(bringBack).toHaveBeenCalledWith('教学回答');
|
||||
});
|
||||
it('ignores an old topic stream after switching and does not cancel when closed', async () => {
|
||||
const closed = vi.fn();
|
||||
const view = render(<TeacherChatPanel projectId="p" sourceId="c" onClose={closed} />);
|
||||
it('ignores an old topic stream after switching and does not cancel when the panel unmounts', async () => {
|
||||
const view = render(<TeacherChatPanel projectId="p" sourceId="c" />);
|
||||
await ready();
|
||||
const old = streams.get('first')!;
|
||||
fireEvent.change(screen.getByRole('combobox', { name: '智能体话题' }), {
|
||||
@@ -245,8 +262,6 @@ describe('teacher side chat', () => {
|
||||
)
|
||||
);
|
||||
expect(screen.getByRole('combobox', { name: '智能体话题' })).toHaveValue('second');
|
||||
fireEvent.click(screen.getByRole('button', { name: '关闭智能体' }));
|
||||
expect(closed).toHaveBeenCalledOnce();
|
||||
view.unmount();
|
||||
expect(api.cancel).not.toHaveBeenCalled();
|
||||
expect(old.close).toHaveBeenCalled();
|
||||
@@ -297,7 +312,8 @@ describe('teacher side chat', () => {
|
||||
api.catalog.mockResolvedValue({ items: [{ teacher_id: 'published', version: 2, is_default: true, definition: published }] });
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" />);
|
||||
await screen.findByRole('heading', { name, exact: true });
|
||||
expect(screen.getByText('这是运营发布的简介')).toBeVisible();
|
||||
expect(screen.queryByText('这是运营发布的简介')).not.toBeInTheDocument();
|
||||
expect(within(screen.getByTestId('teacher-chat-panel').querySelector('header')!).queryByRole('button')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('服务端欢迎语')).toBeVisible();
|
||||
expect(screen.getByRole('button', { name: '服务端推荐问题' })).toBeEnabled();
|
||||
expect(screen.getByTestId('teacher-chat-panel').querySelector('img')?.src).toContain('avatar-09.png');
|
||||
@@ -681,6 +697,8 @@ describe('merged cloud teacher classroom', () => {
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" selectedAgent={{ teacher_id: 'algorithm', version: 9, definition: cloudDefinition, is_default: false }} />);
|
||||
await waitFor(() => expect(screen.getByLabelText('向智能体提问')).toBeEnabled());
|
||||
expect(screen.queryByLabelText('新话题使用的智能体')).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: '以往讨论' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: '智能体新话题' })).not.toBeInTheDocument();
|
||||
expect(api.create).not.toHaveBeenCalled();
|
||||
fireEvent.change(screen.getByLabelText('向智能体提问'), { target: { value: '我想做一个小游戏' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
|
||||
|
||||
Reference in New Issue
Block a user