@@ -1068,131 +1068,76 @@ describe("MessagesTimeline messages", () => {
10681068} ) ;
10691069
10701070describe ( "MessagesTimeline turn folds" , ( ) => {
1071- it ( "keeps a turn the user expanded open when the next run starts" , async ( ) => {
1072- const props = baseProps ( ) ;
1073- const firstRun = RunId . make ( "run-1" ) ;
1074- const secondRun = RunId . make ( "run-2" ) ;
1075- const at = ( second : number ) => new Date ( Date . parse ( CREATED_AT ) + second * 1000 ) . toISOString ( ) ;
1076- const settled = [
1077- message ( "First prompt" , { runId : firstRun , inputIntent : "turn_start" } , "user-1" ) ,
1078- message (
1079- "Interim progress note" ,
1080- { role : "assistant" , runId : firstRun , createdAt : at ( 2 ) , updatedAt : at ( 2 ) } ,
1081- "assistant-interim" ,
1082- ) ,
1071+ const firstRun = RunId . make ( "run-1" ) ;
1072+ const secondRun = RunId . make ( "run-2" ) ;
1073+ const at = ( second : number ) => new Date ( Date . parse ( CREATED_AT ) + second * 1000 ) . toISOString ( ) ;
1074+ const settled = [
1075+ message ( "First prompt" , { runId : firstRun , inputIntent : "turn_start" } , "user-1" ) ,
1076+ message (
1077+ "Interim progress note" ,
1078+ { role : "assistant" , runId : firstRun , createdAt : at ( 2 ) , updatedAt : at ( 2 ) } ,
1079+ "assistant-interim" ,
1080+ ) ,
1081+ message (
1082+ "Final reply" ,
1083+ { role : "assistant" , runId : firstRun , createdAt : at ( 9 ) , updatedAt : at ( 9 ) } ,
1084+ "assistant-final" ,
1085+ ) ,
1086+ ] ;
1087+ const nextRunStarted = {
1088+ entries : [
1089+ ...settled ,
10831090 message (
1084- "Final reply " ,
1085- { role : "assistant" , runId : firstRun , createdAt : at ( 9 ) , updatedAt : at ( 9 ) } ,
1086- "assistant-final " ,
1091+ "Follow-up " ,
1092+ { runId : secondRun , inputIntent : "turn_start" , createdAt : at ( 20 ) , updatedAt : at ( 20 ) } ,
1093+ "user-2 " ,
10871094 ) ,
1088- ] ;
1089- const timeline = ( entries : Entry [ ] , extra : Partial < TimelineProps > ) => (
1090- < MessagesTimeline { ...props } timelineEntries = { entries } { ...extra } />
1091- ) ;
1095+ ] ,
1096+ isWorking : true ,
1097+ latestRun : { runId : secondRun , status : "running" , startedAt : at ( 21 ) , completedAt : null } ,
1098+ } as const ;
1099+ const running = {
1100+ isWorking : true ,
1101+ latestRun : { runId : firstRun , status : "running" , startedAt : at ( 0 ) , completedAt : null } ,
1102+ } as const ;
1103+ const interrupted = {
1104+ latestRun : { runId : firstRun , status : "interrupted" , startedAt : at ( 0 ) , completedAt : at ( 9 ) } ,
1105+ } as const ;
1106+ const timeline = (
1107+ props : ReturnType < typeof baseProps > ,
1108+ { entries = settled , ...extra } : Partial < TimelineProps > & { entries ?: readonly Entry [ ] } ,
1109+ ) => < MessagesTimeline { ...props } timelineEntries = { [ ...entries ] } { ...extra } /> ;
1110+
1111+ it ( "keeps a turn the user expanded open when the next run starts" , async ( ) => {
1112+ const props = baseProps ( ) ;
10921113 await using screen = await renderElement (
1093- timeline ( settled , {
1114+ timeline ( props , {
10941115 latestRun : { runId : firstRun , status : "completed" , startedAt : at ( 0 ) , completedAt : at ( 9 ) } ,
10951116 } ) ,
10961117 ) ;
1097- const fold = ( ) => screen . button ( / ^ W o r k e d f o r / ) ;
10981118 expect ( screen . text ( ) ) . not . toContain ( "Interim progress note" ) ;
1099- await click ( fold ( ) ) ;
1100- expect ( screen . text ( ) ) . toContain ( "Interim progress note" ) ;
1119+ await click ( screen . button ( / ^ W o r k e d f o r / ) ) ;
11011120
1102- await screen . rerender (
1103- timeline (
1104- [
1105- ...settled ,
1106- message (
1107- "Follow-up" ,
1108- { runId : secondRun , inputIntent : "turn_start" , createdAt : at ( 20 ) , updatedAt : at ( 20 ) } ,
1109- "user-2" ,
1110- ) ,
1111- ] ,
1112- {
1113- isWorking : true ,
1114- latestRun : { runId : secondRun , status : "running" , startedAt : at ( 21 ) , completedAt : null } ,
1115- } ,
1116- ) ,
1117- ) ;
1121+ await screen . rerender ( timeline ( props , nextRunStarted ) ) ;
11181122
1119- expect ( fold ( ) . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
1123+ expect ( screen . button ( / ^ W o r k e d f o r / ) . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
11201124 expect ( screen . text ( ) ) . toContain ( "Interim progress note" ) ;
11211125 } ) ;
11221126
11231127 it ( "folds an interrupted turn it expanded once the next run starts" , async ( ) => {
11241128 const props = baseProps ( ) ;
1125- const firstRun = RunId . make ( "run-1" ) ;
1126- const secondRun = RunId . make ( "run-2" ) ;
1127- const at = ( second : number ) => new Date ( Date . parse ( CREATED_AT ) + second * 1000 ) . toISOString ( ) ;
1128- const settled = [
1129- message ( "First prompt" , { runId : firstRun , inputIntent : "turn_start" } , "user-1" ) ,
1130- message (
1131- "Interim progress note" ,
1132- { role : "assistant" , runId : firstRun , createdAt : at ( 2 ) , updatedAt : at ( 2 ) } ,
1133- "assistant-interim" ,
1134- ) ,
1135- message (
1136- "Final reply" ,
1137- { role : "assistant" , runId : firstRun , createdAt : at ( 9 ) , updatedAt : at ( 9 ) } ,
1138- "assistant-final" ,
1139- ) ,
1140- ] ;
1141- const timeline = ( entries : Entry [ ] , extra : Partial < TimelineProps > ) => (
1142- < MessagesTimeline { ...props } timelineEntries = { entries } { ...extra } />
1143- ) ;
1144- await using screen = await renderElement (
1145- timeline ( settled , {
1146- isWorking : true ,
1147- latestRun : { runId : firstRun , status : "running" , startedAt : at ( 0 ) , completedAt : null } ,
1148- } ) ,
1149- ) ;
1150- await screen . rerender (
1151- timeline ( settled , {
1152- latestRun : { runId : firstRun , status : "interrupted" , startedAt : at ( 0 ) , completedAt : at ( 9 ) } ,
1153- } ) ,
1154- ) ;
1129+ await using screen = await renderElement ( timeline ( props , running ) ) ;
1130+ await screen . rerender ( timeline ( props , interrupted ) ) ;
11551131 expect ( screen . button ( / ^ Y o u s t o p p e d a f t e r / ) . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
11561132
1157- await screen . rerender (
1158- timeline (
1159- [
1160- ...settled ,
1161- message (
1162- "Follow-up" ,
1163- { runId : secondRun , inputIntent : "turn_start" , createdAt : at ( 20 ) , updatedAt : at ( 20 ) } ,
1164- "user-2" ,
1165- ) ,
1166- ] ,
1167- {
1168- isWorking : true ,
1169- latestRun : { runId : secondRun , status : "running" , startedAt : at ( 21 ) , completedAt : null } ,
1170- } ,
1171- ) ,
1172- ) ;
1133+ await screen . rerender ( timeline ( props , nextRunStarted ) ) ;
11731134
11741135 expect ( screen . button ( / ^ W o r k e d f o r / ) . getAttribute ( "aria-expanded" ) ) . toBe ( "false" ) ;
11751136 expect ( screen . text ( ) ) . not . toContain ( "Interim progress note" ) ;
11761137 } ) ;
11771138
11781139 it ( "keeps an interrupted turn that was already expanded open when the next run starts" , async ( ) => {
11791140 const props = baseProps ( ) ;
1180- const firstRun = RunId . make ( "run-1" ) ;
1181- const secondRun = RunId . make ( "run-2" ) ;
1182- const at = ( second : number ) => new Date ( Date . parse ( CREATED_AT ) + second * 1000 ) . toISOString ( ) ;
1183- const settled = [
1184- message ( "First prompt" , { runId : firstRun , inputIntent : "turn_start" } , "user-1" ) ,
1185- message (
1186- "Interim progress note" ,
1187- { role : "assistant" , runId : firstRun , createdAt : at ( 2 ) , updatedAt : at ( 2 ) } ,
1188- "assistant-interim" ,
1189- ) ,
1190- message (
1191- "Final reply" ,
1192- { role : "assistant" , runId : firstRun , createdAt : at ( 9 ) , updatedAt : at ( 9 ) } ,
1193- "assistant-final" ,
1194- ) ,
1195- ] ;
11961141 rememberTimelinePosition (
11971142 props . routeThreadKey ,
11981143 {
@@ -1209,38 +1154,10 @@ describe("MessagesTimeline turn folds", () => {
12091154 } ,
12101155 false ,
12111156 ) ;
1212- const timeline = ( entries : Entry [ ] , extra : Partial < TimelineProps > ) => (
1213- < MessagesTimeline { ...props } timelineEntries = { entries } { ...extra } />
1214- ) ;
1215- await using screen = await renderElement (
1216- timeline ( settled , {
1217- isWorking : true ,
1218- latestRun : { runId : firstRun , status : "running" , startedAt : at ( 0 ) , completedAt : null } ,
1219- } ) ,
1220- ) ;
1221- await screen . rerender (
1222- timeline ( settled , {
1223- latestRun : { runId : firstRun , status : "interrupted" , startedAt : at ( 0 ) , completedAt : at ( 9 ) } ,
1224- } ) ,
1225- ) ;
1226- expect ( screen . button ( / ^ Y o u s t o p p e d a f t e r / ) . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
1157+ await using screen = await renderElement ( timeline ( props , running ) ) ;
1158+ await screen . rerender ( timeline ( props , interrupted ) ) ;
12271159
1228- await screen . rerender (
1229- timeline (
1230- [
1231- ...settled ,
1232- message (
1233- "Follow-up" ,
1234- { runId : secondRun , inputIntent : "turn_start" , createdAt : at ( 20 ) , updatedAt : at ( 20 ) } ,
1235- "user-2" ,
1236- ) ,
1237- ] ,
1238- {
1239- isWorking : true ,
1240- latestRun : { runId : secondRun , status : "running" , startedAt : at ( 21 ) , completedAt : null } ,
1241- } ,
1242- ) ,
1243- ) ;
1160+ await screen . rerender ( timeline ( props , nextRunStarted ) ) ;
12441161
12451162 expect ( screen . button ( / ^ W o r k e d f o r / ) . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
12461163 expect ( screen . text ( ) ) . toContain ( "Interim progress note" ) ;
0 commit comments