jojo/tests/e2e/switch.test.e2e.ts
0ko cd9ddac459 [v14.0/forgejo] fix(ui/mde): inputs in table/link insertion modals (#11499)
Backport: #11341
Trivial conflict resolution: commit contained changes to org-members.test.e2e not directly related to the fix. The file is exclusive to v15, so these changes were dropped in the backport.

---

Fixes #11268
Fixes regression of #9614

Calling `initDisabledInputs` wasn't effective for template contents, so inputs in MDEs spawned by repo-legacy.js on comment editing were broken. Now repo-legacy.js also calls it when it spawns a new MDE.

Co-authored-by: Gusted <Gusted@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11341
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>
(cherry picked from commit a0faae2764)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11499
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2026-03-05 22:01:40 +01:00

111 lines
4.6 KiB
TypeScript

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
// @watch start
// web_src/css/modules/switch.css
// web_src/css/modules/button.css
// web_src/css/themes
// @watch end
import {expect} from '@playwright/test';
import {test, login_user} from './utils_e2e.ts';
test.describe('Switch CSS properties', () => {
const noBg = 'rgba(0, 0, 0, 0)';
const activeBg = 'rgb(226, 226, 229)';
async function evaluateSwitchItem(page, selector, isActive, marginLeft, marginRight, paddingLeft, paddingRight, itemHeight) {
const item = page.locator(selector);
const cs = await item.evaluate((el) => {
// In Firefox getComputedStyle is undefined if returned from evaluate
const s = getComputedStyle(el);
return {
backgroundColor: s.backgroundColor,
marginLeft: s.marginLeft,
marginRight: s.marginRight,
paddingLeft: s.paddingLeft,
paddingRight: s.paddingRight,
};
});
expect(cs.marginLeft).toBe(marginLeft);
expect(cs.marginRight).toBe(marginRight);
expect(cs.paddingLeft).toBe(paddingLeft);
expect(cs.paddingRight).toBe(paddingRight);
if (isActive) {
await expect(item).toHaveClass(/active/);
expect(cs.backgroundColor).toBe(activeBg);
} else {
await expect(item).not.toHaveClass(/active/);
expect(cs.backgroundColor).toBe(noBg);
}
expect((await item.boundingBox()).height).toBeCloseTo(itemHeight);
}
const normalMargin = '0px';
const normalPadding = '15.75px';
const specialLeftMargin = '-4px';
const specialPadding = '19.75px';
// Subtest for areas that can be evaluated without JS
test('No JS', async ({browser}) => {
const context = await browser.newContext({javaScriptEnabled: false});
const page = await context.newPage();
const itemHeight = await page.evaluate(() => window.matchMedia('(pointer: coarse)').matches) ? 38 : 34;
await page.goto('/user2/repo1/pulls');
await expect(async () => {
await Promise.all([
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', true, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', false, specialLeftMargin, normalMargin, specialPadding, normalPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', false, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
]);
}).toPass();
await page.goto('/user2/repo1/pulls?state=closed');
await expect(async () => {
await Promise.all([
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', false, normalMargin, specialLeftMargin, normalPadding, specialPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', true, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', false, specialLeftMargin, normalMargin, specialPadding, normalPadding, itemHeight),
]);
}).toPass();
await page.goto('/user2/repo1/pulls?state=all');
await expect(async () => {
await Promise.all([
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', false, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', false, normalMargin, specialLeftMargin, normalPadding, specialPadding, itemHeight),
evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', true, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
]);
}).toPass();
});
// Subtest for areas that can't be reached without JS
test('With JS', async ({browser}, workerInfo) => {
const context = await login_user(browser, workerInfo, 'user2');
const page = await context.newPage();
// Go to files tab of a reviewable pull request
await page.goto('/user2/repo1/pulls/5/files');
// Open review box
await page.locator('#review-box .js-btn-review').click();
// Markdown editor has a special rule for a shorter switch
const itemHeight = 28;
await expect(async () => {
await Promise.all([
evaluateSwitchItem(page, '.review-box-panel .switch > .item:nth-child(1)', true, normalMargin, normalMargin, normalPadding, normalPadding, itemHeight),
evaluateSwitchItem(page, '.review-box-panel .switch > .item:nth-child(2)', false, specialLeftMargin, normalMargin, specialPadding, normalPadding, itemHeight),
]);
}).toPass();
});
});