@@ -1419,6 +1419,85 @@ test.describe('Dashboard', { tag: ['@dashboard'] }, () => {
14191419 } ,
14201420 ) ;
14211421
1422+ test (
1423+ 'replay search keeps a multi-line SQL where after the search page rewrites the URL' ,
1424+ { tag : '@full-stack' } ,
1425+ async ( ) => {
1426+ const chartName = `E2E Multiline Replay Tile ${ Date . now ( ) } ` ;
1427+ // The line break must be the only whitespace between the two tokens: the
1428+ // browser strips raw newlines from URLs but keeps spaces, so an indented
1429+ // second line would survive the bug as valid SQL.
1430+ const whereLines = [ "ServiceName != '' AND" , "SeverityText != ''" ] ;
1431+ const multilineWhere = whereLines . join ( '\n' ) ;
1432+
1433+ await test . step ( 'Save a builder tile with a multi-line SQL where' , async ( ) => {
1434+ await dashboardPage . createNewDashboard ( ) ;
1435+ await dashboardPage . addTile ( ) ;
1436+ await expect ( dashboardPage . chartEditor . nameInput ) . toBeVisible ( ) ;
1437+ await dashboardPage . chartEditor . waitForDataToLoad ( ) ;
1438+ await dashboardPage . chartEditor . setChartType ( DisplayType . Line ) ;
1439+ await dashboardPage . chartEditor . setChartName ( chartName ) ;
1440+ await dashboardPage . chartEditor . selectSource ( DEFAULT_LOGS_SOURCE_NAME ) ;
1441+ await dashboardPage . chartEditor . setMultilineSqlWhere ( whereLines ) ;
1442+ await dashboardPage . chartEditor . runQuery ( ) ;
1443+ await dashboardPage . saveTile ( ) ;
1444+ } ) ;
1445+
1446+ const tile = dashboardPage . getTiles ( ) . filter ( { hasText : chartName } ) ;
1447+ const replayButton = tile . locator (
1448+ '[data-testid^="tile-replay-search-button-"]' ,
1449+ ) ;
1450+
1451+ await test . step ( 'The replay link carries the where with its line break' , async ( ) => {
1452+ await tile . hover ( ) ;
1453+ await expect ( replayButton ) . toBeVisible ( ) ;
1454+ const href = String ( await replayButton . getAttribute ( 'href' ) ) ;
1455+ const where = String (
1456+ new URL ( href , 'http://localhost' ) . searchParams . get ( 'where' ) ,
1457+ ) ;
1458+ expect ( decodeURIComponent ( where ) ) . toBe ( multilineWhere ) ;
1459+ } ) ;
1460+
1461+ await test . step ( 'Changing the time range on the search page keeps the line break' , async ( ) => {
1462+ const popupPromise = dashboardPage . page . waitForEvent ( 'popup' ) ;
1463+ await replayButton . click ( ) ;
1464+ const searchTab = await popupPromise ;
1465+ const searchPage = new SearchPage ( searchTab ) ;
1466+ const readWhere = ( ) =>
1467+ decodeURIComponent (
1468+ new URL ( searchTab . url ( ) ) . searchParams . get ( 'where' ) ?? '' ,
1469+ ) ;
1470+
1471+ await expect ( searchTab ) . toHaveURL ( / \/ s e a r c h \? / , { timeout : 15000 } ) ;
1472+ await expect ( searchPage . table . firstRow ) . toBeVisible ( {
1473+ timeout : 30000 ,
1474+ } ) ;
1475+ const landedFrom = new URL ( searchTab . url ( ) ) . searchParams . get ( 'from' ) ;
1476+
1477+ // A nuqs write that doesn't touch `where` rebuilds the whole query
1478+ // string from the decoded params. A single-encoded `where` comes back
1479+ // with a raw newline that the browser strips, joining the lines.
1480+ await searchPage . timePicker . selectRelativeTime ( 'Last 1 days' ) ;
1481+ await expect
1482+ . poll ( ( ) => new URL ( searchTab . url ( ) ) . searchParams . get ( 'from' ) , {
1483+ timeout : 10000 ,
1484+ } )
1485+ . not . toBe ( landedFrom ) ;
1486+
1487+ expect ( readWhere ( ) ) . toBe ( multilineWhere ) ;
1488+ await expect (
1489+ searchPage . whereInput . sqlEditor . locator ( '.cm-line' ) ,
1490+ ) . toHaveCount ( 2 ) ;
1491+ await expect ( searchPage . table . firstRow ) . toBeVisible ( {
1492+ timeout : 30000 ,
1493+ } ) ;
1494+ await expect ( searchPage . chartErrorState ) . toHaveCount ( 0 ) ;
1495+
1496+ await searchTab . close ( ) ;
1497+ } ) ;
1498+ } ,
1499+ ) ;
1500+
14221501 test . describe ( 'Raw SQL Dashboard Tiles' , ( ) => {
14231502 const LINE_SQL = `SELECT toStartOfInterval(Timestamp, INTERVAL {intervalSeconds:Int64} SECOND) AS ts, count() AS count FROM default.e2e_otel_logs WHERE Timestamp >= fromUnixTimestamp64Milli({startDateMilliseconds:Int64}) AND Timestamp < fromUnixTimestamp64Milli({endDateMilliseconds:Int64}) GROUP BY ts ORDER BY ts ASC` ;
14241503
@@ -2286,7 +2365,11 @@ test.describe('Dashboard', { tag: ['@dashboard'] }, () => {
22862365
22872366 const href = ( await link . getAttribute ( 'href' ) ) ?? '' ;
22882367 const params = new URL ( href , 'http://localhost' ) . searchParams ;
2289- expect ( params . get ( 'where' ) ) . toBe ( "(ServiceName IN ('accounting'))" ) ;
2368+ // The search page reads `where` with nuqs (double-encoded), so decode
2369+ // the extra layer before asserting on the expanded predicate.
2370+ expect ( decodeURIComponent ( params . get ( 'where' ) ?? '' ) ) . toBe (
2371+ "(ServiceName IN ('accounting'))" ,
2372+ ) ;
22902373 expect ( decodeURIComponent ( href ) ) . not . toContain ( '$svc' ) ;
22912374 } ) ;
22922375
@@ -2301,9 +2384,11 @@ test.describe('Dashboard', { tag: ['@dashboard'] }, () => {
23012384 const searchPage = new SearchPage ( searchTab ) ;
23022385
23032386 await expect ( searchTab ) . toHaveURL ( / \/ s e a r c h \? / , { timeout : 15000 } ) ;
2304- expect ( new URL ( searchTab . url ( ) ) . searchParams . get ( 'where' ) ) . toBe (
2305- "(ServiceName IN ('accounting'))" ,
2306- ) ;
2387+ expect (
2388+ decodeURIComponent (
2389+ new URL ( searchTab . url ( ) ) . searchParams . get ( 'where' ) ?? '' ,
2390+ ) ,
2391+ ) . toBe ( "(ServiceName IN ('accounting'))" ) ;
23072392
23082393 await expect ( searchPage . table . firstRow ) . toBeVisible ( {
23092394 timeout : 30000 ,
0 commit comments