@@ -12,38 +12,38 @@ limitations under the License.
1212*/
1313
1414import { test , expect } from '@playwright/test' ;
15- import { setupDashboardAuthentication , generateTestStatefulSetYaml , createK8sStatefulSet , getStatefulSetNameFromYaml , deleteK8sStatefulSet } from './test-utils' ;
15+ import { setupDashboardAuthentication , generateTestCronJobYaml , createK8sCronJob , getCronJobNameFromYaml , deleteK8sCronJob } from './test-utils' ;
1616
1717test . beforeEach ( async ( { page } ) => {
1818 await setupDashboardAuthentication ( page ) ;
1919} ) ;
2020
21- test ( 'should edit statefulset successfully' , async ( { page } ) => {
22- // Create a test statefulset directly via API to set up test data
23- const testStatefulSetYaml = generateTestStatefulSetYaml ( ) ;
24- const statefulSetName = getStatefulSetNameFromYaml ( testStatefulSetYaml ) ;
21+ test ( 'should edit cronjob successfully' , async ( { page } ) => {
22+ // Create a test cronjob directly via API to set up test data
23+ const testCronJobYaml = generateTestCronJobYaml ( ) ;
24+ const cronJobName = getCronJobNameFromYaml ( testCronJobYaml ) ;
2525
26- // Setup: Create statefulset using kubectl
27- await createK8sStatefulSet ( testStatefulSetYaml ) ;
26+ // Setup: Create cronjob using kubectl
27+ await createK8sCronJob ( testCronJobYaml ) ;
2828
2929 // Navigate to workload page
3030 await page . click ( 'text=Workloads' ) ;
3131
32- // Click visible Statefulset tab
33- const statefulsetTab = page . locator ( 'role=option[name="Statefulset "]' ) ;
34- await statefulsetTab . waitFor ( { state : 'visible' , timeout : 30000 } ) ;
35- await statefulsetTab . click ( ) ;
32+ // Click visible Cronjob tab
33+ const cronjobTab = page . locator ( 'role=option[name="Cronjob "]' ) ;
34+ await cronjobTab . waitFor ( { state : 'visible' , timeout : 30000 } ) ;
35+ await cronjobTab . click ( ) ;
3636
3737 // Verify selected state
38- await expect ( statefulsetTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
38+ await expect ( cronjobTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
3939 await expect ( page . locator ( 'table' ) ) . toBeVisible ( { timeout : 30000 } ) ;
4040
41- // Wait for statefulset to appear in list
41+ // Wait for cronjob to appear in list
4242 const table = page . locator ( 'table' ) ;
43- await expect ( table . locator ( `text=${ statefulSetName } ` ) ) . toBeVisible ( { timeout : 30000 } ) ;
43+ await expect ( table . locator ( `text=${ cronJobName } ` ) ) . toBeVisible ( { timeout : 30000 } ) ;
4444
45- // Find row containing test statefulset name
46- const targetRow = page . locator ( `table tbody tr:has-text("${ statefulSetName } ")` ) ;
45+ // Find row containing test cronjob name
46+ const targetRow = page . locator ( `table tbody tr:has-text("${ cronJobName } ")` ) ;
4747 await expect ( targetRow ) . toBeVisible ( { timeout : 15000 } ) ;
4848
4949 // Find Edit button in that row and click
@@ -54,7 +54,7 @@ test('should edit statefulset successfully', async ({ page }) => {
5454 const apiRequestPromise = page . waitForResponse ( response => {
5555 const url = response . url ( ) ;
5656 return ( url . includes ( '/api/v1/_raw/' ) ||
57- url . includes ( '/api/v1/namespaces/' ) && ( url . includes ( '/deployments/' ) || url . includes ( '/statefulsets /' ) || url . includes ( '/daemonsets/' ) ) ) &&
57+ url . includes ( '/api/v1/namespaces/' ) && ( url . includes ( '/deployments/' ) || url . includes ( '/cronjobs /' ) || url . includes ( '/daemonsets/' ) ) ) &&
5858 response . status ( ) === 200 ;
5959 } , { timeout : 15000 } ) ;
6060
@@ -107,20 +107,16 @@ metadata:
107107 name: ${ data . metadata . name }
108108 namespace: ${ data . metadata . namespace }
109109spec:
110- replicas: ${ data . spec . replicas }
111- selector:
112- matchLabels:
113- app: ${ data . spec . selector . matchLabels . app }
114- template:
115- metadata:
116- labels:
117- app: ${ data . spec . template . metadata . labels . app }
110+ schedule: "${ data . spec . schedule } "
111+ jobTemplate:
118112 spec:
119- containers:
120- - name: ${ data . spec . template . spec . containers [ 0 ] . name }
121- image: ${ data . spec . template . spec . containers [ 0 ] . image }
122- ports:
123- - containerPort: ${ data . spec . template . spec . containers [ 0 ] . ports [ 0 ] . containerPort } ` ;
113+ template:
114+ spec:
115+ containers:
116+ - name: ${ data . spec . jobTemplate . spec . template . spec . containers [ 0 ] . name }
117+ image: ${ data . spec . jobTemplate . spec . template . spec . containers [ 0 ] . image }
118+ command: ${ JSON . stringify ( data . spec . jobTemplate . spec . template . spec . containers [ 0 ] . command ) }
119+ restartPolicy: ${ data . spec . jobTemplate . spec . template . spec . restartPolicy } ` ;
124120
125121 const textarea = document . querySelector ( '.monaco-editor textarea' ) as HTMLTextAreaElement ;
126122 if ( textarea ) {
@@ -135,21 +131,21 @@ spec:
135131
136132 // If still unable to get content, report error
137133 if ( ! yamlContent || yamlContent . length === 0 ) {
138- throw new Error ( `Edit feature error: Monaco editor does not load statefulset YAML content. Expected name: "${ expectedName } ", kind: "${ expectedKind } "` ) ;
134+ throw new Error ( `Edit feature error: Monaco editor does not load cronjob YAML content. Expected name: "${ expectedName } ", kind: "${ expectedKind } "` ) ;
139135 }
140136
141- // Modify YAML content (replicas: 1 → 2, if not 1 then change to 3 )
142- let modifiedYaml = yamlContent . replace ( / r e p l i c a s : \s * 1 / , 'replicas: 2 ' ) ;
137+ // Modify YAML content (change schedule from every 5 minutes to every 10 minutes )
138+ let modifiedYaml = yamlContent . replace ( / s c h e d u l e : \s * " \* \/ 5 \s + \* \s + \* \s + \* \s + \* " / , 'schedule: "*/10 * * * *" ' ) ;
143139
144140 // Verify modification took effect
145141 if ( modifiedYaml === yamlContent ) {
146142 // Try other modification methods
147- const alternativeModified = yamlContent . replace ( / r e p l i c a s : \s * \d + / , 'replicas: 3 ' ) ;
143+ const alternativeModified = yamlContent . replace ( / s c h e d u l e : \s * " [ ^ " ] + " / , 'schedule: "0 */2 * * *" ' ) ;
148144 if ( alternativeModified !== yamlContent ) {
149145 modifiedYaml = alternativeModified ;
150146 } else {
151147 // If still can't modify, try changing image name
152- const imageModified = yamlContent . replace ( / i m a g e : \s * n g i n x : 1 \. 2 0 / , 'image: nginx :1.21 ' ) ;
148+ const imageModified = yamlContent . replace ( / i m a g e : \s * b u s y b o x : l a t e s t / , 'image: busybox :1.35 ' ) ;
153149 if ( imageModified !== yamlContent ) {
154150 modifiedYaml = imageModified ;
155151 }
@@ -233,16 +229,16 @@ spec:
233229 }
234230 }
235231
236- // Cleanup: Delete the created statefulset
232+ // Cleanup: Delete the created cronjob
237233 try {
238- await deleteK8sStatefulSet ( statefulSetName , 'default' ) ;
234+ await deleteK8sCronJob ( cronJobName , 'default' ) ;
239235 } catch ( error ) {
240- console . warn ( `Failed to cleanup statefulset ${ statefulSetName } :` , error ) ;
236+ console . warn ( `Failed to cleanup cronjob ${ cronJobName } :` , error ) ;
241237 }
242238
243239 // Debug
244240 if ( process . env . DEBUG === 'true' ) {
245- await page . screenshot ( { path : 'debug-statefulset -edit.png' , fullPage : true } ) ;
241+ await page . screenshot ( { path : 'debug-cronjob -edit.png' , fullPage : true } ) ;
246242 }
247243
248244} ) ;
0 commit comments