@@ -6,6 +6,7 @@ import type { MessageGroup } from "../../../lib/chat/chat-types.ts";
66import { normalizeMessage } from "../../../lib/chat/message-normalizer.ts" ;
77import { setUiTimeFormatPreference } from "../../../lib/format.ts" ;
88import {
9+ formatChatRelativeTimestampLabel ,
910 formatChatTimestampForDisplay ,
1011 renderMessageGroup ,
1112 renderStreamGroup ,
@@ -905,7 +906,10 @@ describe("grouped chat rendering", () => {
905906 const time = container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ;
906907 expect ( time ) . not . toBeNull ( ) ;
907908 expect ( time ?. closest ( "details.msg-meta" ) ) . toBeNull ( ) ;
908- expect ( time ?. title ) . not . toBe ( "" ) ;
909+ // Absolute time lives in the styled tooltip around the relative label.
910+ expect ( time ?. closest ( "openclaw-tooltip" ) ?. getAttribute ( "content" ) ) . toBe (
911+ formatChatTimestampForDisplay ( 1000 ) . label ,
912+ ) ;
909913 } ) ;
910914
911915 it ( "uses the largest single assistant call for grouped context usage" , ( ) => {
@@ -934,36 +938,71 @@ describe("grouped chat rendering", () => {
934938 expect ( container . querySelector ( ".msg-meta__tokens" ) ?. textContent ) . toBe ( "↑214.5k" ) ;
935939 } ) ;
936940
937- it ( "renders full dates with message and streaming timestamps" , ( ) => {
938- const container = document . createElement ( "div" ) ;
939- const timestamp = Date . UTC ( 2026 , 3 , 24 , 18 , 30 ) ;
941+ it ( "renders relative labels with absolute datetimes for message and streaming timestamps" , ( ) => {
942+ vi . useFakeTimers ( ) ;
943+ try {
944+ const timestamp = Date . UTC ( 2026 , 3 , 24 , 18 , 30 ) ;
945+ vi . setSystemTime ( timestamp + 5 * 60 * 1000 ) ;
946+ const container = document . createElement ( "div" ) ;
940947
941- renderAssistantMessage ( container , {
942- role : "assistant" ,
943- content : "Done" ,
944- timestamp,
945- } ) ;
948+ renderAssistantMessage ( container , {
949+ role : "assistant" ,
950+ content : "Done" ,
951+ timestamp,
952+ } ) ;
946953
947- const time = container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ;
948- const display = formatChatTimestampForDisplay ( timestamp ) ;
949- expect ( time ?. dateTime ) . toBe ( display . dateTime ) ;
950- expect ( time ?. textContent ?. trim ( ) ) . toBe ( display . label ) ;
954+ const time = container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ;
955+ const display = formatChatTimestampForDisplay ( timestamp ) ;
956+ expect ( time ?. dateTime ) . toBe ( display . dateTime ) ;
957+ expect ( time ?. textContent ?. trim ( ) ) . toBe ( "5m ago" ) ;
951958
952- render (
953- renderStreamGroup ( [
954- {
955- kind : "stream" ,
956- key : `stream:${ timestamp } ` ,
957- text : "Working" ,
958- startedAt : timestamp ,
959- isStreaming : true ,
960- } ,
961- ] ) ,
962- container ,
959+ render (
960+ renderStreamGroup ( [
961+ {
962+ kind : "stream" ,
963+ key : `stream:${ timestamp } ` ,
964+ text : "Working" ,
965+ startedAt : timestamp ,
966+ isStreaming : true ,
967+ } ,
968+ ] ) ,
969+ container ,
970+ ) ;
971+
972+ const streamingTime = container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ;
973+ expect ( streamingTime ?. textContent ?. trim ( ) ) . toBe ( "5m ago" ) ;
974+ } finally {
975+ vi . useRealTimers ( ) ;
976+ }
977+ } ) ;
978+
979+ it ( "falls back to compact dates for footer labels older than a week" , ( ) => {
980+ const timestamp = Date . UTC ( 2026 , 3 , 24 , 18 , 30 ) ;
981+ const sameYearNow = Date . UTC ( 2026 , 5 , 24 , 18 , 30 ) ;
982+ const nextYearNow = Date . UTC ( 2027 , 0 , 2 , 18 , 30 ) ;
983+ expect ( formatChatRelativeTimestampLabel ( timestamp , sameYearNow ) ) . toBe (
984+ new Date ( timestamp ) . toLocaleDateString ( [ ] , { month : "short" , day : "numeric" } ) ,
985+ ) ;
986+ expect ( formatChatRelativeTimestampLabel ( timestamp , nextYearNow ) ) . toBe (
987+ new Date ( timestamp ) . toLocaleDateString ( [ ] , {
988+ month : "short" ,
989+ day : "numeric" ,
990+ year : "numeric" ,
991+ } ) ,
963992 ) ;
993+ } ) ;
964994
965- const streamingTime = container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ;
966- expect ( streamingTime ?. textContent ?. trim ( ) ) . toBe ( display . label ) ;
995+ it ( "clamps skewed-future footer labels but dates far-future ones" , ( ) => {
996+ const nowMs = Date . UTC ( 2026 , 3 , 24 , 18 , 30 ) ;
997+ expect ( formatChatRelativeTimestampLabel ( nowMs + 30 * 1000 , nowMs ) ) . toBe ( "just now" ) ;
998+ const nextYear = Date . UTC ( 2027 , 3 , 24 , 18 , 30 ) ;
999+ expect ( formatChatRelativeTimestampLabel ( nextYear , nowMs ) ) . toBe (
1000+ new Date ( nextYear ) . toLocaleDateString ( [ ] , {
1001+ month : "short" ,
1002+ day : "numeric" ,
1003+ year : "numeric" ,
1004+ } ) ,
1005+ ) ;
9671006 } ) ;
9681007
9691008 it ( "omits streaming bubble class for completed stream segments" , ( ) => {
@@ -1039,9 +1078,8 @@ describe("grouped chat rendering", () => {
10391078 // One bubble per segment, all under the single group.
10401079 expect ( container . querySelectorAll ( ".chat-bubble" ) ) . toHaveLength ( 3 ) ;
10411080 // Footer time anchors to the earliest segment start, not render order.
1042- const display = formatChatTimestampForDisplay ( 10 ) ;
1043- expect ( container . querySelector ( ".chat-group-timestamp" ) ?. textContent ?. trim ( ) ) . toBe (
1044- display . label ,
1081+ expect ( container . querySelector < HTMLTimeElement > ( ".chat-group-timestamp" ) ?. dateTime ) . toBe (
1082+ formatChatTimestampForDisplay ( 10 ) . dateTime ,
10451083 ) ;
10461084 } ) ;
10471085
0 commit comments