Skip to content

Commit 793a08a

Browse files
committed
Updated tests
1 parent 1d6d3fd commit 793a08a

11 files changed

+78
-48
lines changed

__tests__/job_utilities.test.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,37 +239,64 @@ it('generates new unique dataset name', () => {
239239
});
240240

241241
it('get first task index for continuing workflow', () => {
242+
const doneImages = createImageStatus(0, 2, 0);
243+
const failedImages = createImageStatus(0, 0, 3);
244+
const submittedImages = createImageStatus(5, 0, 0);
242245
expect(testGetFirstTaskIndexForContinuingWorkflow([null, null, null, null])).toEqual(0);
243-
expect(testGetFirstTaskIndexForContinuingWorkflow(['done', 'done', null, null])).toEqual(2);
244-
expect(testGetFirstTaskIndexForContinuingWorkflow(['done', 'failed', 'done', null])).toEqual(1);
245-
expect(testGetFirstTaskIndexForContinuingWorkflow(['done', null, 'done', null])).toEqual(1);
246-
expect(testGetFirstTaskIndexForContinuingWorkflow(['done', 'done', 'done', 'done'])).toEqual(
247-
undefined
246+
expect(testGetFirstTaskIndexForContinuingWorkflow([doneImages, doneImages, null, null])).toEqual(
247+
2
248248
);
249-
expect(testGetFirstTaskIndexForContinuingWorkflow(['submitted', 'failed', null, null])).toEqual(
250-
undefined
249+
expect(
250+
testGetFirstTaskIndexForContinuingWorkflow([doneImages, failedImages, doneImages, null])
251+
).toEqual(1);
252+
expect(testGetFirstTaskIndexForContinuingWorkflow([doneImages, null, doneImages, null])).toEqual(
253+
1
251254
);
255+
expect(
256+
testGetFirstTaskIndexForContinuingWorkflow([doneImages, doneImages, doneImages, doneImages])
257+
).toEqual(undefined);
258+
expect(
259+
testGetFirstTaskIndexForContinuingWorkflow([submittedImages, failedImages, null, null])
260+
).toEqual(undefined);
252261
});
253262

254263
/**
255264
* @param {string[]} names
256265
*/
257266
function getMockedDatasets(names) {
258267
return names.map((name, index) => {
259-
return { id: index + 1, name };
268+
return /** @type {import('fractal-components/types/api').DatasetV2} */ ({
269+
id: index + 1,
270+
name
271+
});
260272
});
261273
}
262274

263275
/**
264-
* @param {Array<string|null>} values
276+
* @param {number} submitted
277+
* @param {number} done
278+
* @param {number} failed
279+
* @returns {import('fractal-components/types/api').ImagesStatus}
280+
*/
281+
function createImageStatus(submitted, done, failed) {
282+
return {
283+
num_submitted_images: submitted,
284+
num_done_images: done,
285+
num_failed_images: failed,
286+
num_available_images: 10
287+
};
288+
}
289+
290+
/**
291+
* @param {Array<import('fractal-components/types/api').ImagesStatus|null>} values
265292
* @returns {number|undefined}
266293
*/
267294
function testGetFirstTaskIndexForContinuingWorkflow(values) {
268295
const workflowTasks = values.map((_, i) => {
269-
return {
296+
return /** @type {import('fractal-components/types/api').WorkflowTaskV2} */ ({
270297
id: i + 1,
271298
order: i
272-
};
299+
});
273300
});
274301
const statuses = Object.fromEntries(
275302
values.map((v, i) => [i + 1, v]).filter((e) => e[1] !== null)

src/lib/common/job_utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const completeTracebackLine = 'Traceback (most recent call last):';
88
* @param {boolean} ignoreUppercaseTraceback
99
* @returns {Array<{text: string, highlight: boolean}>}
1010
*/
11-
export function extractJobErrorParts(log, ignoreUppercaseTraceback = false) {
11+
export function extractJobErrorParts(log = null, ignoreUppercaseTraceback = false) {
1212
if (!log) {
1313
return [];
1414
}
@@ -89,7 +89,7 @@ function extractUppercaseTraceback(error) {
8989
* @param {number|undefined} maxLines
9090
* @returns {string}
9191
*/
92-
export function extractRelevantJobError(completeJobError, maxLines = undefined) {
92+
export function extractRelevantJobError(completeJobError = null, maxLines = undefined) {
9393
if (!completeJobError) {
9494
return '';
9595
}

tests/v2/accounting.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ test('Display accounting page', async ({ page, workflow }) => {
2828
});
2929

3030
await test.step('Wait tasks submitted', async () => {
31-
await waitTaskSubmitted(page, 1);
31+
await waitTaskSubmitted(page);
3232
});
3333

3434
await test.step('Wait task success', async () => {
35-
await waitTasksSuccess(page, 1);
35+
await waitTasksSuccess(page);
3636
});
3737

3838
/** @type {number} */

tests/v2/admin_jobs.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('Execute a job and show it on the job tables [v2]', async ({ page, request
2828
});
2929
workflow1 = job.workflow;
3030
dataset1 = job.dataset;
31-
await waitTaskSubmitted(page, 1);
31+
await waitTaskSubmitted(page);
3232
await waitTaskFailure(page);
3333
await workflow1.deleteProject();
3434
});
@@ -46,7 +46,7 @@ test('Execute a job and show it on the job tables [v2]', async ({ page, request
4646
workflow2 = job.workflow;
4747
dataset2 = job.dataset;
4848
jobId2 = job.jobId;
49-
await waitTaskSubmitted(page, 1);
49+
await waitTaskSubmitted(page);
5050
});
5151

5252
await test.step('Open the admin jobs', async () => {

tests/v2/image_filters_continue_workflow.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ test('Continue workflow displays image lists [#693]', async ({ page, workflow })
3434
});
3535

3636
await test.step('Wait tasks submitted', async () => {
37-
await waitTaskSubmitted(page, 1);
37+
await waitTaskSubmitted(page);
3838
});
3939

4040
await test.step('Wait task success', async () => {
41-
await waitTasksSuccess(page, 1);
41+
await waitTasksSuccess(page);
4242
});
4343

4444
await test.step('Reload the page', async () => {

tests/v2/run_mock_tasks.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ test('Run mock tasks [v2]', async ({ page, workflow }) => {
7979
});
8080

8181
await test.step('Wait tasks submitted', async () => {
82-
await waitTaskSubmitted(page, 1);
82+
await waitTaskSubmitted(page);
8383
});
8484

8585
await test.step('Wait task success', async () => {
86-
await waitTasksSuccess(page, 1);
86+
await waitTasksSuccess(page);
8787
});
8888

8989
await test.step('Open "Continue workflow" modal', async () => {
@@ -143,7 +143,7 @@ test('Run mock tasks [v2]', async ({ page, workflow }) => {
143143
});
144144

145145
await test.step('Wait tasks submitted', async () => {
146-
await waitTaskSubmitted(page, 2);
146+
await waitTaskSubmitted(page);
147147
});
148148

149149
await test.step('Wait job failure', async () => {
@@ -180,11 +180,11 @@ test('Run mock tasks [v2]', async ({ page, workflow }) => {
180180
});
181181

182182
await test.step('Wait tasks submitted', async () => {
183-
await waitTaskSubmitted(page, 1);
183+
await waitTaskSubmitted(page);
184184
});
185185

186186
await test.step('Wait tasks success', async () => {
187-
await waitTasksSuccess(page, 2);
187+
await waitTasksSuccess(page);
188188
});
189189

190190
await test.step('Cleanup zarr_dir', async () => {
@@ -206,11 +206,11 @@ test('Run mock tasks [v2]', async ({ page, workflow }) => {
206206
});
207207

208208
await test.step('Wait tasks submitted', async () => {
209-
await waitTaskSubmitted(page, 2);
209+
await waitTaskSubmitted(page);
210210
});
211211

212212
await test.step('Wait tasks success', async () => {
213-
await waitTasksSuccess(page, 2);
213+
await waitTasksSuccess(page);
214214
});
215215

216216
await test.step('Cleanup zarr_dir', async () => {
@@ -243,11 +243,11 @@ test('Run mock tasks [v2]', async ({ page, workflow }) => {
243243
});
244244

245245
await test.step('Wait tasks submitted', async () => {
246-
await waitTaskSubmitted(page, 2);
246+
await waitTaskSubmitted(page);
247247
});
248248

249249
await test.step('Wait tasks success', async () => {
250-
await waitTasksSuccess(page, 2);
250+
await waitTasksSuccess(page);
251251
});
252252

253253
await test.step('Open the workflow jobs page', async () => {

tests/v2/run_workflow_images.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test('View images in run workflow modal', async ({ page, workflow }) => {
7575
await expect(page.getByRole('button', { name: 'Save' })).toBeDisabled();
7676
await selectSlimSelect(page, page.getByLabel('Selector for attribute k1'), 'k1v1');
7777
// Await slim-select change events are propagated before clicking the Save button
78-
//await new Promise((r) => setTimeout(r, 500));
78+
await new Promise((r) => setTimeout(r, 500));
7979
await page.getByRole('button', { name: 'Apply', exact: true }).click();
8080
await page.getByRole('button', { name: 'Save' }).click();
8181
await modal.waitFor();

tests/v2/slurm_account.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ test('Add SLURM accounts for the admin and execute workflow using a specific acc
6666
});
6767

6868
await test.step('Wait task submitted', async () => {
69-
await waitTaskSubmitted(page, 1);
69+
await waitTaskSubmitted(page);
7070
});
7171

7272
await test.step('Wait for job completion', async () => {
73-
await waitTasksSuccess(page, 1);
73+
await waitTasksSuccess(page);
7474
});
7575

7676
await test.step('Check SLURM account in workflow info modal', async () => {

tests/v2/workflow_fixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class PageWithWorkflow extends PageWithProject {
8181
* @param {string} taskName
8282
*/
8383
async selectTask(taskName) {
84-
await this.page.getByText(taskName).first().click();
84+
await this.page.getByRole('button', { name: taskName }).first().click();
8585
}
8686

8787
async openWorkflowPage() {

tests/v2/workflow_image_filters_switch_dataset.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ test('Switching datasets on continue workflow applies correct filters [#695]', a
9191
});
9292

9393
await test.step('Wait tasks submitted', async () => {
94-
await waitTaskSubmitted(page, 1);
94+
await waitTaskSubmitted(page);
9595
});
9696

9797
await test.step('Wait task success', async () => {
98-
await waitTasksSuccess(page, 1);
98+
await waitTasksSuccess(page);
9999
});
100100

101101
await test.step('Select the first dataset', async () => {

0 commit comments

Comments
 (0)