Repository navigation
feat(chat): fold a run of claim lines into one summary row (TASK-692) #3084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
26260ce
feat(chat): fold a run of claim lines into one summary row (TASK-692)
lilyshen0722 2f26cb1
fix(i18n): attach the zh-CN claim-run count and declare its last plac…
lilyshen0722 848780d
test(chat): cover the claim-run summary control in a rendered thread …
lilyshen0722 c668d27
Merge remote-tracking branch 'origin/main' into polish/task-692-merge
lilyshen0722 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import React from 'react'; | ||
| import { act, render, screen, within } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { MemoryRouter } from 'react-router-dom'; | ||
| import i18n from '../../i18n'; | ||
| import V2ThreadMessages from '../components/V2ThreadMessages'; | ||
| import { buildThreadView } from '../utils/threadView'; | ||
|
|
||
| jest.mock('../../context/AuthContext', () => ({ | ||
| useAuth: () => ({ currentUser: { username: 'viewer' } }), | ||
| })); | ||
| jest.mock('../hooks/useV2Api', () => ({ | ||
| useV2Api: () => ({ get: jest.fn(), post: jest.fn(), patch: jest.fn(), del: jest.fn() }), | ||
| })); | ||
|
|
||
| const claim = (id: number, taskId: string) => ({ | ||
| id: String(id), | ||
| pod_id: 'pod-1', | ||
| user_id: 'u1', | ||
| content: '', | ||
| message_type: 'system', | ||
| created_at: `2026-10-31T10:0${id}:00.000Z`, | ||
| thread_root_id: null, | ||
| user: { username: 'scout' }, | ||
| payload: { kind: 'system-action', action: 'task-claimed', taskId, actorName: 'Scout' }, | ||
| }); | ||
|
|
||
| const claims = [claim(1, 'TASK-674'), claim(2, 'TASK-675'), claim(3, 'TASK-676'), claim(4, 'TASK-678')]; | ||
|
|
||
| const renderClaims = (messages = claims) => { | ||
| const threadView = buildThreadView(messages as any, new Map()); | ||
| return render( | ||
| <MemoryRouter> | ||
| <V2ThreadMessages | ||
| messages={messages as any} | ||
| threadView={threadView} | ||
| threadState={{ byRoot: new Map(), toggleCollapsed: jest.fn(), toggleFollowing: jest.fn() }} | ||
| decisionByMessageId={new Map()} | ||
| settledDecisionByMessageId={new Map()} | ||
| agentDisplayNames={new Map()} | ||
| agentAuthorKeys={new Set()} | ||
| onAimAtThread={jest.fn()} | ||
| hasMore={false} | ||
| loadingOlder={false} | ||
| onLoadOlder={jest.fn()} | ||
| loading={false} | ||
| error={null} | ||
| messagesContainerRef={React.createRef()} | ||
| messagesEndRef={React.createRef()} | ||
| /> | ||
| </MemoryRouter>, | ||
| ); | ||
| }; | ||
|
|
||
| // The claim rows render as V2MessageRow system lines with a task id each. | ||
| const claimRowTaskIds = (container: HTMLElement) => Array.from( | ||
| container.querySelectorAll('.v2-system-action-line__object'), | ||
| ).map((node) => node.textContent); | ||
|
|
||
| describe('claim run summary control (TASK-692)', () => { | ||
| afterEach(() => i18n.changeLanguage('en')); | ||
|
|
||
| test('shows the count and the first and last task ids, collapsed by default', () => { | ||
| const { container } = renderClaims(); | ||
| const toggle = screen.getByRole('button', { name: '4 claims · TASK-674 to TASK-678' }); | ||
| expect(toggle).toHaveAttribute('aria-expanded', 'false'); | ||
| expect(claimRowTaskIds(container)).toEqual([]); | ||
| }); | ||
|
|
||
| test('clicking expands the claim rows in order and clicking again collapses them', () => { | ||
| const { container } = renderClaims(); | ||
| const toggle = screen.getByRole('button', { name: /4 claims/ }); | ||
| act(() => toggle.click()); | ||
| expect(toggle).toHaveAttribute('aria-expanded', 'true'); | ||
| expect(claimRowTaskIds(container)).toEqual(['TASK-674', 'TASK-675', 'TASK-676', 'TASK-678']); | ||
| act(() => toggle.click()); | ||
| expect(toggle).toHaveAttribute('aria-expanded', 'false'); | ||
| expect(claimRowTaskIds(container)).toEqual([]); | ||
| }); | ||
|
|
||
| test('Enter and Space on the focused toggle expand and collapse it', async () => { | ||
| const user = userEvent.setup(); | ||
| const { container } = renderClaims(); | ||
| const toggle = screen.getByRole('button', { name: /4 claims/ }); | ||
| toggle.focus(); | ||
| await user.keyboard('{Enter}'); | ||
| expect(toggle).toHaveAttribute('aria-expanded', 'true'); | ||
| expect(claimRowTaskIds(container)).toHaveLength(4); | ||
| await user.keyboard(' '); | ||
| expect(toggle).toHaveAttribute('aria-expanded', 'false'); | ||
| expect(claimRowTaskIds(container)).toEqual([]); | ||
| }); | ||
|
|
||
| test('the expanded rows sit inside the summary group, below the toggle', () => { | ||
| const { container } = renderClaims(); | ||
| act(() => screen.getByRole('button', { name: /4 claims/ }).click()); | ||
| const group = container.querySelector('.v2-claim-run') as HTMLElement; | ||
| expect(within(group).getByRole('button', { name: /4 claims/ })).toBeInTheDocument(); | ||
| expect(group.querySelectorAll('.v2-system-action-line')).toHaveLength(4); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { buildThreadView } from '../utils/threadView'; | ||
|
|
||
| const claim = (id: number, taskId: string, opts: Partial<any> = {}) => ({ | ||
| id: String(id), | ||
| pod_id: 'pod-1', | ||
| user_id: 'u1', | ||
| content: '', | ||
| message_type: 'system', | ||
| created_at: `2026-10-31T10:0${id % 10}:00Z`, | ||
| thread_root_id: opts.thread_root_id ?? null, | ||
| payload: { kind: 'system-action', action: 'task-claimed', taskId, actorName: 'Scout' }, | ||
| } as any); | ||
|
|
||
| const text = (id: number) => ({ | ||
| id: String(id), | ||
| pod_id: 'pod-1', | ||
| user_id: 'u2', | ||
| content: `m${id}`, | ||
| message_type: 'text', | ||
| created_at: `2026-10-31T10:0${id % 10}:00Z`, | ||
| thread_root_id: null, | ||
| } as any); | ||
|
|
||
| const state = (ids: number[]) => new Map( | ||
| ids.map((i) => [String(i), { threadRootId: i, following: null, collapsed: true }]), | ||
| ) as any; | ||
|
|
||
| describe('consecutive claim lines fold into one summary item', () => { | ||
| test('two adjacent claims become one claims item, in order', () => { | ||
| const items = buildThreadView([claim(1, 'TASK-674'), claim(2, 'TASK-675')], state([])); | ||
| expect(items.map((i) => i.kind)).toEqual(['claims']); | ||
| expect(items[0]).toMatchObject({ kind: 'claims', key: '1' }); | ||
| expect((items[0] as any).messages.map((m: any) => m.id)).toEqual(['1', '2']); | ||
| }); | ||
|
|
||
| test('a single claim stays a plain message', () => { | ||
| const items = buildThreadView([text(1), claim(2, 'TASK-674'), text(3)], state([])); | ||
| expect(items.map((i) => i.kind)).toEqual(['message', 'message', 'message']); | ||
| }); | ||
|
|
||
| test('a normal message between claims ends the run', () => { | ||
| const items = buildThreadView( | ||
| [claim(1, 'TASK-674'), claim(2, 'TASK-675'), text(3), claim(4, 'TASK-676'), claim(5, 'TASK-677')], | ||
| state([]), | ||
| ); | ||
| expect(items.map((i) => i.kind)).toEqual(['claims', 'message', 'claims']); | ||
| }); | ||
|
|
||
| test('a claim that roots a thread stays a message so its card still renders', () => { | ||
| const items = buildThreadView( | ||
| [claim(1, 'TASK-674'), claim(2, 'TASK-675'), claim(3, 'TASK-676', {}), claim(4, 'TASK-677', { thread_root_id: 3 })], | ||
| state([3]), | ||
| ); | ||
| expect(items.map((i) => i.kind)).toEqual(['claims', 'message', 'card']); | ||
| expect(items[1]).toMatchObject({ kind: 'message', message: { id: '3' } }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.