66 deriveUniqueRepos ,
77 filterAndSortArchivedTasks ,
88 getRepoName ,
9+ mergeArchivedWithTasks ,
910 withRepoNames ,
1011} from "./archiveListView" ;
1112
@@ -58,6 +59,63 @@ describe("deriveUniqueRepos", () => {
5859 } ) ;
5960} ) ;
6061
62+ describe ( "mergeArchivedWithTasks" , ( ) => {
63+ it ( "resolves details fetched directly for an archived task" , ( ) => {
64+ const archived = makeArchived ( "older-task" , "2024-01-02T00:00:00.000Z" ) ;
65+ const task = makeTask ( "older-task" , { title : "Recover me" } ) ;
66+
67+ expect ( mergeArchivedWithTasks ( [ archived ] , [ task ] ) ) . toEqual ( [
68+ { archived, task } ,
69+ ] ) ;
70+ } ) ;
71+
72+ it . each ( [
73+ {
74+ name : "creation date" ,
75+ patch : { taskCreatedAt : undefined } ,
76+ expected : {
77+ title : "Recovered title" ,
78+ created_at : null ,
79+ repository : "posthog/code" ,
80+ } ,
81+ } ,
82+ {
83+ name : "title" ,
84+ patch : { title : undefined } ,
85+ expected : {
86+ title : "Unknown task (older-ta)" ,
87+ created_at : "2024-01-01T00:00:00.000Z" ,
88+ repository : "posthog/code" ,
89+ } ,
90+ } ,
91+ {
92+ name : "repository" ,
93+ patch : { repository : undefined } ,
94+ expected : {
95+ title : "Recovered title" ,
96+ created_at : "2024-01-01T00:00:00.000Z" ,
97+ repository : null ,
98+ } ,
99+ } ,
100+ ] ) (
101+ "preserves other archived metadata when $name is missing" ,
102+ ( { patch, expected } ) => {
103+ const archived = {
104+ ...makeArchived ( "older-task" , "2024-01-02T00:00:00.000Z" ) ,
105+ title : "Recovered title" ,
106+ taskCreatedAt : "2024-01-01T00:00:00.000Z" ,
107+ repository : "posthog/code" ,
108+ ...patch ,
109+ } ;
110+
111+ expect ( mergeArchivedWithTasks ( [ archived ] , [ ] ) [ 0 ] . task ) . toEqual ( {
112+ id : "older-task" ,
113+ ...expected ,
114+ } ) ;
115+ } ,
116+ ) ;
117+ } ) ;
118+
61119describe ( "filterAndSortArchivedTasks" , ( ) => {
62120 const items : ArchivedTaskWithDetails [ ] = [
63121 {
@@ -79,6 +137,15 @@ describe("filterAndSortArchivedTasks", () => {
79137 expect ( result . map ( ( i ) => i . archived . taskId ) ) . toEqual ( [ "b" ] ) ;
80138 } ) ;
81139
140+ it ( "filters by task id when the original title is unavailable" , ( ) => {
141+ const result = filterAndSortArchivedTasks ( withRepoNames ( items ) , {
142+ searchQuery : "b" ,
143+ repoFilter : null ,
144+ sort : { column : "archived" , direction : "desc" } ,
145+ } ) ;
146+ expect ( result . map ( ( i ) => i . archived . taskId ) ) . toEqual ( [ "b" ] ) ;
147+ } ) ;
148+
82149 it ( "filters by repo name" , ( ) => {
83150 const result = filterAndSortArchivedTasks ( withRepoNames ( items ) , {
84151 searchQuery : "" ,
@@ -88,6 +155,15 @@ describe("filterAndSortArchivedTasks", () => {
88155 expect ( result . map ( ( i ) => i . archived . taskId ) ) . toEqual ( [ "a" ] ) ;
89156 } ) ;
90157
158+ it ( "does not include repository names in the title and task ID search" , ( ) => {
159+ const result = filterAndSortArchivedTasks ( withRepoNames ( items ) , {
160+ searchQuery : "two" ,
161+ repoFilter : null ,
162+ sort : { column : "archived" , direction : "desc" } ,
163+ } ) ;
164+ expect ( result ) . toEqual ( [ ] ) ;
165+ } ) ;
166+
91167 it ( "sorts by archivedAt descending" , ( ) => {
92168 const result = filterAndSortArchivedTasks ( withRepoNames ( items ) , {
93169 searchQuery : "" ,
0 commit comments