11import { expect , test } from "@playwright/test" ;
22import {
33 DONOR_EMAIL ,
4+ HOST_EMAIL ,
5+ HOST_SECOND_SEEDED_THREAD_ID ,
6+ SECOND_SEEDED_THREAD_ID ,
47 SEEDED_THREAD_ID ,
58 delayChatSendRequests ,
69 failChatSendRequests ,
@@ -10,6 +13,20 @@ import {
1013test ( "chat loads the seeded thread and composer for a signed-in donor" , async ( {
1114 page,
1215} ) => {
16+ const maxUpdateDepthErrors : string [ ] = [ ] ;
17+ const recordMaxUpdateDepthError = ( message : string ) => {
18+ if ( message . includes ( "Maximum update depth exceeded" ) ) {
19+ maxUpdateDepthErrors . push ( message ) ;
20+ }
21+ } ;
22+
23+ page . on ( "console" , ( message ) => {
24+ recordMaxUpdateDepthError ( message . text ( ) ) ;
25+ } ) ;
26+ page . on ( "pageerror" , ( error ) => {
27+ recordMaxUpdateDepthError ( error . message ) ;
28+ } ) ;
29+
1330 await signIn ( page , {
1431 email : DONOR_EMAIL ,
1532 redirectTo : `/chats/${ SEEDED_THREAD_ID } ` ,
@@ -25,6 +42,61 @@ test("chat loads the seeded thread and composer for a signed-in donor", async ({
2542 ) ;
2643 await expect ( page . getByTestId ( "chat-composer" ) ) . toBeVisible ( ) ;
2744 await expect ( page . getByTestId ( "chat-composer-input" ) ) . toBeVisible ( ) ;
45+ await page
46+ . getByTestId ( "thread-list" )
47+ . evaluate ( ( element ) => element . setAttribute ( "data-persist-check" , "true" ) ) ;
48+
49+ await page . getByTestId ( `thread-preview-${ SECOND_SEEDED_THREAD_ID } ` ) . click ( ) ;
50+ await expect ( page ) . toHaveURL (
51+ new RegExp ( `/chats/${ SECOND_SEEDED_THREAD_ID } $` )
52+ ) ;
53+ await expect ( page . getByTestId ( "thread-list" ) ) . toHaveAttribute (
54+ "data-persist-check" ,
55+ "true"
56+ ) ;
57+ await expect ( page . getByTestId ( "chat-message-list" ) ) . toContainText (
58+ "Hi Morgan, are banana peels okay if they are chopped up?"
59+ ) ;
60+ await expect ( page . getByTestId ( "chat-message-list" ) ) . toContainText (
61+ "Yes please. Chopped scraps break down much faster in this bay."
62+ ) ;
63+
64+ await page . getByTestId ( `thread-preview-${ SEEDED_THREAD_ID } ` ) . click ( ) ;
65+ await expect ( page ) . toHaveURL ( new RegExp ( `/chats/${ SEEDED_THREAD_ID } $` ) ) ;
66+ await expect ( page . getByTestId ( "chat-message-list" ) ) . toContainText (
67+ "Yes, absolutely. Small sealed containers are perfect."
68+ ) ;
69+
70+ await page . waitForTimeout ( 250 ) ;
71+ expect ( maxUpdateDepthErrors ) . toEqual ( [ ] ) ;
72+ } ) ;
73+
74+ test ( "chat lists multiple seeded threads for a signed-in host" , async ( {
75+ page,
76+ } ) => {
77+ await signIn ( page , {
78+ email : HOST_EMAIL ,
79+ redirectTo : `/chats/${ SEEDED_THREAD_ID } ` ,
80+ } ) ;
81+
82+ await expect ( page ) . toHaveURL ( new RegExp ( `/chats/${ SEEDED_THREAD_ID } $` ) ) ;
83+ await expect ( page . getByTestId ( "thread-list" ) ) . toBeVisible ( ) ;
84+ await expect (
85+ page . getByTestId ( `thread-preview-${ HOST_SECOND_SEEDED_THREAD_ID } ` )
86+ ) . toContainText ( "Morgan" ) ;
87+
88+ await page
89+ . getByTestId ( `thread-preview-${ HOST_SECOND_SEEDED_THREAD_ID } ` )
90+ . click ( ) ;
91+ await expect ( page ) . toHaveURL (
92+ new RegExp ( `/chats/${ HOST_SECOND_SEEDED_THREAD_ID } $` )
93+ ) ;
94+ await expect ( page . getByTestId ( "chat-message-list" ) ) . toContainText (
95+ "Hi Avery, can the cafe take a few buckets from our community garden working bee?"
96+ ) ;
97+ await expect ( page . getByTestId ( "chat-message-list" ) ) . toContainText (
98+ "Yes, drop them by after 3 pm and I'll add them to the cafe pickup."
99+ ) ;
28100} ) ;
29101
30102test ( "chat send disables the composer while pending and appends the new message" , async ( {
@@ -40,7 +112,9 @@ test("chat send disables the composer while pending and appends the new message"
40112 const sendButton = page . getByTestId ( "chat-composer-send" ) ;
41113 const message = `Playwright chat message ${ Date . now ( ) } ` ;
42114
43- await composerInput . fill ( message ) ;
115+ await composerInput . click ( ) ;
116+ await composerInput . pressSequentially ( message ) ;
117+ await expect ( sendButton ) . toBeEnabled ( ) ;
44118
45119 const messageVisible = page
46120 . getByTestId ( "chat-message-list" )
@@ -65,7 +139,9 @@ test("chat send failures preserve the draft and show inline feedback", async ({
65139 const composerInput = page . getByTestId ( "chat-composer-input" ) ;
66140 const failedMessage = `Chat failure draft ${ Date . now ( ) } ` ;
67141
68- await composerInput . fill ( failedMessage ) ;
142+ await composerInput . click ( ) ;
143+ await composerInput . pressSequentially ( failedMessage ) ;
144+ await expect ( page . getByTestId ( "chat-composer-send" ) ) . toBeEnabled ( ) ;
69145 await page . getByTestId ( "chat-composer-send" ) . click ( ) ;
70146
71147 await expect ( composerInput ) . toHaveValue ( failedMessage ) ;
0 commit comments