Skip to content

Commit dc787d2

Browse files
committed
move tests to use stories for verification instead
1 parent 6fc49d1 commit dc787d2

File tree

6 files changed

+54
-67
lines changed

6 files changed

+54
-67
lines changed

code/addons/pseudo-states/src/preview/rewriteStyleSheet.test.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,6 @@ import { describe, expect, it } from 'vitest';
33
import { rewriteStyleSheet } from './rewriteStyleSheet';
44
import { splitSelectors } from './splitSelectors';
55

6-
function getNestedRule(rule: any, index: number) {
7-
if (!('cssRules' in rule)) {
8-
throw new Error('Cannot get nested rule, because the rule is not a CSSGroupingRule.', rule);
9-
}
10-
return (rule as CSSGroupingRule).cssRules[index];
11-
}
12-
13-
function ensureCSSStyleRule(rule: any) {
14-
if (!(rule instanceof CSSStyleRule)) {
15-
throw new Error(`Rule is not a CSSStyleRule, but a ${rule.constructor.name}`);
16-
}
17-
return rule;
18-
}
19-
20-
function ensureCSSLayerBlockRule(rule: any) {
21-
if (!(rule instanceof CSSLayerBlockRule)) {
22-
throw new Error(`Rule is not a BlockLayerRule, but a ${rule.constructor.name}`);
23-
}
24-
return rule;
25-
}
26-
27-
function ensureCSSMediaRule(rule: any) {
28-
if (!(rule instanceof CSSMediaRule)) {
29-
throw new Error(`Rule is not a CSSMediaRule, but a ${rule.constructor.name}`);
30-
}
31-
return rule;
32-
}
33-
346
function splitRules(cssText: string): string[] {
357
let ruleStart: number | undefined;
368
let depth = 0;
@@ -478,36 +450,6 @@ describe('rewriteStyleSheet', () => {
478450
expect(sheet.cssRules[3].getSelectors()).toContain('.pseudo-hover-all .test2');
479451
});
480452

481-
it('rewrites deeply nested rules', () => {
482-
const styleSheet = new CSSStyleSheet();
483-
styleSheet.replaceSync(
484-
`@layer utilities {
485-
.hover\\:text-red-500 {
486-
@media (hover: hover) {
487-
&:hover {
488-
color: var(--color-red-500);
489-
}
490-
}
491-
}
492-
}`
493-
);
494-
495-
rewriteStyleSheet(styleSheet);
496-
497-
const layerRule = ensureCSSLayerBlockRule(getNestedRule(styleSheet, 0));
498-
expect(layerRule.name).toBe('utilities');
499-
500-
const twSelector = ensureCSSStyleRule(getNestedRule(layerRule, 0));
501-
expect(twSelector.selectorText).toBe('.hover\\:text-red-500');
502-
503-
const media = ensureCSSMediaRule(getNestedRule(twSelector, 0));
504-
expect(media.conditionText).toBe('(hover: hover)');
505-
506-
const hover = ensureCSSStyleRule(getNestedRule(media, 0));
507-
expect(hover).toBeInstanceOf(CSSStyleRule);
508-
expect(hover.selectorText).toBe('&:hover, &.pseudo-hover, .pseudo-hover-all &');
509-
});
510-
511453
it('rewrites rules inside "@media"', () => {
512454
const sheet = new Sheet(
513455
`@media (max-width: 790px) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Meta, StoryObj } from '@storybook/react-vite';
2+
3+
import { Button } from './NestedRules';
4+
5+
const meta = {
6+
title: 'NestedRules',
7+
component: Button,
8+
render: (args, context) => <Button {...args}>{context.name}</Button>,
9+
} satisfies Meta<typeof Button>;
10+
11+
export default meta;
12+
13+
type Story = StoryObj<typeof meta>;
14+
15+
export const NestedHover: Story = {
16+
parameters: {
17+
pseudo: { focusVisible: true },
18+
},
19+
// TODO: Use this test once the pseudostates addon uses the beforeEach API
20+
// play: async ({ canvas }) => {
21+
// const button = canvas.getByRole('button')!;
22+
// await expect(getComputedStyle(button).textDecorationLine).toBe('underline');
23+
// await expect(getComputedStyle(button).textDecorationColor).toBe('rgb(255, 0, 0)');
24+
// },
25+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
import './nested.css';
4+
5+
export const Button = (props: React.ButtonHTMLAttributes<HTMLButtonElement>) => (
6+
<button className="nested-focus-visible" {...props} />
7+
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
button {
2+
display: inline-block;
3+
cursor: pointer;
4+
border: 0;
5+
border-radius: 3em;
6+
background-color: #1ea7fd;
7+
padding: 11px 20px;
8+
color: white;
9+
font-weight: 700;
10+
font-size: 14px;
11+
line-height: 1;
12+
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
13+
}
14+
15+
.nested-focus-visible {
16+
&:focus-visible {
17+
@supports (color: color-mix(in lab, red, red)) {
18+
text-decoration: underline red;
19+
}
20+
}
21+
}
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { defineConfig, mergeConfig } from 'vitest/config';
22

3-
import { playwright } from '@vitest/browser-playwright';
4-
53
import { vitestCommonConfig } from '../../vitest.shared';
64

75
export default mergeConfig(
@@ -11,12 +9,6 @@ export default mergeConfig(
119
typecheck: {
1210
enabled: true,
1311
},
14-
browser: {
15-
enabled: true,
16-
headless: true,
17-
provider: playwright(),
18-
instances: [{ browser: 'chromium' }],
19-
},
2012
},
2113
})
2214
);

scripts/ci/common-jobs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export const testsUnit_linux = defineJob(
239239
'Tests (linux)',
240240
(workflowName) => ({
241241
executor: {
242-
name: 'sb_playwright',
242+
name: 'sb_node_22_classic',
243243
class: 'large',
244244
},
245245
steps: [

0 commit comments

Comments
 (0)