1414 * limitations under the License.
1515 */
1616
17- import { test , expect } from '@playwright/test' ;
17+ import { test , expect , type Page } from '@playwright/test' ;
1818import {
1919 loginAsUser ,
2020 BASE_URL ,
@@ -23,6 +23,14 @@ import {
2323 resetUserData ,
2424} from './utils' ;
2525
26+ function waitForChannelsRefetch ( page : Page ) {
27+ return page . waitForResponse (
28+ response =>
29+ response . url ( ) . includes ( '/v1/users/me/notification-channels' ) &&
30+ response . request ( ) . method ( ) === 'GET' ,
31+ ) ;
32+ }
33+
2634test ( 'redirects unauthenticated user to home and shows toast' , async ( {
2735 page,
2836} ) => {
@@ -37,8 +45,19 @@ test.describe('Notification Channels Page', () => {
3745 test . beforeEach ( async ( { page} ) => {
3846 await resetUserData ( ) ;
3947 await loginAsUser ( page , 'test user 1' ) ;
48+
49+ // Listen for the initial data load GET request
50+ const initialLoad = page . waitForResponse (
51+ response =>
52+ response . url ( ) . includes ( '/v1/users/me/notification-channels' ) &&
53+ response . request ( ) . method ( ) === 'GET' ,
54+ ) ;
55+
4056 await page . goto ( `${ BASE_URL } /settings/notification-channels` ) ;
4157 await waitForSidebarLoaded ( page ) ;
58+
59+ // Wait for the initial load to complete
60+ await initialLoad ;
4261 } ) ;
4362
4463 test . afterAll ( async ( ) => {
@@ -114,15 +133,24 @@ test.describe('Notification Channels Page', () => {
114133 . getByRole ( 'textbox' , { name : 'Slack Webhook URL' } )
115134 . fill ( webhookUrl ) ;
116135
136+ // Setup refetch listener before click
137+ const refetch = waitForChannelsRefetch ( page ) ;
138+
117139 await dialog . getByRole ( 'button' , { name : 'Create' , exact : true } ) . click ( ) ;
118140
141+ // Wait for refetch to complete
142+ await refetch ;
143+
119144 // Verify it's in the list.
120145 await expect ( dialog . locator ( 'sl-dialog' ) ) . not . toBeVisible ( ) ;
121146 const channelItem = webhookPanel . locator ( '.channel-item' , {
122147 hasText : webhookName ,
123148 } ) ;
124149 await expect ( channelItem ) . toBeVisible ( ) ;
125150
151+ // Setup refetch listener before delete click
152+ const deleteRefetch = waitForChannelsRefetch ( page ) ;
153+
126154 await channelItem . locator ( 'sl-button[label="Delete"]' ) . click ( ) ;
127155
128156 const deleteDialog = webhookPanel . locator ( 'sl-dialog[open]' ) ;
@@ -131,6 +159,9 @@ test.describe('Notification Channels Page', () => {
131159 . getByRole ( 'button' , { name : 'Delete' , exact : true } )
132160 . click ( ) ;
133161
162+ // Wait for deletion refetch
163+ await deleteRefetch ;
164+
134165 // Verify it's gone.
135166 await expect ( channelItem ) . not . toBeVisible ( ) ;
136167 } ) ;
@@ -165,8 +196,15 @@ test.describe('Notification Channels Page', () => {
165196 await dialog
166197 . getByRole ( 'textbox' , { name : 'Slack Webhook URL' } )
167198 . fill ( originalUrl ) ;
199+
200+ // Setup refetch listener for initial creation
201+ const createRefetch = waitForChannelsRefetch ( page ) ;
202+
168203 await dialog . getByRole ( 'button' , { name : 'Create' , exact : true } ) . click ( ) ;
169204
205+ // Wait for creation refetch
206+ await createRefetch ;
207+
170208 // Verify it was created.
171209 await expect ( dialog . locator ( 'sl-dialog' ) ) . not . toBeVisible ( ) ;
172210 const originalItem = webhookPanel . locator ( '.channel-item' , {
@@ -193,8 +231,14 @@ test.describe('Notification Channels Page', () => {
193231 . getByRole ( 'textbox' , { name : 'Slack Webhook URL' } )
194232 . fill ( updatedUrl ) ;
195233
234+ // Setup refetch listener for save
235+ const saveRefetch = waitForChannelsRefetch ( page ) ;
236+
196237 await dialog . getByRole ( 'button' , { name : 'Save' , exact : true } ) . click ( ) ;
197238
239+ // Wait for save refetch
240+ await saveRefetch ;
241+
198242 // Verify it was updated.
199243 await expect ( dialog . locator ( 'sl-dialog' ) ) . not . toBeVisible ( ) ;
200244 const updatedItem = webhookPanel . locator ( '.channel-item' , {
@@ -209,9 +253,17 @@ test.describe('Notification Channels Page', () => {
209253
210254 const deleteDialog = webhookPanel . locator ( 'sl-dialog[open]' ) ;
211255 await expect ( deleteDialog ) . toBeVisible ( ) ;
256+
257+ // Setup refetch listener for delete
258+ const deleteRefetch = waitForChannelsRefetch ( page ) ;
259+
212260 await deleteDialog
213261 . getByRole ( 'button' , { name : 'Delete' , exact : true } )
214262 . click ( ) ;
263+
264+ // Wait for deletion refetch
265+ await deleteRefetch ;
266+
215267 await expect ( updatedItem ) . not . toBeVisible ( ) ;
216268 } ) ;
217269} ) ;
0 commit comments