mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-30 15:19:43 +00:00
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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. #6362 first part ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: Julian Schlarb <julian.schlarb@denktmit.de> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6585 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
74 lines
3 KiB
TypeScript
74 lines
3 KiB
TypeScript
// @watch start
|
|
// templates/repo/actions/**
|
|
// web_src/css/actions.css
|
|
// web_src/js/components/ActionRunStatus.vue
|
|
// web_src/js/components/RepoActionView.vue
|
|
// modules/actions/**
|
|
// modules/structs/workflow.go
|
|
// routers/api/v1/repo/action.go
|
|
// routers/web/repo/actions/**
|
|
// @watch end
|
|
|
|
import {expect} from '@playwright/test';
|
|
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 ({page}) => {
|
|
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
|
|
|
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 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('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 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');
|
|
});
|
|
|
|
await page.locator('#workflow-dispatch-submit').click();
|
|
|
|
await expect(page.getByText('Require value for input "String w/o. default".')).toBeVisible();
|
|
await save_visual(page);
|
|
});
|
|
|
|
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 page.locator('#workflow_dispatch_dropdown>button').click();
|
|
|
|
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}) => {
|
|
await page.goto('/user2/test_workflows/actions?workflow=test-dispatch.yml&actor=0&status=0');
|
|
|
|
await expect(page.locator('body')).not.toContainText(workflow_trigger_notification_text);
|
|
});
|