Skip to content

Commit 2b0dd5a

Browse files
authored
fix(test): load app CSS in Cypress component tests / 修复 Cypress 组件测试未加载应用 CSS (#614)
* test: load app CSS in Cypress component tests 中文:在 Cypress 组件测试中统一加载应用 CSS,并增加 Tailwind 可见性与尺寸回归测试。 * test: scope Header mobile navigation assertions 中文:将 Header 移动端导航断言限定在汉堡菜单容器内(新增 mobile-menu testid),并验证桌面导航在小屏幕下隐藏。 * fix: keep selector category tooltips above dropdowns 中文:提高 selector 分类 Tooltip 的局部层级,避免其被 MultiSelect 选项遮挡。
1 parent 1e60c7b commit 2b0dd5a

6 files changed

Lines changed: 39 additions & 7 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe('component CSS harness', () => {
2+
it('loads Tailwind visibility and sizing utilities', () => {
3+
cy.mount(
4+
<button type="button" data-testid="css-probe" className="hidden size-11">
5+
probe
6+
</button>,
7+
);
8+
9+
cy.get('[data-testid="css-probe"]').then(($probe) => {
10+
const style = getComputedStyle($probe[0]);
11+
12+
expect({ display: style.display, width: style.width, height: style.height }).to.deep.equal({
13+
display: 'none',
14+
width: '44px',
15+
height: '44px',
16+
});
17+
});
18+
});
19+
});

packages/app/cypress/component/header.cy.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ describe('Header', () => {
7272

7373
it('shows mobile hamburger menu on small viewports', () => {
7474
cy.viewport(375, 812);
75-
cy.get('[data-testid="mobile-menu-toggle"]').should('be.visible');
76-
cy.get('[data-testid="mobile-menu-toggle"]').click();
77-
cy.contains('Dashboard').should('be.visible');
78-
cy.contains('Comparisons').should('be.visible');
79-
cy.contains('Supporters').should('be.visible');
75+
cy.get('[data-testid="nav-link-dashboard"]').should('not.be.visible');
76+
cy.get('[data-testid="mobile-menu-toggle"]')
77+
.should('be.visible')
78+
.and('have.attr', 'aria-expanded', 'false')
79+
.click()
80+
.should('have.attr', 'aria-expanded', 'true');
81+
cy.get('[data-testid="mobile-menu"]').within(() => {
82+
cy.contains('a', 'Dashboard').should('be.visible').and('have.attr', 'href', '/inference');
83+
cy.contains('a', 'Comparisons').should('be.visible').and('have.attr', 'href', '/compare');
84+
cy.contains('a', 'Supporters').should('be.visible').and('have.attr', 'href', '/quotes');
85+
});
8086
});
8187
});

packages/app/cypress/support/component-index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Components App</title>
7+
<!-- Used by Next.js to inject CSS. -->
8+
<noscript id="__next_css__DO_NOT_USE__"></noscript>
79
</head>
810
<body>
911
<div data-cy-root></div>

packages/app/cypress/support/component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { mount } from 'cypress/react';
22

3+
import '@/app/globals.css';
4+
35
declare global {
46
namespace Cypress {
57
interface Chainable {

packages/app/src/components/header/header.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ export const Header = ({ starCount }: { starCount?: number | null }) => {
215215
</svg>
216216
</button>
217217
{mobileMenuOpen && (
218-
<div className="absolute right-0 top-full mt-2 z-50 flex flex-col rounded-lg border border-border bg-background p-1.5 shadow-lg min-w-40">
218+
<div
219+
data-testid="mobile-menu"
220+
className="absolute right-0 top-full mt-2 z-50 flex flex-col rounded-lg border border-border bg-background p-1.5 shadow-lg min-w-40"
221+
>
219222
{navLinks.map(({ href, displayHref, label, event }) => (
220223
<Link
221224
key={href}

packages/app/src/components/ui/chart-selectors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function CategorySectionTitle({ label, reason }: { label: string; reason: string
7777
data-testid={`selector-category-${label.toLowerCase().replaceAll(' ', '-')}-info`}
7878
/>
7979
</TooltipTrigger>
80-
<TooltipContent side="top" collisionPadding={10}>
80+
<TooltipContent side="top" collisionPadding={10} className="z-[130]">
8181
<span>{reason}</span>
8282
</TooltipContent>
8383
</TooltipRoot>

0 commit comments

Comments
 (0)