Skip to content

Commit

Permalink
Test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zonia3000 committed Nov 13, 2024
1 parent 182ab23 commit 0f97200
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 38 deletions.
3 changes: 1 addition & 2 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export async function waitPageLoading(page) {
* @param {import('@playwright/test').Page} page
*/
export async function waitModalClosed(page) {
await page.waitForFunction(() => document.querySelector('.modal.show') === null);
await expect(page.locator('.modal.show')).toHaveCount(0);
await expect(page.locator('.modal.show')).not.toBeVisible();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/v2/add_single_task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ test('Add single tasks [v2]', async ({ page }) => {
await page.goto('/v2/tasks');
await waitPageLoading(page);

test.slow();

await test.step('Select "Add a single task" form', async () => {
await page.getByText('Single task').click();
});
Expand Down Expand Up @@ -172,7 +174,7 @@ test('Add single tasks [v2]', async ({ page }) => {
await setUploadFile(page, 'Upload non parallel args schema', brokenJson);
await setUploadFile(page, 'Upload parallel args schema', invalidArgsSchema);
await createBtn.click();
await page.getByText("File doesn't contain valid JSON").first().waitFor();
await page.getByText("File doesn't contain valid JSON").first().scrollIntoViewIfNeeded();
expect(
await page.getByText("File doesn't contain valid JSON", { exact: true }).count()
).toEqual(3);
Expand Down
15 changes: 8 additions & 7 deletions tests/v2/admin_task_group_activities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ test('Admin task group activities page', async ({ page }) => {
});

await test.step('Search fractal-tasks-mock', async () => {
const searchButton = page.getByRole('button', { name: 'Search activities' });
await expect(searchButton).toBeEnabled();
await page.getByRole('textbox', { name: 'Package name' }).fill('fractal-tasks-mock');
await page.getByRole('combobox', { name: 'Status' }).selectOption('OK');
await page.getByRole('combobox', { name: 'Action' }).selectOption('Collect');
await page.getByRole('combobox', { name: 'User' }).selectOption('[email protected]');
const searchButton = page.getByRole('button', { name: 'Search activities' });
await searchButton.click();
await expect(searchButton).toBeEnabled();
await expect(searchButton).toBeEnabled();
await expect(page.getByText(/The query returned 1 matching result/)).toBeVisible();
});

Expand All @@ -33,9 +34,9 @@ test('Admin task group activities page', async ({ page }) => {
await test.step('Reset', async () => {
await page.getByRole('button', { name: 'Reset' }).click();
await expect(page.getByText(/The query returned \d+ matching result/)).not.toBeVisible();
await expect(page.getByRole('textbox', { name: 'Package name' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'Status' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'Action' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'User' })).toHaveValue('');
});
await expect(page.getByRole('textbox', { name: 'Package name' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'Status' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'Action' })).toHaveValue('');
await expect(page.getByRole('combobox', { name: 'User' })).toHaveValue('');
});
});
24 changes: 14 additions & 10 deletions tests/v2/import_export_args.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
await page.waitForURL(workflow.url);
await waitPageLoading(page);

test.slow();

let nonParallelTaskWithoutArgsSchema;
let parallelTaskWithoutArgsSchema;
let compoundTaskWithoutArgsSchema;
Expand Down Expand Up @@ -91,7 +93,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
expect(data.args_parallel).toEqual(null);
const newData = { args_non_parallel: { key_non_parallel: 'value_non_parallel-updated' } };
await importValidArgs(page, file, newData);
await page.getByText('Arguments changes saved successfully').waitFor();
await expect(page.getByText('Arguments changes saved successfully')).toBeVisible();
await workflow.removeCurrentTask();
});

Expand All @@ -102,14 +104,15 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
await page.getByPlaceholder('Argument name').click();
await page.getByPlaceholder('Argument name').fill('key_parallel');
await page.getByPlaceholder('Argument value').fill('value_parallel');
await expect(page.getByText('Arguments changes saved successfully')).not.toBeVisible();
await page.getByRole('button', { name: 'Save changes' }).click();

const { file, data } = await exportArgs(page, parallelTaskWithoutArgsSchema);
expect(data.args_non_parallel).toEqual(null);
expect(data.args_parallel.key_parallel).toEqual('value_parallel');
const newData = { args_parallel: { key_parallel: 'value_parallel-updated' } };
await importValidArgs(page, file, newData);
await page.getByText('Arguments changes saved successfully').waitFor();
await expect(page.getByText('Arguments changes saved successfully')).toBeVisible();
await workflow.removeCurrentTask();
});

Expand All @@ -122,6 +125,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
await page.getByRole('button', { name: 'Add property' }).nth(1).click();
await page.getByPlaceholder('Argument name').nth(1).fill('key_parallel');
await page.getByPlaceholder('Argument value').nth(1).fill('value_parallel');
await expect(page.getByText('Arguments changes saved successfully')).not.toBeVisible();
await page.getByRole('button', { name: 'Save changes' }).click();
await expect(page.getByRole('button', { name: 'Save changes' })).toBeDisabled();

Expand All @@ -132,9 +136,9 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
args_non_parallel: { key_non_parallel: 'value_non_parallel-updated' },
args_parallel: { key_parallel: 'value_parallel-updated' }
};
await expect(page.getByText('Arguments changes saved successfully')).toHaveCount(0);
await expect(page.getByText('Arguments changes saved successfully')).not.toBeVisible();
await importValidArgs(page, file, newData);
await page.getByText('Arguments changes saved successfully').waitFor();
await expect(page.getByText('Arguments changes saved successfully')).toBeVisible();
await workflow.removeCurrentTask();
});

Expand All @@ -148,7 +152,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
expect(data.args_parallel).toEqual(null);
const newData = { args_non_parallel: { test_non_parallel: 'value_non_parallel-updated' } };
await importValidArgs(page, file, newData);
expect(await page.getByRole('textbox', { name: 'test_non_parallel' }).inputValue()).toEqual(
await expect(await page.getByRole('textbox', { name: 'test_non_parallel' })).toHaveValue(
'value_non_parallel-updated'
);
await workflow.removeCurrentTask();
Expand All @@ -164,7 +168,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
expect(data.args_parallel.test_parallel).toEqual('value_parallel');
const newData = { args_parallel: { test_parallel: 'value_parallel-updated' } };
await importValidArgs(page, file, newData);
expect(await page.getByRole('textbox', { name: 'test_parallel' }).inputValue()).toEqual(
await expect(page.getByRole('textbox', { name: 'test_parallel' })).toHaveValue(
'value_parallel-updated'
);
await workflow.removeCurrentTask();
Expand All @@ -184,10 +188,10 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
args_parallel: { test_parallel: 'value_parallel-updated' }
};
await importValidArgs(page, file, newData);
expect(await page.getByRole('textbox', { name: 'test_non_parallel' }).inputValue()).toEqual(
await expect(page.getByRole('textbox', { name: 'test_non_parallel' })).toHaveValue(
'value_non_parallel-updated'
);
expect(await page.getByRole('textbox', { name: 'test_parallel' }).inputValue()).toEqual(
await expect(page.getByRole('textbox', { name: 'test_parallel' })).toHaveValue(
'value_parallel-updated'
);
});
Expand All @@ -202,7 +206,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, '..', 'data', 'broken.json'));
await page.getByRole('button', { name: 'Confirm' }).click();
await page.getByText("File doesn't contain valid JSON").waitFor();
await expect(page.getByText("File doesn't contain valid JSON")).toBeVisible();
await modal.getByRole('button', { name: 'Close' }).click();
await waitModalClosed(page);
});
Expand All @@ -219,7 +223,7 @@ test('Import/export arguments [v2]', async ({ page, workflow }) => {
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(file);
await page.getByRole('button', { name: 'Confirm' }).click();
await page.getByText('must have required property').waitFor();
await expect(page.getByText('must have required property')).toBeVisible();
await modal.getByRole('button', { name: 'Close' }).click();
await waitModalClosed(page);
fs.rmSync(file);
Expand Down
18 changes: 15 additions & 3 deletions tests/v2/task_group_activities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ import { waitModalClosed, waitPageLoading } from '../utils';

test('Task group activities page', async ({ page }) => {
await test.step('Open task group activities page', async () => {
page.goto('/v2/tasks/activities');
await page.goto('/v2/tasks/activities');
await waitPageLoading(page);
await expect(page.getByText(/The query returned \d+ matching result/)).toBeVisible();
const regexResult = /The query returned (\d+) matching result/;
const resultText = page.getByText(regexResult);
await expect(resultText).toBeVisible();
const result = (await resultText.innerText()).match(regexResult);
if (result === null) {
expect(result).not.toBeNull();
return;
}
const expectedCount = parseInt(result[1]);
await expect(page.getByRole('row')).toHaveCount(expectedCount + 1);
});

await test.step('Search fractal-tasks-mock', async () => {
const searchButton = page.getByRole('button', { name: 'Search activities' });
await expect(searchButton).toBeEnabled();
await page.getByRole('textbox', { name: 'Package name' }).waitFor();
await page.getByRole('textbox', { name: 'Package name' }).fill('fractal-tasks-mock');
await page.getByRole('combobox', { name: 'Status' }).selectOption('OK');
await page.getByRole('combobox', { name: 'Action' }).selectOption('Collect');
const searchButton = page.getByRole('button', { name: 'Search activities' });
await searchButton.click();
await expect(searchButton).toBeEnabled();
await expect(page.getByText(/The query returned 1 matching result/)).toBeVisible();
await expect(page.getByRole('row')).toHaveCount(2);
});

await test.step('Open log modal', async () => {
Expand Down
35 changes: 20 additions & 15 deletions tests/v2/task_version_update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await page.waitForURL(workflow.url);
await waitPageLoading(page);

test.slow();

let nonParallelTask;
let parallelTask;
let compoundTask;
Expand Down Expand Up @@ -123,7 +125,7 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await test.step('Fill optional argument p2', async () => {
await page.getByRole('textbox', { name: 'p2' }).fill('foo');
await page.getByRole('button', { name: 'Save changes' }).click();
await page.getByText('Arguments changes saved successfully').waitFor();
await expect(page.getByText('Arguments changes saved successfully')).toBeVisible();
});

await test.step('Add Input Filters', async () => {
Expand All @@ -134,23 +136,25 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await page.getByRole('button', { name: 'Add type filter', exact: true }).click();
await page.getByPlaceholder('Key').nth(1).fill('key2');
await page.getByRole('button', { name: 'Save' }).click();
await page.getByText('Input filters successfully updated').waitFor();
await expect(page.getByText('Input filters successfully updated')).toBeVisible();
});

await test.step('Update non parallel task to v2', async () => {
await page.getByRole('button', { name: 'Version' }).click();
await page
.getByRole('combobox', { name: /New versions of this task exist/ })
.selectOption('0.0.2');
await page.getByText('Following errors must be fixed before performing the update').waitFor();
await expect(
page.getByText('Following errors must be fixed before performing the update')
).toBeVisible();
await expect(page.locator('.alert-danger li')).toHaveCount(1);
await page
.getByRole('textbox', { name: 'Fix the non parallel arguments:' })
.fill('{"p1": "test"}');
await page.getByRole('button', { name: 'Check' }).click();
await page.getByText('The arguments are valid').waitFor();
await expect(page.getByText('The arguments are valid')).toBeVisible();
await page.getByRole('button', { name: 'Update' }).click();
await page.getByText('No new versions available').waitFor();
await expect(page.getByText('No new versions available')).toBeVisible();
});

await test.step('Verify that input filters have been preserved', async () => {
Expand All @@ -173,10 +177,12 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await page
.getByRole('combobox', { name: /New versions of this task exist/ })
.selectOption('0.0.2');
await page.getByText('Following errors must be fixed before performing the update').waitFor();
await expect(
page.getByText('Following errors must be fixed before performing the update')
).toBeVisible();
await page.getByRole('textbox', { name: 'Fix the parallel arguments:' }).fill('{"p2": "test"}');
await page.getByRole('button', { name: 'Check' }).click();
await page.getByText('The arguments are valid').waitFor();
await expect(page.getByText('The arguments are valid')).toBeVisible();
await page.getByRole('button', { name: 'Update' }).click();
await expect(
page.getByRole('combobox', { name: /New versions of this task exist/ }).getByRole('option')
Expand All @@ -194,15 +200,15 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await page.getByRole('button', { name: 'Arguments', exact: true }).click();
await page.getByRole('textbox', { name: 'p2' }).fill('test-value');
await page.getByRole('button', { name: 'Save changes' }).click();
await page.getByText('Arguments changes saved successfully').waitFor();
await expect(page.getByText('Arguments changes saved successfully')).toBeVisible();
await expect(page.getByRole('button', { name: 'Save changes' })).toBeDisabled();
await page.getByRole('button', { name: 'Version' }).click();
await page
.getByRole('combobox', { name: /New versions of this task exist/ })
.selectOption('0.0.3');
await page.getByText('The arguments are valid').waitFor();
await expect(page.getByText('The arguments are valid')).toBeVisible();
await page.getByRole('button', { name: 'Update' }).click();
await page.getByText('No new versions available').waitFor();
await expect(page.getByText('No new versions available')).toBeVisible();
// Verify that the arguments are preserved after the update
await page.getByRole('button', { name: 'Arguments', exact: true }).click();
await expect(page.getByRole('textbox', { name: 'p2' })).toHaveValue('test-value');
Expand All @@ -221,10 +227,9 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await page
.getByRole('combobox', { name: /New versions of this task exist/ })
.selectOption('0.0.2');
await page
.getByText('Following errors must be fixed before performing the update')
.first()
.waitFor();
await expect(
page.getByText('Following errors must be fixed before performing the update').first()
).toBeVisible();
await page.getByRole('textbox', { name: 'Fix the non parallel arguments:' }).click();
await page
.getByRole('textbox', { name: 'Fix the non parallel arguments:' })
Expand All @@ -235,7 +240,7 @@ test('Task version update [v2]', async ({ page, workflow }) => {
await expect(page.getByText('The parallel arguments are valid')).toBeVisible();
await expect(page.getByText('The non parallel arguments are valid')).toBeVisible();
await page.getByRole('button', { name: 'Update' }).click();
await page.getByText('No new versions available').waitFor();
await expect(page.getByText('No new versions available')).toBeVisible();
});

await test.step('Cleanup test tasks', async () => {
Expand Down

0 comments on commit 0f97200

Please sign in to comment.