forgejo/tests/e2e/switch.test.e2e.ts
0ko 9a29241cde feat(ui): implement new buttons for better cohesiveness (#9359)
Followup to https://codeberg.org/forgejo/forgejo/pulls/9317#issuecomment-7214470.

Summary of changes:
- implement new CSS for buttons that doesn't have problems Fomantic buttons have:
    - button height doesn't depend on it's content - `min-height:` is used instead of `padding-{top,bottom}:`
    - no margins to fit right in with the other elements while relying on `display:flex` and `flex-gap:`
- other `.button` changes compared to `.ui.button`:
    - no semi-bold black text for now, I think it looks just as fine with normal weight
    - no variable `font-size` - should give better readability compared to existing `.small` and `.tiny` buttons
    - variable height depending on specified size (currently normal or `.small`) and on `@media (pointer: )`
- apply the new buttons to areas where there are switches or dropdown openers near them

Before:
- https://codeberg.org/forgejo/forgejo/attachments/8d9a3941-8889-4420-8f4f-f44cb8c3726f
- https://codeberg.org/forgejo/forgejo/attachments/e5804fae-a71f-43ba-918b-20d4f742124c
- https://codeberg.org/forgejo/forgejo/attachments/65d4e31c-01b7-4050-89a1-4afe74aa574c
- https://codeberg.org/forgejo/forgejo/attachments/c8057262-a834-4b61-a87f-70dab60b5506
- https://codeberg.org/forgejo/forgejo/attachments/aa9508e3-dca1-4ffe-913e-9cbddbb0d6ff
- https://codeberg.org/forgejo/forgejo/attachments/4b2daa07-e0ca-4b44-8795-1609dff8968f
- https://codeberg.org/forgejo/forgejo/attachments/93f7803f-1338-44dc-a428-e44e26231517

After:
- https://codeberg.org/forgejo/forgejo/attachments/ca5426c4-d75e-493d-8b29-64eee1e1c9de
- https://codeberg.org/forgejo/forgejo/attachments/f21c7219-6880-4a2e-9117-6267d46b3081
- https://codeberg.org/forgejo/forgejo/attachments/da3ee771-b5d5-4b4f-8c88-9a8de11b1a45
- https://codeberg.org/forgejo/forgejo/attachments/56f974c3-f72e-4f80-9bbd-5bc785a4a624
- https://codeberg.org/forgejo/forgejo/attachments/17f6e360-dfe5-4bb6-a6b5-dd747dbc2af8
- https://codeberg.org/forgejo/forgejo/attachments/91cd10e1-6c5e-4134-be4c-18223ed2a4f4
- https://codeberg.org/forgejo/forgejo/attachments/f0322c5c-ee9d-4889-9840-0c46838566cc
- https://codeberg.org/forgejo/forgejo/attachments/96560fe7-3436-46dc-8456-c43bfaee2daf
- https://codeberg.org/forgejo/forgejo/attachments/273cf795-6bb4-479f-804f-f40010fae825

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9359
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2025-10-05 05:22:32 +02:00

75 lines
3.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} from './utils_e2e.ts';
test('Switch CSS properties', async ({browser}) => {
// This test doesn't need JS and runs a little faster without it
const context = await browser.newContext({javaScriptEnabled: false});
const page = await context.newPage();
const noBg = 'rgba(0, 0, 0, 0)';
const activeBg = 'rgb(226, 226, 229)';
const normalMargin = '0px';
const normalPadding = '15.75px';
const specialLeftMargin = '-4px';
const specialPadding = '19.75px';
async function evaluateSwitchItem(page, selector, isActive, background, marginLeft, marginRight, paddingLeft, paddingRight) {
const item = page.locator(selector);
if (isActive) {
await expect(item).toHaveClass(/active/);
} else {
await expect(item).not.toHaveClass(/active/);
}
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.backgroundColor).toBe(background);
expect(cs.marginLeft).toBe(marginLeft);
expect(cs.marginRight).toBe(marginRight);
expect(cs.paddingLeft).toBe(paddingLeft);
expect(cs.paddingRight).toBe(paddingRight);
}
await page.goto('/user2/repo1/pulls');
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', true, activeBg, normalMargin, normalMargin, normalPadding, normalPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', false, noBg, specialLeftMargin, normalMargin, specialPadding, normalPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', false, noBg, normalMargin, normalMargin, normalPadding, normalPadding);
await page.goto('/user2/repo1/pulls?state=closed');
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', false, noBg, normalMargin, specialLeftMargin, normalPadding, specialPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', true, activeBg, normalMargin, normalMargin, normalPadding, normalPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', false, noBg, specialLeftMargin, normalMargin, specialPadding, normalPadding);
await page.goto('/user2/repo1/pulls?state=all');
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(1)', false, noBg, normalMargin, normalMargin, normalPadding, normalPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(2)', false, noBg, normalMargin, specialLeftMargin, normalPadding, specialPadding);
await evaluateSwitchItem(page, '#issue-filters .switch > .item:nth-child(3)', true, activeBg, normalMargin, normalMargin, normalPadding, normalPadding);
// E2E already runs clients with both fine and coarse pointer simulated
// This test will verify that coarse-related CSS is working as intended
const itemHeight = await page.evaluate(() => window.matchMedia('(pointer: coarse)').matches) ? 38 : 34;
// In Firefox Math.round is needed because .height is 33.99998474121094
expect(Math.round((await page.locator('#issue-filters .switch > .item:nth-child(1)').boundingBox()).height)).toBe(itemHeight);
});