chore(e2e): refactor "Toggle visibility" org-members test (#12871)

This test fails very often in CI. This should hopefully improve it.

With a downclocked CPU I've got 2 errors in 10 tries. After adding

```
await page.waitForLoadState();
```

I got no errors in 20 tries. But my testing methodology is unreliable so there's no guarantee that this helps:
* `Locator.click()` documentation says that it already waits by default for caused navigation to finish
* I added some `date` time measurement and `waitForLoadState` was clocking in about 5-15 ms, which shouldn't be causing the issue for `expect` that times out in 3000ms
...but e2e issues were `element(s) not found` on timeout, not wrong state, so my assumption is that somehow it is asserting the wrong snapshot of a page that isn't fully loaded

Additionally, I've converted _revertion_ logic to _make consistent before testing_, which is better at handling test retries in case that the _revertion_ part of the code was never ran in previous failure. In such case test retry is guaranteed to fail as well, at least when testing locally, not sure about CI.

Additionally, a completely unrelated comment fix in Playwright config.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12871
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
0ko
2026-06-02 14:52:01 +02:00
committed by Gusted
parent 667479c7b0
commit eb76582261
2 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ const BASE_URL = process.env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localho
*/ */
export default { export default {
testDir: './tests/e2e/', testDir: './tests/e2e/',
testMatch: /.*\.test\.e2e\.ts/, // Match any .test.e2e.js files testMatch: /.*\.test\.e2e\.ts/, // Match any .test.e2e.ts files
// you can adjust this value locally to match your machine's power, // you can adjust this value locally to match your machine's power,
// or pass `--workers x` to playwright // or pass `--workers x` to playwright
+11 -9
View File
@@ -19,18 +19,20 @@ test('Toggle visibility', async ({page}) => {
// Button "Make visible" for user2's row // Button "Make visible" for user2's row
const showUser2 = page.locator('.link-action[data-url="/org/org3/members/action/public?uid=2"]'); const showUser2 = page.locator('.link-action[data-url="/org/org3/members/action/public?uid=2"]');
await expect(hideUser2).toBeVisible(); if (await hideUser2.isHidden()) {
await expect(showUser2).toBeHidden(); // Bring page to a consistent state before testing
await hideUser2.click();
// Button action was flipped
await expect(hideUser2).toBeHidden();
await expect(showUser2).toBeVisible();
// Revert for repeatability
await showUser2.click(); await showUser2.click();
await expect(hideUser2).toBeVisible(); await expect(hideUser2).toBeVisible();
await expect(showUser2).toBeHidden(); await expect(showUser2).toBeHidden();
}
// Click button to make user2 hidden
await hideUser2.click();
await page.waitForLoadState();
// Verify that button action was flipped
await expect(hideUser2).toBeHidden();
await expect(showUser2).toBeVisible();
}); });
test('Leave org', async ({page}) => { test('Leave org', async ({page}) => {