44 * Root cause: the drag-and-drop wrapper div introduced with attachments had
55 * no CSS class when not dragging, so no flex rule applied and the chat body
66 * collapsed to content height instead of filling the window.
7- *
8- * Run against popup variant: EXAMPLE=form-filling pnpm test
9- * Run against sidebar variant: EXAMPLE=chat-with-your-data pnpm test
107 */
118import { test , expect } from "@playwright/test" ;
129
1310const EXAMPLE = process . env . EXAMPLE ?? "form-filling" ;
1411
15- const SUPPORTED = [ "form-filling" , "chat-with-your-data" ] ;
16-
1712test . describe ( "chat window layout" , ( ) => {
18- test . skip ( ! SUPPORTED . includes ( EXAMPLE ) , `EXAMPLE=${ EXAMPLE } ` ) ;
13+ test . skip ( EXAMPLE !== "form-filling" , `EXAMPLE=${ EXAMPLE } ` ) ;
1914
2015 test . beforeEach ( async ( { page } ) => {
2116 await page . goto ( "/" ) ;
22- // Wait for the page to hydrate before checking state
23- await page . locator ( ".copilotKitButton" ) . waitFor ( { timeout : 10_000 } ) ;
24- // Both form-filling and chat-with-your-data use defaultOpen — only click if not already open
25- const alreadyOpen = await page
26- . locator ( ".copilotKitWindow.open" )
27- . isVisible ( )
28- . catch ( ( ) => false ) ;
29- if ( ! alreadyOpen ) {
30- await page . locator ( ".copilotKitButton" ) . click ( ) ;
31- }
17+ // form-filling uses defaultOpen — window is already open after hydration
3218 await page . locator ( ".copilotKitWindow.open" ) . waitFor ( { timeout : 10_000 } ) ;
3319 } ) ;
3420
35- test ( "chat body fills the window (flex-grow invariant) " , async ( { page } ) => {
21+ test ( "chat body fills the window" , async ( { page } ) => {
3622 const chatBody = page . locator ( ".copilotKitChatBody" ) ;
3723 const window = page . locator ( ".copilotKitWindow" ) ;
3824
39- // Direct class invariant — catches "wrapper exists but doesn't grow"
4025 await expect ( chatBody ) . toHaveCSS ( "flex" , "1 1 0%" ) ;
4126
4227 const bodyBox = await chatBody . boundingBox ( ) ;
4328 const windowBox = await window . boundingBox ( ) ;
4429 expect ( bodyBox ) . not . toBeNull ( ) ;
4530 expect ( windowBox ) . not . toBeNull ( ) ;
46- // Body should fill at least 80% of window height (header takes the rest)
4731 expect ( bodyBox ! . height ) . toBeGreaterThan ( windowBox ! . height * 0.8 ) ;
4832 } ) ;
4933
50- test ( "messages area fills available space and does not collapse" , async ( {
51- page,
52- } ) => {
34+ test ( "messages area fills available space" , async ( { page } ) => {
5335 const messages = page . locator ( ".copilotKitMessages" ) ;
5436 const window = page . locator ( ".copilotKitWindow" ) ;
5537
5638 const messagesBox = await messages . boundingBox ( ) ;
5739 const windowBox = await window . boundingBox ( ) ;
5840 expect ( messagesBox ) . not . toBeNull ( ) ;
5941 expect ( windowBox ) . not . toBeNull ( ) ;
60- // Collapsed height in the broken version was ~184px regardless of window size
6142 expect ( messagesBox ! . height ) . toBeGreaterThan ( windowBox ! . height * 0.5 ) ;
6243 expect ( messagesBox ! . height ) . toBeLessThanOrEqual ( windowBox ! . height ) ;
6344 } ) ;
@@ -79,18 +60,19 @@ test.describe("chat window layout", () => {
7960 test ( "drag state does not break layout" , async ( { page } ) => {
8061 const chatBody = page . locator ( ".copilotKitChatBody" ) ;
8162 const messages = page . locator ( ".copilotKitMessages" ) ;
63+ const window = page . locator ( ".copilotKitWindow" ) ;
8264
83- // Simulate dragenter on the wrapper itself — more robust than targeting the window
8465 await page . evaluate ( ( ) => {
8566 const body = document . querySelector ( ".copilotKitChatBody" ) ;
8667 body ?. dispatchEvent ( new DragEvent ( "dragenter" , { bubbles : true } ) ) ;
8768 } ) ;
8869
89- // Flex-grow must hold in drag state too
90- await expect ( chatBody ) . toHaveCSS ( "flex-grow" , "1" ) ;
70+ await expect ( chatBody ) . toHaveCSS ( "flex" , "1 1 0%" ) ;
9171
9272 const messagesBox = await messages . boundingBox ( ) ;
73+ const windowBox = await window . boundingBox ( ) ;
9374 expect ( messagesBox ) . not . toBeNull ( ) ;
94- expect ( messagesBox ! . height ) . toBeGreaterThan ( 200 ) ;
75+ expect ( windowBox ) . not . toBeNull ( ) ;
76+ expect ( messagesBox ! . height ) . toBeGreaterThan ( windowBox ! . height * 0.5 ) ;
9577 } ) ;
9678} ) ;
0 commit comments