feat: integrate pinned teacher discussion workspace
This commit is contained in:
@@ -9,6 +9,7 @@ const api = vi.hoisted(() => ({
|
||||
create: vi.fn(),
|
||||
read: vi.fn(),
|
||||
send: vi.fn(),
|
||||
updateDiscussion: vi.fn(),
|
||||
cancel: vi.fn(),
|
||||
save: vi.fn(),
|
||||
events: vi.fn(),
|
||||
@@ -448,3 +449,105 @@ describe('teacher side chat', () => {
|
||||
await waitFor(() => expect(api.create).toHaveBeenCalledWith('preview/sample', 7, '学生的练习代码'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('pinned discussion workspace', () => {
|
||||
const ideas = { id: 'tool', revision: 1, status: 'active' as const, content: {
|
||||
kind: 'ideas' as const, title: '一起想我的宠物游戏', items: [{ id: 'dog', text: '养只小狗', state: 'kept' as const }],
|
||||
} };
|
||||
async function openDiscussion(status: 'active' | 'offered' = 'active') {
|
||||
const current = { ...structuredClone(first), discussion: { ...structuredClone(ideas), status } };
|
||||
api.read.mockResolvedValue(current);
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" role="teacher" />);
|
||||
await screen.findByText('一起想我的宠物游戏');
|
||||
await waitFor(() => expect(streams.has('first')).toBe(true));
|
||||
return current;
|
||||
}
|
||||
it('quotes a focused item into the existing composer without sending, then sends the locked version', async () => {
|
||||
const current = await openDiscussion();
|
||||
api.send.mockImplementation(async (_base, _id, input) => ({ ...current, revision: 2, requests: [request({ text: input.text, response: '先聊聊小狗。' })] }));
|
||||
fireEvent.click(screen.getByRole('button', { name: '养只小狗', exact: true }));
|
||||
expect(api.send).not.toHaveBeenCalled();
|
||||
expect(screen.getByText('接着聊:养只小狗')).toBeVisible();
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '我希望是柯基' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
|
||||
await waitFor(() => expect(api.send).toHaveBeenCalledWith('p/teacher', 'first', expect.objectContaining({ presentation: 'discussion-v1', discussion: { toolId: 'tool', revision: 1, focusId: 'dog' }, text: '我希望是柯基' })));
|
||||
expect(screen.getAllByTestId('teacher-discussion')).toHaveLength(1);
|
||||
});
|
||||
it('finishes provisionally, keeps the draft, chats without changing the tool, and resumes explicitly', async () => {
|
||||
const current = await openDiscussion();
|
||||
api.updateDiscussion.mockResolvedValueOnce({ ...current, revision: 2, discussion: { ...ideas, status: 'finished', revision: 2 } });
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '还在想的下一句' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '先这些', exact: true }));
|
||||
await screen.findByText('先留在这里');
|
||||
expect(screen.getByLabelText('向老师提问')).toHaveValue('还在想的下一句');
|
||||
expect(screen.getByTestId('teacher-discussion')).toHaveAttribute('data-collapsed', 'true');
|
||||
api.send.mockImplementation(async (_base, _id, input) => ({ ...current, revision: 3, discussion: { ...ideas, status: 'finished', revision: 2 }, requests: [request({ text: input.text, response: '我们慢慢聊。' })] }));
|
||||
fireEvent.click(screen.getByRole('button', { name: '提问', exact: true }));
|
||||
await screen.findByText('我们慢慢聊。');
|
||||
expect(api.send.mock.calls[0][2].discussion).toBeUndefined();
|
||||
api.updateDiscussion.mockResolvedValueOnce({ ...current, revision: 4, discussion: { ...ideas, revision: 3 } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '接着改', exact: true }));
|
||||
await screen.findByRole('button', { name: '养只小狗', exact: true });
|
||||
expect(api.updateDiscussion.mock.calls[1][2]).toEqual({ toolId: 'tool', revision: 2, action: 'resume' });
|
||||
});
|
||||
it('offers a tool before activating, and preserves a draft during explicit structure conversion', async () => {
|
||||
const current = await openDiscussion('offered');
|
||||
api.updateDiscussion.mockResolvedValue({ ...current, revision: 2, discussion: { ...ideas, revision: 2 } });
|
||||
expect(screen.getByRole('button', { name: '养只小狗', exact: true })).toBeDisabled();
|
||||
fireEvent.click(screen.getByRole('button', { name: '用这个一起想', exact: true }));
|
||||
await screen.findByRole('button', { name: '把想法理一理', exact: true });
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '不要丢掉的草稿' } });
|
||||
api.send.mockResolvedValue({ ...current, revision: 3, discussion: { ...ideas, revision: 2 }, requests: [] });
|
||||
fireEvent.click(screen.getByRole('button', { name: '把想法理一理', exact: true }));
|
||||
await waitFor(() => expect(api.send).toHaveBeenCalled());
|
||||
expect(api.send.mock.calls[0][2].discussion).toEqual({ toolId: 'tool', revision: 2, transition: 'structure' });
|
||||
expect(screen.getByLabelText('向老师提问')).toHaveValue('不要丢掉的草稿');
|
||||
});
|
||||
it('uses the same pinned component for SSE updates and leaves it untouched while thinking or stopping', async () => {
|
||||
const current = await openDiscussion();
|
||||
const stream = streams.get('first')!;
|
||||
const updating = { ...current, revision: 2, requests: [request({ status: 'running', response: '', discussionContext: { toolId: 'tool', revision: 1 } })] };
|
||||
act(() => stream.dispatchEvent(new MessageEvent('snapshot', { data: JSON.stringify(updating) })));
|
||||
expect(screen.getByRole('status')).toHaveTextContent('正在梳理');
|
||||
expect(screen.getByRole('button', { name: '养只小狗', exact: true })).toBeVisible();
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '下一轮草稿' } });
|
||||
api.cancel.mockResolvedValue({ ...updating, revision: 3, requests: [request({ status: 'cancelled' })] });
|
||||
fireEvent.click(screen.getByRole('button', { name: '停止回复' }));
|
||||
await screen.findByText('这次先停在这里。想继续时可以再说说。');
|
||||
expect(screen.getByLabelText('向老师提问')).toHaveValue('下一轮草稿');
|
||||
act(() => stream.dispatchEvent(new MessageEvent('snapshot', { data: JSON.stringify({ ...current, revision: 4, discussion: { ...ideas, revision: 2, content: { ...ideas.content, title: '一起想小狗和花园' } } }) })));
|
||||
expect(screen.getAllByTestId('teacher-discussion')).toHaveLength(1);
|
||||
expect(screen.getByText('一起想小狗和花园')).toBeVisible();
|
||||
});
|
||||
it('sends a normal suggested question directly without changing the composer draft', async () => {
|
||||
const current = { ...first, requests: [request({ response: '先听听你的想法。', suggestedQuestions: ['怎样知道小狗喜欢我?'] })] };
|
||||
api.read.mockResolvedValue(current);
|
||||
api.send.mockResolvedValue({ ...current, revision: 2 });
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" role="teacher" />);
|
||||
await screen.findByRole('button', { name: '怎样知道小狗喜欢我?' });
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '自己的草稿' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '怎样知道小狗喜欢我?' }));
|
||||
await waitFor(() => expect(api.send).toHaveBeenCalled());
|
||||
expect(api.send.mock.calls[0][2].text).toBe('怎样知道小狗喜欢我?');
|
||||
expect(screen.getByLabelText('向老师提问')).toHaveValue('自己的草稿');
|
||||
expect(screen.queryByTestId('teacher-discussion')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('comparison focuses and directly sends the selected difference while preserving the existing draft', async () => {
|
||||
const current = { ...first, discussion: { id: 'compare', revision: 3, status: 'active' as const, content: {
|
||||
kind: 'comparison' as const, title: '它什么时候回应我?', columns: [{ id: 'a', label: '点击才回应' }, { id: 'b', label: '主动回应' }], rows: [{ id: 'home', label: '回到家时', cells: [{ columnId: 'a', text: '等我点击' }, { columnId: 'b', text: '跑来欢迎我' }] }],
|
||||
} } };
|
||||
api.read.mockResolvedValue(current);
|
||||
api.send.mockResolvedValue({ ...current, revision: 2 });
|
||||
render(<TeacherChatPanel projectId="p" sourceId="c" role="teacher" />);
|
||||
await screen.findByText('回到家时');
|
||||
fireEvent.change(screen.getByLabelText('向老师提问'), { target: { value: '自己还没说完的话' } });
|
||||
fireEvent.click(screen.getAllByRole('button', { name: '聊聊这一点' })[1]);
|
||||
await waitFor(() => expect(api.send).toHaveBeenCalled());
|
||||
expect(api.send.mock.calls[0][2]).toMatchObject({ text: '聊聊「回到家时」时,「主动回应」这一点:跑来欢迎我', discussion: { toolId: 'compare', revision: 3, focusId: 'home:b' } });
|
||||
expect(screen.getByLabelText('向老师提问')).toHaveValue('自己还没说完的话');
|
||||
expect(screen.getAllByTestId('teacher-discussion')).toHaveLength(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user