@@ -2241,6 +2241,190 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
22412241 }
22422242 } ) ;
22432243
2244+ it ( "keeps managed image actions anchored around tiny rendered images" , async ( ) => {
2245+ const page = await openBrowserPage ( 1280 , 900 ) ;
2246+ try {
2247+ await page . setContent (
2248+ `<!doctype html><html><head><style>${ readUiCss ( ) } </style></head><body>
2249+ <div class="chat-message-images">
2250+ <span class="chat-image-frame chat-image-frame--managed">
2251+ <button class="chat-message-image-button" type="button">
2252+ <img
2253+ class="chat-message-image chat-message-image--small"
2254+ width="16"
2255+ height="16"
2256+ alt="Tiny generated image"
2257+ src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='16' height='16' fill='%23dc4f92'/%3E%3C/svg%3E"
2258+ />
2259+ </button>
2260+ <span class="chat-image-actions">
2261+ <button class="chat-image-action" type="button">1</button>
2262+ <button class="chat-image-action" type="button">2</button>
2263+ </span>
2264+ </span>
2265+ <span class="chat-image-frame chat-image-frame--managed">
2266+ <button class="chat-message-image-button" type="button">
2267+ <img
2268+ class="chat-message-image"
2269+ width="420"
2270+ height="1800"
2271+ alt="Tall generated image"
2272+ src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='1800'%3E%3Crect width='420' height='1800' fill='%235c86ff'/%3E%3C/svg%3E"
2273+ />
2274+ </button>
2275+ <span class="chat-image-actions">
2276+ <button class="chat-image-action" type="button">1</button>
2277+ <button class="chat-image-action" type="button">2</button>
2278+ </span>
2279+ </span>
2280+ </div>
2281+ </body></html>` ,
2282+ ) ;
2283+ const frames = page . locator ( ".chat-image-frame--managed" ) ;
2284+ await expect . poll ( ( ) => frames . count ( ) ) . toBe ( 2 ) ;
2285+ const frameRows = await frames . evaluateAll ( ( elements ) =>
2286+ elements . map ( ( element ) => {
2287+ const box = element . getBoundingClientRect ( ) ;
2288+ return { bottom : box . bottom , top : box . top } ;
2289+ } ) ,
2290+ ) ;
2291+ expect ( frameRows [ 1 ] ! . top ) . toBeGreaterThan ( frameRows [ 0 ] ! . bottom ) ;
2292+ for ( const [ index , expectedWidth ] of [ 160 , 84 ] . entries ( ) ) {
2293+ const frame = frames . nth ( index ) ;
2294+ await frame . hover ( ) ;
2295+ await expect
2296+ . poll ( ( ) => frame . evaluate ( ( element ) => getComputedStyle ( element , "::after" ) . opacity ) )
2297+ . toBe ( "1" ) ;
2298+ const geometry = await frame . evaluate ( ( element ) => {
2299+ const actions = element . querySelector < HTMLElement > ( ".chat-image-actions" ) ! ;
2300+ const frameRect = element . getBoundingClientRect ( ) ;
2301+ const actionsRect = actions . getBoundingClientRect ( ) ;
2302+ return {
2303+ actionsInsideFrame :
2304+ actionsRect . left >= frameRect . left &&
2305+ actionsRect . right <= frameRect . right &&
2306+ actionsRect . top >= frameRect . top &&
2307+ actionsRect . bottom <= frameRect . bottom ,
2308+ actionsNearBottom : frameRect . bottom - actionsRect . bottom <= 9 ,
2309+ fadeWidth : Number . parseFloat ( getComputedStyle ( element , "::after" ) . width ) ,
2310+ frameWidth : frameRect . width ,
2311+ overflow : getComputedStyle ( element ) . overflow ,
2312+ } ;
2313+ } ) ;
2314+ expect ( geometry . actionsInsideFrame ) . toBe ( true ) ;
2315+ expect ( geometry . actionsNearBottom ) . toBe ( true ) ;
2316+ expect ( geometry . fadeWidth ) . toBeCloseTo ( geometry . frameWidth , 0 ) ;
2317+ expect ( geometry . frameWidth ) . toBeCloseTo ( expectedWidth , 0 ) ;
2318+ expect ( geometry . overflow ) . toBe ( "hidden" ) ;
2319+ }
2320+ } finally {
2321+ await closeBrowserPage ( page ) ;
2322+ }
2323+ } ) ;
2324+
2325+ it ( "places a five-image sent gallery above its separate text bubble" , async ( ) => {
2326+ const page = await openBrowserPage ( 1280 , 900 ) ;
2327+ try {
2328+ const tile = ( index : number ) => `
2329+ <span class="chat-image-frame" data-tile="${ index } ">
2330+ <button class="chat-message-image-button" type="button">
2331+ <img class="chat-message-image" width="640" height="640" alt="Image ${ index } "
2332+ src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Crect width='640' height='640' fill='%23865cff'/%3E%3C/svg%3E" />
2333+ </button>
2334+ </span>` ;
2335+ await page . setContent (
2336+ `<!doctype html><html><head><style>${ readUiCss ( ) } </style></head><body>
2337+ <div class="chat-group user">
2338+ <div class="chat-bubble chat-bubble--with-images">
2339+ <div
2340+ class="chat-message-images chat-message-images--gallery chat-message-images--five"
2341+ >
2342+ ${ Array . from ( { length : 5 } , ( _ , index ) => tile ( index + 1 ) ) . join ( "" ) }
2343+ </div>
2344+ <div class="chat-text">oi</div>
2345+ </div>
2346+ </div>
2347+ </body></html>` ,
2348+ ) ;
2349+ await page . locator ( ".chat-message-image" ) . first ( ) . waitFor ( ) ;
2350+ const geometry = await page . locator ( ".chat-bubble" ) . evaluate ( ( bubble ) => {
2351+ const gallery = bubble . querySelector < HTMLElement > ( ".chat-message-images" ) ! ;
2352+ const text = bubble . querySelector < HTMLElement > ( ".chat-text" ) ! ;
2353+ const frames = [ ...gallery . querySelectorAll < HTMLElement > ( ".chat-image-frame" ) ] ;
2354+ const boxes = frames . map ( ( frame ) => frame . getBoundingClientRect ( ) ) ;
2355+ const galleryBox = gallery . getBoundingClientRect ( ) ;
2356+ const textBox = text . getBoundingClientRect ( ) ;
2357+ return {
2358+ background : getComputedStyle ( bubble ) . backgroundColor ,
2359+ firstRow : boxes . filter ( ( box ) => Math . round ( box . top ) === Math . round ( boxes [ 0 ] ! . top ) ) . length ,
2360+ fourthAlignedWithSecond : Math . abs ( boxes [ 3 ] ! . left - boxes [ 1 ] ! . left ) <= 1 ,
2361+ lastRowRightAligned : Math . abs ( boxes [ 4 ] ! . right - galleryBox . right ) <= 1 ,
2362+ textBelow : textBox . top >= galleryBox . bottom + 7 ,
2363+ textRightAligned : Math . abs ( textBox . right - galleryBox . right ) <= 1 ,
2364+ tileSize : boxes [ 0 ] ! . width ,
2365+ } ;
2366+ } ) ;
2367+ expect ( geometry ) . toMatchObject ( {
2368+ background : "rgba(0, 0, 0, 0)" ,
2369+ firstRow : 3 ,
2370+ fourthAlignedWithSecond : true ,
2371+ lastRowRightAligned : true ,
2372+ textBelow : true ,
2373+ textRightAligned : true ,
2374+ } ) ;
2375+ expect ( geometry . tileSize ) . toBeCloseTo ( 128 , 0 ) ;
2376+ } finally {
2377+ await closeBrowserPage ( page ) ;
2378+ }
2379+ } ) ;
2380+
2381+ it ( "keeps every sent-image text shape on the user bubble surface" , async ( ) => {
2382+ const page = await openBrowserPage ( 1280 , 900 ) ;
2383+ try {
2384+ await page . setContent (
2385+ `<!doctype html><html><head><style>${ readUiCss ( ) } </style></head><body>
2386+ <div class="chat-group user">
2387+ <div class="chat-bubble chat-bubble--with-images">
2388+ <div class="chat-text" data-shape="text">Short text</div>
2389+ </div>
2390+ <div class="chat-bubble chat-bubble--with-images">
2391+ <div class="chat-message-disclosure" data-shape="disclosure">
2392+ <div class="chat-message-disclosure__content">
2393+ <div class="chat-text">Collapsed text</div>
2394+ </div>
2395+ </div>
2396+ </div>
2397+ <div class="chat-bubble chat-bubble--with-images">
2398+ <details class="chat-json-collapse" data-shape="json">
2399+ <summary class="chat-json-summary">JSON</summary>
2400+ </details>
2401+ </div>
2402+ </div>
2403+ </body></html>` ,
2404+ ) ;
2405+ for ( const theme of [ "dark" , "light" ] as const ) {
2406+ await page . evaluate (
2407+ ( mode ) => document . documentElement . setAttribute ( "data-theme-mode" , mode ) ,
2408+ theme ,
2409+ ) ;
2410+ const surfaces = await page . locator ( "[data-shape]" ) . evaluateAll ( ( elements ) =>
2411+ elements . map ( ( element ) => {
2412+ const style = getComputedStyle ( element ) ;
2413+ return {
2414+ backgroundColor : style . backgroundColor ,
2415+ padding : style . padding ,
2416+ } ;
2417+ } ) ,
2418+ ) ;
2419+ expect ( surfaces [ 0 ] ) . toMatchObject ( { padding : "10px 14px" } ) ;
2420+ expect ( surfaces [ 1 ] ) . toEqual ( surfaces [ 0 ] ) ;
2421+ expect ( surfaces [ 2 ] ) . toEqual ( surfaces [ 0 ] ) ;
2422+ }
2423+ } finally {
2424+ await closeBrowserPage ( page ) ;
2425+ }
2426+ } ) ;
2427+
22442428 it ( "wraps long question and approval metadata inside narrow cards" , async ( ) => {
22452429 const page = await openBrowserPage ( 320 , 568 ) ;
22462430 try {
0 commit comments