@@ -1515,3 +1515,69 @@ describe("createDashboardViewRenderer", () => {
15151515 } ) ;
15161516 } ) ;
15171517} ) ;
1518+
1519+ // ===========================================================================
1520+ // formatTimestamp branch coverage
1521+ // Tests for the three branches in formatTimestamp (internal helper):
1522+ // - < 2 days: HH:MM
1523+ // - 2-30 days: MM/DD
1524+ // - > 30 days: Mon DD
1525+ // These are exercised by formatting dashboards with appropriate time spans.
1526+ // ===========================================================================
1527+
1528+ describe ( "formatDashboardWithData — time axis formats" , ( ) => {
1529+ usePlainMode ( ) ;
1530+
1531+ /**
1532+ * Create a time series spanning the given number of days, centered around
1533+ * 2024-01-15. Returns a TimeseriesResult whose timestamps span enough range
1534+ * to trigger the right formatTimestamp branch.
1535+ */
1536+ function makeSpannedTimeseries ( days : number ) : TimeseriesResult {
1537+ const now = new Date ( "2024-01-15T12:00:00Z" ) . getTime ( ) / 1000 ;
1538+ const start = now - days * 24 * 3600 ;
1539+ const numPoints = 5 ;
1540+ const step = ( days * 24 * 3600 ) / numPoints ;
1541+ const values = Array . from ( { length : numPoints + 1 } , ( _ , i ) => ( {
1542+ timestamp : start + i * step ,
1543+ value : Math . floor ( Math . random ( ) * 100 ) ,
1544+ } ) ) ;
1545+ return {
1546+ type : "timeseries" ,
1547+ series : [ { label : "count()" , values } ] ,
1548+ } ;
1549+ }
1550+
1551+ test ( "renders time axis with MM/DD format for 7-day span" , ( ) => {
1552+ const data = makeDashboardData ( {
1553+ period : "7d" ,
1554+ widgets : [
1555+ // layout.h=2 → totalHeight=12, contentHeight=10 >= 8 → renderTimeseriesBarsContent
1556+ makeWidget ( {
1557+ displayType : "line" ,
1558+ layout : { x : 0 , y : 0 , w : 6 , h : 2 } ,
1559+ data : makeSpannedTimeseries ( 7 ) ,
1560+ } ) ,
1561+ ] ,
1562+ } ) ;
1563+ const output = formatDashboardWithData ( data ) ;
1564+ // 7-day span → MM/DD format like "01/15"
1565+ expect ( output ) . toMatch ( / \d { 2 } \/ \d { 2 } / ) ;
1566+ } ) ;
1567+
1568+ test ( "renders time axis with Mon DD format for 90-day span" , ( ) => {
1569+ const data = makeDashboardData ( {
1570+ period : "90d" ,
1571+ widgets : [
1572+ makeWidget ( {
1573+ displayType : "line" ,
1574+ layout : { x : 0 , y : 0 , w : 6 , h : 2 } ,
1575+ data : makeSpannedTimeseries ( 90 ) ,
1576+ } ) ,
1577+ ] ,
1578+ } ) ;
1579+ const output = formatDashboardWithData ( data ) ;
1580+ // 90-day span → "Jan 15" style format
1581+ expect ( output ) . toMatch ( / J a n | F e b | M a r | A p r | M a y | J u n | J u l | A u g | S e p | O c t | N o v | D e c / ) ;
1582+ } ) ;
1583+ } ) ;
0 commit comments