11import { expect , test } from '@playwright/test' ;
2- import { waitPageLoading } from '../utils.js' ;
2+ import { waitModalClosed , waitPageLoading } from '../utils.js' ;
33import { PageWithWorkflow } from './workflow_fixture.js' ;
44import * as fs from 'fs' ;
55
66test ( 'Execute a job and show it on the job tables [v1]' , async ( { page, request } ) => {
77 /** @type {PageWithWorkflow } */
88 let workflow1 ;
99 await test . step ( 'Create first job and wait its failure' , async ( ) => {
10- workflow1 = await createJob ( page , request , 'input' , 'output' ) ;
11- await workflow1 . triggerTaskFailure ( ) ;
10+ const job = await createJob ( page , request , 'input' , 'output' ) ;
11+ workflow1 = job . workflow ;
12+ await workflow1 . triggerTaskFailure ( job . jobId ) ;
1213 const jobBadge = page . locator ( '.badge.text-bg-danger' ) ;
1314 await jobBadge . waitFor ( ) ;
1415 expect ( await jobBadge . innerText ( ) ) . toEqual ( 'failed' ) ;
@@ -17,8 +18,12 @@ test('Execute a job and show it on the job tables [v1]', async ({ page, request
1718
1819 /** @type {PageWithWorkflow } */
1920 let workflow2 ;
21+ /** @type {number } */
22+ let jobId2 ;
2023 await test . step ( 'Create second job' , async ( ) => {
21- workflow2 = await createJob ( page , request , 'input2' , 'output2' ) ;
24+ const job = await createJob ( page , request , 'input2' , 'output2' ) ;
25+ workflow2 = job . workflow ;
26+ jobId2 = job . jobId ;
2227 } ) ;
2328
2429 await test . step ( 'Open the admin jobs' , async ( ) => {
@@ -84,7 +89,7 @@ test('Execute a job and show it on the job tables [v1]', async ({ page, request
8489 } ) ;
8590
8691 await test . step ( 'Wait job completion' , async ( ) => {
87- await workflow2 . triggerTaskSuccess ( ) ;
92+ await workflow2 . triggerTaskSuccess ( jobId2 ) ;
8893 const jobBadge = page . locator ( '.badge.text-bg-success' ) ;
8994 await jobBadge . waitFor ( ) ;
9095 expect ( await jobBadge . innerText ( ) ) . toEqual ( 'done' ) ;
@@ -161,19 +166,22 @@ async function getWorkflowRow(page, workflowName) {
161166 * @param {import('@playwright/test').APIRequestContext } request
162167 * @param {string } inputDataset
163168 * @param {string } outputDataset
169+ * @returns {Promise<{ workflow: PageWithWorkflow, jobId: number }> }
164170 */
165171async function createJob ( page , request , inputDataset , outputDataset ) {
166172 const workflow = new PageWithWorkflow ( page , request ) ;
173+ /** @type {number|undefined } */
174+ let jobId ;
167175 await test . step ( 'Create workflow' , async ( ) => {
168176 await workflow . createProject ( ) ;
169177 await workflow . createDataset ( inputDataset , 'image' ) ;
170178 await workflow . createDataset ( outputDataset , 'zarr' ) ;
171179 await workflow . createWorkflow ( ) ;
172180 await page . waitForURL ( /** @type {string } */ ( workflow . url ) ) ;
173181 await addTaskToWorkflow ( workflow ) ;
174- await runWorkflow ( page , inputDataset , outputDataset ) ;
182+ jobId = await runWorkflow ( page , inputDataset , outputDataset ) ;
175183 } ) ;
176- return workflow ;
184+ return { workflow, jobId : /** @type { number } */ ( jobId ) } ;
177185}
178186
179187/**
@@ -189,8 +197,11 @@ async function addTaskToWorkflow(workflow) {
189197 * @param {import('@playwright/test').Page } page
190198 * @param {string } inputDataset
191199 * @param {string } outputDataset
200+ * @returns {Promise<number> } the id of the job
192201 */
193202async function runWorkflow ( page , inputDataset , outputDataset ) {
203+ /** @type {number|undefined } */
204+ let jobId ;
194205 await test . step ( 'Run workflow' , async ( ) => {
195206 const runWorkflowBtn = page . getByRole ( 'button' , { name : 'Run workflow' } ) ;
196207 await runWorkflowBtn . click ( ) ;
@@ -204,5 +215,16 @@ async function runWorkflow(page, inputDataset, outputDataset) {
204215 const confirmBtn = page . locator ( '.modal.show' ) . getByRole ( 'button' , { name : 'Confirm' } ) ;
205216 await confirmBtn . click ( ) ;
206217 await page . waitForURL ( new RegExp ( `/v1/projects/(\\d+)/workflows/(\\d+)/jobs` ) ) ;
218+ await page
219+ . getByRole ( 'row' , { name : 'submitted' } )
220+ . getByRole ( 'button' , { name : 'Info' } )
221+ . click ( ) ;
222+ const modal = page . locator ( '.modal.show' ) ;
223+ await modal . waitFor ( ) ;
224+ const value = await modal . getByRole ( 'listitem' ) . nth ( 1 ) . textContent ( ) ;
225+ jobId = Number ( value ?. trim ( ) ) ;
226+ await modal . getByRole ( 'button' , { name : 'Close' } ) . click ( ) ;
227+ await waitModalClosed ( page ) ;
207228 } ) ;
229+ return /** @type {number } */ ( jobId ) ;
208230}
0 commit comments