@@ -76,6 +76,7 @@ import { useTaskSearch } from "../useTaskSearch"
7676import { useGroupedTasks } from "../useGroupedTasks"
7777import { useExtensionState } from "@src/context/ExtensionStateContext"
7878import { useTaskOrganizationDnd } from "../useTaskOrganizationDnd"
79+ import TaskGroupItem from "../TaskGroupItem"
7980
8081const mockUseTaskSearch = useTaskSearch as any
8182const mockUseGroupedTasks = useGroupedTasks as any
@@ -332,6 +333,65 @@ describe("HistoryView task organization integration", () => {
332333 expect ( screen . getByTestId ( "draggable-entry-unfiled-unit-t3" ) ) . toBeInTheDocument ( )
333334 } )
334335
336+ it ( "passes pin props to grouped rows and pins a task via the row toggle" , async ( ) => {
337+ mockUseTaskOrganizationDnd . mockReturnValue ( {
338+ sensors : [ ] ,
339+ activeDrag : null ,
340+ targetMeta : { isOverTarget : false } ,
341+ handleDragStart : vi . fn ( ) ,
342+ handleDragOver : vi . fn ( ) ,
343+ handleDragEnd : vi . fn ( ) ,
344+ handleDragCancel : vi . fn ( ) ,
345+ UNFILED_DROP_ZONE_ID ,
346+ } )
347+ const t1 = makeTask ( "t1" )
348+ const t2 = makeTask ( "t2" )
349+ const t3 = makeTask ( "t3" )
350+ const mutateSpy = vi . fn ( ) . mockResolvedValue ( {
351+ requestId : "" ,
352+ success : true ,
353+ committedRevision : 1 ,
354+ } )
355+
356+ mockUseExtensionState . mockReturnValue ( {
357+ taskOrganization : {
358+ ...createEmptyOrganizationState ( ) ,
359+ pins : [ { target : { kind : "task" , taskId : "t3" } , pinnedAt : 100 } ] ,
360+ } ,
361+ mutateTaskOrganization : mutateSpy ,
362+ cwd : "/test/workspace" ,
363+ } )
364+ mockUseTaskSearch . mockReturnValue ( {
365+ ...defaultSearchResult ,
366+ tasks : [ t1 , t2 , t3 ] ,
367+ } )
368+ mockUseGroupedTasks . mockReturnValue ( {
369+ groups : [ makeGroup ( t1 ) , makeGroup ( t2 ) , makeGroup ( t3 ) ] ,
370+ flatTasks : null ,
371+ toggleExpand : vi . fn ( ) ,
372+ isSearchMode : false ,
373+ } )
374+
375+ render ( < HistoryView onDone = { vi . fn ( ) } /> )
376+
377+ // Every grouped row receives pin props; only t3 is pinned.
378+ const calls = vi . mocked ( TaskGroupItem ) . mock . calls . map ( ( [ props ] ) => props )
379+ const byId = new Map ( calls . map ( ( props ) => [ props . group . parent . id , props ] ) )
380+ expect ( byId . get ( "t1" ) ) . toMatchObject ( { showPin : true , isPinned : false , canPin : true } )
381+ expect ( byId . get ( "t2" ) ) . toMatchObject ( { showPin : true , isPinned : false , canPin : true } )
382+ expect ( byId . get ( "t3" ) ) . toMatchObject ( { showPin : true , isPinned : true , canPin : true } )
383+
384+ // Toggling t1's pin posts a setPinned mutation with the task target.
385+ byId . get ( "t1" ) ?. onTogglePin ?.( )
386+ await waitFor ( ( ) => {
387+ expect ( mutateSpy ) . toHaveBeenCalledWith ( {
388+ kind : "setPinned" ,
389+ target : { kind : "task" , taskId : "t1" } ,
390+ pinned : true ,
391+ } )
392+ } )
393+ } )
394+
335395 it ( "opens the folder-name dialog after a real task-on-task drop and posts createFolder on confirm" , async ( ) => {
336396 const mutateSpy = vi . fn ( ) . mockResolvedValue ( {
337397 requestId : "" ,
0 commit comments