@@ -18,7 +18,12 @@ import { routesPom } from '@e2e/pom/routes';
1818import { randomId } from '@e2e/utils/common' ;
1919import { e2eReq } from '@e2e/utils/req' ;
2020import { test } from '@e2e/utils/test' ;
21- import { uiClearEditor , uiHasToastMsg } from '@e2e/utils/ui' ;
21+ import {
22+ uiClearMonacoEditor ,
23+ uiFillMonacoEditor ,
24+ uiGetMonacoEditor ,
25+ uiHasToastMsg ,
26+ } from '@e2e/utils/ui' ;
2227import { uiFillUpstreamAllFields } from '@e2e/utils/ui/upstreams' ;
2328import { expect } from '@playwright/test' ;
2429
@@ -33,13 +38,18 @@ const nodes: APISIXType['UpstreamNode'][] = [
3338 { host : 'test.com' , port : 80 , weight : 100 } ,
3439 { host : 'test2.com' , port : 80 , weight : 100 } ,
3540] ;
41+ // Define vars values for testing
42+ const initialVars = '[["arg_name", "==", "json"], ["arg_age", ">", 18]]' ;
43+ const updatedVars = '[["arg_name", "==", "updated"], ["arg_age", ">", 21]]' ;
3644
3745test . beforeAll ( async ( ) => {
3846 await deleteAllRoutes ( e2eReq ) ;
3947} ) ;
4048
4149test ( 'should CRUD route with all fields' , async ( { page } ) => {
42- test . setTimeout ( 30000 ) ;
50+ test . slow ( ) ;
51+
52+ const varsSection = page . getByText ( 'Vars' ) . locator ( '..' ) ;
4353
4454 // Navigate to the route list page
4555 await routesPom . toIndex ( page ) ;
@@ -85,6 +95,10 @@ test('should CRUD route with all fields', async ({ page }) => {
8595 await page . getByRole ( 'option' , { name : 'Disabled' } ) . click ( ) ;
8696 await expect ( status ) . toHaveValue ( 'Disabled' ) ;
8797
98+ // Fill in Vars field
99+ const varsEditor = await uiGetMonacoEditor ( page , varsSection ) ;
100+ await uiFillMonacoEditor ( page , varsEditor , initialVars ) ;
101+
88102 // Add upstream nodes
89103 const upstreamSection = page . getByRole ( 'group' , {
90104 name : 'Upstream' ,
@@ -120,11 +134,8 @@ test('should CRUD route with all fields', async ({ page }) => {
120134 . click ( ) ;
121135
122136 const addPluginDialog = page . getByRole ( 'dialog' , { name : 'Add Plugin' } ) ;
123- const editorLoading = addPluginDialog . getByTestId ( 'editor-loading' ) ;
124- await expect ( editorLoading ) . toBeHidden ( ) ;
125- const editor = addPluginDialog . getByRole ( 'code' ) . getByRole ( 'textbox' ) ;
126- await uiClearEditor ( page ) ;
127- await editor . fill ( '{"hide_credentials": true}' ) ;
137+ const pluginEditor = await uiGetMonacoEditor ( page , addPluginDialog ) ;
138+ await uiFillMonacoEditor ( page , pluginEditor , '{"hide_credentials": true}' ) ;
128139 // add plugin
129140 await addPluginDialog . getByRole ( 'button' , { name : 'Add' } ) . click ( ) ;
130141 await expect ( addPluginDialog ) . toBeHidden ( ) ;
@@ -135,7 +146,6 @@ test('should CRUD route with all fields', async ({ page }) => {
135146
136147 // should show edit plugin dialog
137148 const editPluginDialog = page . getByRole ( 'dialog' , { name : 'Edit Plugin' } ) ;
138- await expect ( editorLoading ) . toBeHidden ( ) ;
139149
140150 await expect ( editPluginDialog . getByText ( 'hide_credentials' ) ) . toBeVisible ( ) ;
141151 // save edit plugin dialog
@@ -157,13 +167,12 @@ test('should CRUD route with all fields', async ({ page }) => {
157167 // real-ip need config, otherwise it will show an error
158168 await addPluginDialog . getByRole ( 'button' , { name : 'Add' } ) . click ( ) ;
159169 await expect ( addPluginDialog ) . toBeVisible ( ) ;
160- await expect ( editorLoading ) . toBeHidden ( ) ;
161170 await expect (
162171 addPluginDialog . getByText ( 'Missing property "source"' )
163172 ) . toBeVisible ( ) ;
164173
165174 // clear the editor, will show JSON format is not valid
166- await uiClearEditor ( page ) ;
175+ await uiClearMonacoEditor ( page , pluginEditor ) ;
167176 await expect (
168177 addPluginDialog . getByText ( 'JSON format is not valid' )
169178 ) . toBeVisible ( ) ;
@@ -175,15 +184,18 @@ test('should CRUD route with all fields', async ({ page }) => {
175184 ) . toBeVisible ( ) ;
176185
177186 // add a valid config
178- await editor . fill ( '{"source": "X-Forwarded-For"}' ) ;
187+ await uiFillMonacoEditor (
188+ page ,
189+ pluginEditor ,
190+ '{"source": "X-Forwarded-For"}'
191+ ) ;
179192 await addPluginDialog . getByRole ( 'button' , { name : 'Add' } ) . click ( ) ;
180193 await expect ( addPluginDialog ) . toBeHidden ( ) ;
181194
182195 // check real-ip plugin in edit dialog
183196 const realIpPlugin = page . getByTestId ( 'plugin-real-ip' ) ;
184197 await realIpPlugin . getByRole ( 'button' , { name : 'Edit' } ) . click ( ) ;
185198 await expect ( editPluginDialog ) . toBeVisible ( ) ;
186- await expect ( editorLoading ) . toBeHidden ( ) ;
187199 await expect ( editPluginDialog . getByText ( 'X-Forwarded-For' ) ) . toBeVisible ( ) ;
188200 // close
189201 await editPluginDialog . getByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
@@ -249,6 +261,10 @@ test('should CRUD route with all fields', async ({ page }) => {
249261 const status = page . getByRole ( 'textbox' , { name : 'Status' , exact : true } ) ;
250262 await expect ( status ) . toHaveValue ( 'Disabled' ) ;
251263
264+ // Verify Vars field
265+ await expect ( varsSection . getByText ( 'arg_name' ) ) . toBeVisible ( ) ;
266+ await expect ( varsSection . getByText ( 'json' ) ) . toBeVisible ( ) ;
267+
252268 // Verify Plugins
253269 await expect ( page . getByText ( 'basic-auth' ) ) . toBeHidden ( ) ;
254270 await expect ( page . getByText ( 'real-ip' ) ) . toBeVisible ( ) ;
@@ -279,6 +295,10 @@ test('should CRUD route with all fields', async ({ page }) => {
279295 // Update Priority
280296 await page . getByLabel ( 'Priority' , { exact : true } ) . first ( ) . fill ( '200' ) ;
281297
298+ // Update Vars field
299+ const varsEditor = await uiGetMonacoEditor ( page , varsSection ) ;
300+ await uiFillMonacoEditor ( page , varsEditor , updatedVars ) ;
301+
282302 // Click the Save button to save changes
283303 const saveBtn = page . getByRole ( 'button' , { name : 'Save' } ) ;
284304 await saveBtn . click ( ) ;
@@ -312,6 +332,10 @@ test('should CRUD route with all fields', async ({ page }) => {
312332 page . getByLabel ( 'Priority' , { exact : true } ) . first ( )
313333 ) . toHaveValue ( '200' ) ;
314334
335+ // Verify updated Vars field
336+ await expect ( varsSection . getByText ( 'arg_name' ) ) . toBeVisible ( ) ;
337+ await expect ( varsSection . getByText ( 'updated' ) ) . toBeVisible ( ) ;
338+
315339 // Return to list page and verify the route exists
316340 await routesPom . getRouteNavBtn ( page ) . click ( ) ;
317341 await routesPom . isIndexPage ( page ) ;
0 commit comments