feat(chat): simplify teacher pane and color follow-up cards

This commit is contained in:
鲨鱼辣椒 committed 2026-09-28 12:43:39 +08:00
1 parent 80c9c0d683
commit 862477f9d4
8 files changed
+51 -38

No files matched your search

+10 -11
View File
@@ -1,4 +1,4 @@
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { act, fireEvent, render, screen, waitFor } 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,31 +96,30 @@ 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 () => {
it('opens directly into the consultation 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();
const panel = screen.getByRole('complementary', { name: '智能体咨询' });
expect(panel).toBeVisible();
expect(panel.querySelector('header')).toBeNull();
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 () => {
it('renders the pinned topic icon with 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: '继续原来的讨论' })] });
const view = render(<TeacherChatPanel projectId="p" sourceId="c" />);
await ready();
const images = view.container.querySelectorAll('[data-testid="teacher-chat-panel"] img');
expect(images).toHaveLength(2);
expect(images).toHaveLength(1);
for (const img of images) expect(img).toHaveAttribute('src', icon);
});
@@ -311,9 +310,9 @@ describe('teacher side chat', () => {
api.list.mockResolvedValue({ items: [], lastSelectedTopicId: null });
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 });
const panel = await screen.findByRole('complementary', { name: `${name}咨询`, exact: true });
expect(screen.queryByText('这是运营发布的简介')).not.toBeInTheDocument();
expect(within(screen.getByTestId('teacher-chat-panel').querySelector('header')!).queryByRole('button')).not.toBeInTheDocument();
expect(panel.querySelector('header')).toBeNull();
expect(screen.getByText('服务端欢迎语')).toBeVisible();
expect(screen.getByRole('button', { name: '服务端推荐问题' })).toBeEnabled();
expect(screen.getByTestId('teacher-chat-panel').querySelector('img')?.src).toContain('avatar-09.png');
@@ -705,7 +704,7 @@ describe('merged cloud teacher classroom', () => {
await screen.findByText('先看看玩家会做什么。');
expect(api.create).toHaveBeenCalledWith('p/agent-topics', undefined, undefined, 9);
expect(api.send.mock.calls[0][2]).toMatchObject({ sourceConversationId: 'c', presentation: 'discussion-v1' });
expect(screen.getByRole('heading', { name: '算法智能体' })).toBeVisible();
expect(screen.getByRole('complementary', { name: '算法智能体咨询' })).toBeVisible();
});
it('does not enable a disabled cloud topic through another teacher or an Enter shortcut', async () => {