mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
The Firefox mermaid e2e test fails intermittently with `Clipboard read operation is not allowed.`, for example in https://github.com/go-gitea/gitea/actions/runs/41281998298/job/124776072700. Firefox rejects `readText()` when it overlaps the page's still pending clipboard write, and `expect.poll` does not retry errors thrown by its callback, so one overlapping read fails the test. https://github.com/go-gitea/gitea/pull/39838 only removed the paste prompt, not this rejection. - A new `assertClipboardText` helper treats a rejected read as a mismatch so it is polled again - The bot token copy test had the same race and uses it too _Written by Claude (Opus 5.5)._
28 lines
1.5 KiB
TypeScript
28 lines
1.5 KiB
TypeScript
import {env} from 'node:process';
|
|
import {test, expect} from '@playwright/test';
|
|
import {assertClipboardText, clickDropdownItem, login, randomString} from './utils.ts';
|
|
|
|
test('create a bot and manage its access token', async ({page, request}) => {
|
|
const botName = `e2e-bot-${randomString(8)}`;
|
|
await login(page);
|
|
await page.goto('/-/admin/users/new');
|
|
await page.getByLabel('Username').fill(botName);
|
|
await clickDropdownItem(page, page.getByRole('combobox').filter({hasText: 'Bot'}), 'Bot');
|
|
await page.getByLabel('Email Address').fill(`${botName}@${env.GITEA_TEST_E2E_DOMAIN}`);
|
|
await page.getByRole('button', {name: 'Create User Account'}).click();
|
|
await page.waitForURL(/\/-\/admin\/users\/\d+$/);
|
|
|
|
await page.getByLabel('Token Name').fill('e2e-token');
|
|
await page.getByRole('row', {name: /^user /}).getByRole('radio', {name: 'Read', exact: true}).check();
|
|
await page.getByRole('button', {name: 'Generate Token'}).click();
|
|
const token = (await page.getByRole('code').textContent())!;
|
|
await page.getByRole('button', {name: 'Copy', exact: true}).click();
|
|
await assertClipboardText(page, token);
|
|
const response = await request.get('/api/v1/user', {headers: {Authorization: `token ${token}`}});
|
|
expect(await response.json()).toMatchObject({login: botName, type: 'Bot'});
|
|
|
|
await page.getByRole('button', {name: 'Delete'}).click();
|
|
await page.getByRole('button', {name: 'Yes'}).click();
|
|
await expect(page.getByText('The token has been deleted.')).toBeVisible();
|
|
});
|