mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-27 04:07:08 +00:00
[v10.0/forgejo] Refactor e2e tests to simplify authentication setup (#6585)
**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>
This commit is contained in:
parent
39843ee2b3
commit
05056b8aa2
19 changed files with 327 additions and 254 deletions
|
@ -5,13 +5,9 @@
|
|||
// @watch end
|
||||
|
||||
import {expect, type Page} from '@playwright/test';
|
||||
import {test, save_visual, login_user, login} from './utils_e2e.ts';
|
||||
import {save_visual, test} from './utils_e2e.ts';
|
||||
import {accessibilityCheck} from './shared/accessibility.ts';
|
||||
|
||||
test.beforeAll(async ({browser}, workerInfo) => {
|
||||
await login_user(browser, workerInfo, 'user2');
|
||||
});
|
||||
|
||||
async function assertSelectedLines(page: Page, nums: string[]) {
|
||||
const pageAssertions = async () => {
|
||||
expect(
|
||||
|
@ -81,20 +77,23 @@ test('Readable diff', async ({page}, workerInfo) => {
|
|||
}
|
||||
});
|
||||
|
||||
test('Username highlighted in commits', async ({browser}, workerInfo) => {
|
||||
const page = await login({browser}, workerInfo);
|
||||
await page.goto('/user2/mentions-highlighted/commits/branch/main');
|
||||
// check first commit
|
||||
await page.getByRole('link', {name: 'A commit message which'}).click();
|
||||
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
|
||||
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
|
||||
await accessibilityCheck({page}, ['.commit-header'], [], []);
|
||||
await save_visual(page);
|
||||
// check second commit
|
||||
await page.goto('/user2/mentions-highlighted/commits/branch/main');
|
||||
await page.locator('tbody').getByRole('link', {name: 'Another commit which mentions'}).click();
|
||||
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
|
||||
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
|
||||
await accessibilityCheck({page}, ['.commit-header'], [], []);
|
||||
await save_visual(page);
|
||||
test.describe('As authenticated user', () => {
|
||||
test.use({user: 'user2'});
|
||||
|
||||
test('Username highlighted in commits', async ({page}) => {
|
||||
await page.goto('/user2/mentions-highlighted/commits/branch/main');
|
||||
// check first commit
|
||||
await page.getByRole('link', {name: 'A commit message which'}).click();
|
||||
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
|
||||
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
|
||||
await accessibilityCheck({page}, ['.commit-header'], [], []);
|
||||
await save_visual(page);
|
||||
// check second commit
|
||||
await page.goto('/user2/mentions-highlighted/commits/branch/main');
|
||||
await page.locator('tbody').getByRole('link', {name: 'Another commit which mentions'}).click();
|
||||
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
|
||||
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
|
||||
await accessibilityCheck({page}, ['.commit-header'], [], []);
|
||||
await save_visual(page);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue