mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 09:52:26 +02:00
chore(e2e): simplify authentication setup (#6400)
Replaced manual login and context loading across tests with Playwright's `test.use` configuration for user authentication. This simplifies test setup, improves readability, and reduces repetition. For #6362 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6400 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Julian Schlarb <julian.schlarb@denktmit.de> Co-committed-by: Julian Schlarb <julian.schlarb@denktmit.de>
This commit is contained in:
parent
a2eb249766
commit
68d690b6b9
19 changed files with 327 additions and 254 deletions
|
@ -10,72 +10,61 @@
|
|||
// @watch end
|
||||
|
||||
import {expect} from '@playwright/test';
|
||||
import {test, login_user, save_visual, load_logged_in_context} from './utils_e2e.ts';
|
||||
|
||||
test.beforeAll(async ({browser}, workerInfo) => {
|
||||
await login_user(browser, workerInfo, 'user2');
|
||||
});
|
||||
import {save_visual, test} from './utils_e2e.ts';
|
||||
|
||||
const workflow_trigger_notification_text = 'This workflow has a workflow_dispatch event trigger.';
|
||||
test.describe('Workflow Authenticated user2', () => {
|
||||
test.use({user: 'user2'});
|
||||
|
||||
test('workflow dispatch present', async ({browser}, workerInfo) => {
|
||||
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
||||
const page = await context.newPage();
|
||||
test('workflow dispatch present', async ({page}) => {
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
await expect(page.getByText(workflow_trigger_notification_text)).toBeVisible();
|
||||
|
||||
await expect(page.getByText(workflow_trigger_notification_text)).toBeVisible();
|
||||
const run_workflow_btn = page.locator('#workflow_dispatch_dropdown>button');
|
||||
await expect(run_workflow_btn).toBeVisible();
|
||||
|
||||
const run_workflow_btn = page.locator('#workflow_dispatch_dropdown>button');
|
||||
await expect(run_workflow_btn).toBeVisible();
|
||||
|
||||
const menu = page.locator('#workflow_dispatch_dropdown>.menu');
|
||||
await expect(menu).toBeHidden();
|
||||
await run_workflow_btn.click();
|
||||
await expect(menu).toBeVisible();
|
||||
await save_visual(page);
|
||||
});
|
||||
|
||||
test('workflow dispatch error: missing inputs', async ({browser}, workerInfo) => {
|
||||
test.skip(workerInfo.project.name === 'Mobile Safari', 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383');
|
||||
|
||||
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
||||
const page = await context.newPage();
|
||||
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
|
||||
await page.locator('#workflow_dispatch_dropdown>button').click();
|
||||
|
||||
// Remove the required attribute so we can trigger the error message!
|
||||
await page.evaluate(() => {
|
||||
const elem = document.querySelector('input[name="inputs[string2]"]');
|
||||
elem?.removeAttribute('required');
|
||||
const menu = page.locator('#workflow_dispatch_dropdown>.menu');
|
||||
await expect(menu).toBeHidden();
|
||||
await run_workflow_btn.click();
|
||||
await expect(menu).toBeVisible();
|
||||
await save_visual(page);
|
||||
});
|
||||
|
||||
await page.locator('#workflow-dispatch-submit').click();
|
||||
test('dispatch error: missing inputs', async ({page}, testInfo) => {
|
||||
test.skip(testInfo.project.name === 'Mobile Safari', 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383');
|
||||
|
||||
await expect(page.getByText('Require value for input "String w/o. default".')).toBeVisible();
|
||||
await save_visual(page);
|
||||
});
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
|
||||
test('workflow dispatch success', async ({browser}, workerInfo) => {
|
||||
test.skip(workerInfo.project.name === 'Mobile Safari', 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383');
|
||||
await page.locator('#workflow_dispatch_dropdown>button').click();
|
||||
|
||||
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
||||
const page = await context.newPage();
|
||||
// Remove the required attribute so we can trigger the error message!
|
||||
await page.evaluate(() => {
|
||||
const elem = document.querySelector('input[name="inputs[string2]"]');
|
||||
elem?.removeAttribute('required');
|
||||
});
|
||||
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
await page.locator('#workflow-dispatch-submit').click();
|
||||
|
||||
await page.locator('#workflow_dispatch_dropdown>button').click();
|
||||
await expect(page.getByText('Require value for input "String w/o. default".')).toBeVisible();
|
||||
await save_visual(page);
|
||||
});
|
||||
|
||||
await page.fill('input[name="inputs[string2]"]', 'abc');
|
||||
await save_visual(page);
|
||||
await page.locator('#workflow-dispatch-submit').click();
|
||||
test('dispatch success', async ({page}, testInfo) => {
|
||||
test.skip(testInfo.project.name === 'Mobile Safari', 'Flaky behaviour on mobile safari; see https://codeberg.org/forgejo/forgejo/pulls/3334#issuecomment-2033383');
|
||||
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
||||
|
||||
await expect(page.getByText('Workflow run was successfully requested.')).toBeVisible();
|
||||
await page.locator('#workflow_dispatch_dropdown>button').click();
|
||||
|
||||
await expect(page.locator('.run-list>:first-child .run-list-meta', {hasText: 'now'})).toBeVisible();
|
||||
await save_visual(page);
|
||||
await page.fill('input[name="inputs[string2]"]', 'abc');
|
||||
await save_visual(page);
|
||||
await page.locator('#workflow-dispatch-submit').click();
|
||||
|
||||
await expect(page.getByText('Workflow run was successfully requested.')).toBeVisible();
|
||||
|
||||
await expect(page.locator('.run-list>:first-child .run-list-meta', {hasText: 'now'})).toBeVisible();
|
||||
await save_visual(page);
|
||||
});
|
||||
});
|
||||
|
||||
test('workflow dispatch box not available for unauthenticated users', async ({page}) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue