mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 19:29:02 +03:00
c9e402afdc
Modifies forms: - (new) org team - (new) repo webhook - (new) repo protected branch The forms are not completely rewritten to semantic HTML yet. The focus of this change was on standard elements, some custom solutions were left untouched for now. - swaps the order fo permission radio buttons as per https://codeberg.org/forgejo/forgejo/issues/4983 - uses fieldsets to group related inputs - ensures consistent styling across forms - can be improved later, e.g. using horizontal lines between sections - fixes: previous font size of labels was smaller than the font size of the help text - help text are now part of the label, clicking them now also activates the input - drop unused CSS (no required checkboxes in grouped class remain) - playwright testing: - move login boilerplate to utils - automated form accessibility checking - allow defining the scope, because legacy parts of the forms are not yet accessible - assert some CSS properties that should not be overriden - the Makefile adjustment was necessary, because eslint scanned some internal files in the tests/e2e/reports directory
81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
import {expect, test as baseTest} from '@playwright/test';
|
|
|
|
export const test = baseTest.extend({
|
|
context: async ({browser}, use) => {
|
|
return use(await test_context(browser));
|
|
},
|
|
});
|
|
|
|
async function test_context(browser, options) {
|
|
const context = await browser.newContext(options);
|
|
|
|
context.on('page', (page) => {
|
|
page.on('pageerror', (err) => expect(err).toBeUndefined());
|
|
});
|
|
|
|
return context;
|
|
}
|
|
|
|
const ARTIFACTS_PATH = `tests/e2e/test-artifacts`;
|
|
const LOGIN_PASSWORD = 'password';
|
|
|
|
// log in user and store session info. This should generally be
|
|
// run in test.beforeAll(), then the session can be loaded in tests.
|
|
export async function login_user(browser, workerInfo, user) {
|
|
// Set up a new context
|
|
const context = await test_context(browser);
|
|
const page = await context.newPage();
|
|
|
|
// Route to login page
|
|
// Note: this could probably be done more quickly with a POST
|
|
const response = await page.goto('/user/login');
|
|
await expect(response?.status()).toBe(200); // Status OK
|
|
|
|
// Fill out form
|
|
await page.type('input[name=user_name]', user);
|
|
await page.type('input[name=password]', LOGIN_PASSWORD);
|
|
await page.click('form button.ui.primary.button:visible');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
await expect(page.url(), {message: `Failed to login user ${user}`}).toBe(`${workerInfo.project.use.baseURL}/`);
|
|
|
|
// Save state
|
|
await context.storageState({path: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`});
|
|
|
|
return context;
|
|
}
|
|
|
|
export async function load_logged_in_context(browser, workerInfo, user) {
|
|
let context;
|
|
try {
|
|
context = await test_context(browser, {storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`});
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`);
|
|
}
|
|
}
|
|
return context;
|
|
}
|
|
|
|
export async function login({browser}, workerInfo) {
|
|
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
|
return await context.newPage();
|
|
}
|
|
|
|
export async function save_visual(page) {
|
|
// Optionally include visual testing
|
|
if (process.env.VISUAL_TEST) {
|
|
await page.waitForLoadState('networkidle');
|
|
// Mock page/version string
|
|
await page.locator('footer div.ui.left').evaluate((node) => node.innerHTML = 'MOCK');
|
|
await expect(page).toHaveScreenshot({
|
|
fullPage: true,
|
|
timeout: 20000,
|
|
mask: [
|
|
page.locator('.secondary-nav span>img.ui.avatar'),
|
|
page.locator('.ui.dropdown.jump.item span>img.ui.avatar'),
|
|
],
|
|
});
|
|
}
|
|
}
|