|
| 1 | +import { expect, test } from './workflow_fixture.js'; |
| 2 | +import { waitModalClosed, waitPageLoading } from './utils.js'; |
| 3 | +import path from 'path'; |
| 4 | +import fs from 'fs'; |
| 5 | +import os from 'os'; |
| 6 | + |
| 7 | +test('Create and edit arguments of a task without schema', async ({ page, workflow }) => { |
| 8 | + await page.waitForURL(workflow.url); |
| 9 | + await waitPageLoading(page); |
| 10 | + |
| 11 | + await test.step('Open "Add a single task" form', async () => { |
| 12 | + await page.goto('/tasks'); |
| 13 | + await waitPageLoading(page); |
| 14 | + await page.getByText('Single task').click(); |
| 15 | + }); |
| 16 | + |
| 17 | + const randomTaskName = Math.random().toString(36).substring(7); |
| 18 | + |
| 19 | + await test.step('Create new task', async () => { |
| 20 | + await page.getByRole('textbox', { name: 'Task name' }).fill(randomTaskName); |
| 21 | + await page.getByRole('textbox', { name: 'Command' }).fill('/tmp/test'); |
| 22 | + await page.getByRole('textbox', { name: 'Source' }).fill(`${randomTaskName}-source`); |
| 23 | + await page.getByRole('textbox', { name: 'Input Type' }).fill('image'); |
| 24 | + await page.getByRole('textbox', { name: 'Output Type' }).fill('zarr'); |
| 25 | + |
| 26 | + await page.getByRole('button', { name: /^Create$/ }).click(); |
| 27 | + expect(await page.getByText('field required').count()).toEqual(0); |
| 28 | + await page.getByText('Task created successfully').waitFor(); |
| 29 | + }); |
| 30 | + |
| 31 | + await test.step('Open workflow page', async () => { |
| 32 | + await page.goto(workflow.url); |
| 33 | + await waitPageLoading(page); |
| 34 | + }); |
| 35 | + |
| 36 | + await test.step('Add task to workflow', async () => { |
| 37 | + await workflow.addTask(randomTaskName); |
| 38 | + }); |
| 39 | + |
| 40 | + await test.step('Add task to workflow again', async () => { |
| 41 | + await workflow.addTask(randomTaskName); |
| 42 | + }); |
| 43 | + |
| 44 | + await test.step('Open workflow task form', async () => { |
| 45 | + await page.getByText(`${randomTaskName} #`).first().click(); |
| 46 | + }); |
| 47 | + |
| 48 | + await test.step('Add argument property', async () => { |
| 49 | + await page.getByText('Add property').click(); |
| 50 | + await page.getByPlaceholder('Arg name').fill('key1'); |
| 51 | + await page.getByPlaceholder('Argument default value').fill('value1'); |
| 52 | + await page.getByLabel('Save argument').click(); |
| 53 | + await page.waitForFunction( |
| 54 | + () => document.querySelectorAll('[aria-label="Save argument"]').length === 0 |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + /** @type {string} */ |
| 59 | + let downloadedFile; |
| 60 | + |
| 61 | + await test.step('Export arguments', async () => { |
| 62 | + const exportBtn = page.getByRole('button', { name: 'Export' }); |
| 63 | + const downloadPromise = page.waitForEvent('download'); |
| 64 | + await exportBtn.click(); |
| 65 | + const download = await downloadPromise; |
| 66 | + downloadedFile = path.resolve(os.tmpdir(), 'playwright', download.suggestedFilename()); |
| 67 | + await download.saveAs(downloadedFile); |
| 68 | + }); |
| 69 | + |
| 70 | + /** @type {object} */ |
| 71 | + let exportedData; |
| 72 | + |
| 73 | + await test.step('Check exported file', async () => { |
| 74 | + exportedData = JSON.parse(fs.readFileSync(downloadedFile).toString()); |
| 75 | + expect(exportedData.key1).toEqual('value1'); |
| 76 | + }); |
| 77 | + |
| 78 | + await test.step('Import arguments', async () => { |
| 79 | + fs.writeFileSync(downloadedFile, JSON.stringify({ key1: 'value1-updated', key2: 'value2' })); |
| 80 | + await page.getByRole('button', { name: 'Import' }).click(); |
| 81 | + const modalTitle = page.locator('.modal.show .modal-title'); |
| 82 | + await modalTitle.waitFor(); |
| 83 | + const fileChooserPromise = page.waitForEvent('filechooser'); |
| 84 | + await page.getByText('Select arguments file').click(); |
| 85 | + const fileChooser = await fileChooserPromise; |
| 86 | + await fileChooser.setFiles(downloadedFile); |
| 87 | + await page.getByRole('button', { name: 'Confirm' }).click(); |
| 88 | + await waitModalClosed(page); |
| 89 | + await verifyImportedArguments(page); |
| 90 | + }); |
| 91 | + |
| 92 | + await test.step('Switch to the other task arguments form, go back to the first form and check the arguments', async () => { |
| 93 | + await page.getByText(`${randomTaskName} #`).nth(1).click(); |
| 94 | + await page.getByText(`${randomTaskName} #`).nth(0).click(); |
| 95 | + await verifyImportedArguments(page); |
| 96 | + }); |
| 97 | + |
| 98 | + await test.step('Refresh the page check the arguments', async () => { |
| 99 | + await page.reload(); |
| 100 | + await waitPageLoading(page); |
| 101 | + await page.getByText(`${randomTaskName} #`).first().click(); |
| 102 | + await verifyImportedArguments(page); |
| 103 | + }); |
| 104 | +}); |
| 105 | + |
| 106 | +/** |
| 107 | + * @param {import('@playwright/test').Page} page |
| 108 | + */ |
| 109 | +async function verifyImportedArguments(page) { |
| 110 | + const values = await page.locator('#args-tab .list-group .list-group-item').allInnerTexts(); |
| 111 | + expect(values[0]).toEqual('key1'); |
| 112 | + expect(values[1]).toEqual('value1-updated'); |
| 113 | + expect(values[2]).toEqual('key2'); |
| 114 | + expect(values[3]).toEqual('value2'); |
| 115 | +} |
0 commit comments