11import { expect , test } from './workflow_fixture.js' ;
22import { waitModalClosed , waitPageLoading } from '../utils.js' ;
3- import path from 'path' ;
4- import os from 'os' ;
53import fs from 'fs' ;
64import { createDataset } from './dataset_utils.js' ;
5+ import { waitTaskSubmitted , waitTasksSuccess } from './workflow_task_utils.js' ;
76
8- test ( 'Collect and run mock tasks [v2]' , async ( { page, workflow, request } ) => {
9- const tasksMockWheelUrl =
10- 'https://github.com/fractal-analytics-platform/fractal-server/raw/main/tests/v2/fractal_tasks_mock/dist/fractal_tasks_mock-0.0.1-py3-none-any.whl' ;
11-
7+ test ( 'Run mock tasks [v2]' , async ( { page, workflow } ) => {
128 await page . waitForURL ( workflow . url ) ;
139 await waitPageLoading ( page ) ;
1410
@@ -31,91 +27,6 @@ test('Collect and run mock tasks [v2]', async ({ page, workflow, request }) => {
3127 datasetName2 = name ;
3228 } ) ;
3329
34- await test . step ( 'Go to tasks page' , async ( ) => {
35- await page . goto ( '/v2/tasks' ) ;
36- await waitPageLoading ( page ) ;
37- } ) ;
38-
39- let skipTasksCollection = false ;
40- if ( ( await page . getByRole ( 'table' ) . last ( ) . getByText ( 'MIP_compound' ) . count ( ) ) > 0 ) {
41- console . warn ( 'WARNING: Mock tasks V2 already collected. Skipping tasks collection' ) ;
42- skipTasksCollection = true ;
43- }
44-
45- if ( ! skipTasksCollection ) {
46- /** @type {string } */
47- let tasksMockWheelFile ;
48-
49- await test . step ( 'Download fractal_tasks_mock wheel' , async ( ) => {
50- const response = await request . get ( tasksMockWheelUrl ) ;
51- expect ( response . status ( ) ) . toEqual ( 200 ) ;
52- const body = await response . body ( ) ;
53- const tmpDir = path . resolve ( os . tmpdir ( ) , 'playwright' ) ;
54- if ( ! fs . existsSync ( tmpDir ) ) {
55- fs . mkdirSync ( tmpDir ) ;
56- }
57- tasksMockWheelFile = path . resolve ( tmpDir , 'fractal_tasks_mock-0.0.1-py3-none-any.whl' ) ;
58- fs . writeFileSync ( tasksMockWheelFile , body ) ;
59- } ) ;
60-
61- await test . step ( 'Collect mock tasks' , async ( ) => {
62- await page . getByText ( 'Local' , { exact : true } ) . click ( ) ;
63- await page . getByRole ( 'textbox' , { name : 'Package' , exact : true } ) . fill ( tasksMockWheelFile ) ;
64- await page . getByRole ( 'button' , { name : 'Collect' , exact : true } ) . click ( ) ;
65-
66- if ( await page . getByText ( 'Already installed' ) . isVisible ( ) ) {
67- skipTasksCollection = true ;
68- return ;
69- }
70-
71- // Wait for Task collections table
72- await page . waitForFunction (
73- ( expectedCount ) => document . querySelectorAll ( 'table' ) . length === expectedCount ,
74- 2
75- ) ;
76- await expect (
77- page . locator ( 'table tbody tr:first-child td:nth-child(2)' ) . first ( )
78- ) . toContainText ( 'fractal_tasks_mock' ) ;
79- expect ( await getStatus ( page ) ) . toMatch ( / ^ ( p e n d i n g | i n s t a l l i n g ) $ / ) ;
80- } ) ;
81-
82- if ( ! skipTasksCollection ) {
83- await test . step ( 'Wait tasks collection' , async ( ) => {
84- await page . waitForFunction (
85- ( ) =>
86- document . querySelector ( 'table tbody tr:first-child td:nth-child(4)' ) ?. textContent ===
87- 'OK'
88- ) ;
89- } ) ;
90-
91- await test . step ( 'Check tasks list' , async ( ) => {
92- await page . getByRole ( 'table' ) . last ( ) . getByRole ( 'cell' , { name : 'MIP_compound' } ) . waitFor ( ) ;
93- } ) ;
94-
95- await test . step ( 'Delete task collection log' , async ( ) => {
96- const deleteCollectionLogBtn = page . locator (
97- 'table tr:first-child td:nth-child(5) button.btn-warning'
98- ) ;
99- await deleteCollectionLogBtn . click ( ) ;
100-
101- // Confirm action modal
102- const modalTitle = page . locator ( '.modal.show .modal-title' ) ;
103- await modalTitle . waitFor ( ) ;
104- await expect ( modalTitle ) . toHaveText ( 'Confirm action' ) ;
105- await expect ( page . locator ( '.modal.show .modal-body' ) ) . toContainText (
106- 'Remove a task collection log'
107- ) ;
108-
109- // Confirm the deletion
110- await page . getByRole ( 'button' , { name : 'Confirm' } ) . click ( ) ;
111- } ) ;
112- }
113-
114- await test . step ( 'Cleanup temporary wheel file' , async ( ) => {
115- fs . rmSync ( tasksMockWheelFile ) ;
116- } ) ;
117- }
118-
11930 await test . step ( 'Go to workflow page' , async ( ) => {
12031 await page . goto ( workflow . url ) ;
12132 await waitPageLoading ( page ) ;
@@ -400,15 +311,6 @@ test('Collect and run mock tasks [v2]', async ({ page, workflow, request }) => {
400311 } ) ;
401312} ) ;
402313
403- /**
404- * @param {import('@playwright/test').Page } page
405- * @return {Promise<string> }
406- */
407- async function getStatus ( page ) {
408- const statusCell = page . locator ( 'table tbody tr:first-child td:nth-child(4)' ) . first ( ) ;
409- return await statusCell . innerText ( ) ;
410- }
411-
412314/**
413315 * @param {import('@playwright/test').Page } page
414316 * @param {import('@playwright/test').Locator } row
@@ -424,33 +326,3 @@ async function getJobId(page, row) {
424326 await page . locator ( '.modal.show .modal-header [aria-label="Close"]' ) . click ( ) ;
425327 return /** @type {RegExpMatchArray } */ ( match ) [ 1 ] ;
426328}
427-
428- /**
429- * @param {import('@playwright/test').Page } page
430- * @param {number } count
431- */
432- async function waitTaskSubmitted ( page , count ) {
433- await expect ( page . getByText ( 'The last job failed with the following error' ) ) . toHaveCount ( 0 ) ;
434- if ( ( await page . locator ( '.job-status-icon.bi-check' ) . count ( ) ) > 0 ) {
435- return ;
436- }
437- const spinners = page . locator ( '.job-status-submitted.spinner-border' ) ;
438- await expect ( spinners ) . toHaveCount ( count ) ;
439- }
440-
441- /**
442- * @param {import('@playwright/test').Page } page
443- * @param {number } count
444- */
445- async function waitTasksSuccess ( page , count ) {
446- const spinners = page . locator ( '.job-status-submitted.spinner-border' ) ;
447- await expect ( spinners ) . toHaveCount ( 0 ) ;
448- const errorAlert = page . getByText ( 'The last job failed with the following error' ) ;
449- if ( await errorAlert . isVisible ( ) ) {
450- const error = await page . locator ( '.alert.border-danger' ) . innerText ( ) ;
451- console . error ( error ) ;
452- }
453- await expect ( errorAlert ) . toHaveCount ( 0 ) ;
454- await page . locator ( '.job-status-icon.bi-check' ) . first ( ) . waitFor ( ) ;
455- await expect ( page . locator ( '.job-status-icon.bi-check' ) ) . toHaveCount ( count ) ;
456- }
0 commit comments