Files
Gitea/tests/e2e/admin.test.ts
T
silverwind 5d84bbd525 test: run e2e tests in WebKit on macOS (#40140)
WebKit was removed from the e2e tests in
https://github.com/go-gitea/gitea/pull/37315 because Linux WebKit kept
crashing. `make test-e2e` on macOS now also runs WebKit, which does not
show these crashes there. CI stays on Linux, because macOS runners would
need about an extra GB of cache storage.

1. The bot account test clicks the user type dropdown, Safari only moves
Tab focus between text fields
1. On macOS, Playwright runs with a single libuv thread, concurrent
`getaddrinfo` lookups of `localhost` there sporadically stall for 5s

---------

Signed-off-by: silverwind <me@silverwind.io>
2026-10-31 22:44:39 +00:00

28 lines
1.5 KiB
TypeScript

import {env} from 'node:process';
import {test, expect} from '@playwright/test';
import {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 expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(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();
});