Skip to content

Commit 6ddc1df

Browse files
lukasbrizabedrich-schindler
authored andcommitted
Transform miscellaneous section form jest to playwright (#595)
1 parent b5ca4ad commit 6ddc1df

File tree

97 files changed

+1303
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1303
-529
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import {
3+
expect,
4+
test,
5+
} from '@playwright/experimental-ct-react';
6+
import {
7+
mixPropTests,
8+
propTests,
9+
} from '../../../../tests/playwright';
10+
import { BadgeForTest } from './Badge.story';
11+
import { labelPropTest } from './_propTests/labelPropTest';
12+
import { priorityPropTest } from './_propTests/priorityPropTest';
13+
14+
test.describe('Badge', () => {
15+
test.describe('visual', () => {
16+
[
17+
...propTests.defaultComponentPropTest,
18+
...labelPropTest,
19+
...mixPropTests([
20+
[
21+
...propTests.feedbackColorPropTest,
22+
...propTests.neutralColorPropTest,
23+
],
24+
priorityPropTest,
25+
]),
26+
].forEach(({
27+
name,
28+
onBeforeTest,
29+
onBeforeSnapshot,
30+
props,
31+
}) => {
32+
test(name, async ({
33+
mount,
34+
page,
35+
}) => {
36+
if (onBeforeTest) {
37+
await onBeforeTest(page);
38+
}
39+
40+
const component = await mount(
41+
<BadgeForTest
42+
{...props}
43+
/>,
44+
);
45+
46+
if (onBeforeSnapshot) {
47+
await onBeforeSnapshot(page, component);
48+
}
49+
50+
const screenshot = await component.screenshot();
51+
expect(screenshot).toMatchSnapshot();
52+
});
53+
});
54+
});
55+
56+
test.describe('non-visual', () => {
57+
test('id', async ({ mount }) => {
58+
const component = await mount(
59+
<BadgeForTest
60+
id="test-id"
61+
/>,
62+
);
63+
64+
await expect(component).toHaveAttribute('id', 'test-id');
65+
});
66+
});
67+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import type { HTMLAttributes } from 'react';
3+
import { Badge } from '..';
4+
5+
// Types for story component will be improved when we have full TypeScript support
6+
type BadgeForTestProps = HTMLAttributes<HTMLDivElement>;
7+
8+
export const BadgeForTest = ({
9+
...props
10+
}: BadgeForTestProps) => (
11+
<Badge label="Badge label" {...props} />
12+
);

src/components/Badge/__tests__/Badge.test.jsx

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { propTests } from '../../../../../tests/playwright';
2+
import type { PropTests } from '../../../../../tests/playwright/types';
3+
4+
export const labelPropTest: PropTests = [
5+
...propTests.labelPropTest.filter((test) => typeof test.props?.label === 'string'),
6+
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { propTests } from '../../../../../tests/playwright';
2+
import type { PropTests } from '../../../../../tests/playwright/types';
3+
4+
const subsetOfValues = [
5+
'filled',
6+
'outline',
7+
];
8+
9+
export const priorityPropTest: PropTests = propTests.priorityPropTest
10+
.filter(({ props }) => subsetOfValues.includes(props.priority as string));
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import React from 'react';
2+
import {
3+
expect,
4+
test,
5+
} from '@playwright/experimental-ct-react';
6+
import {
7+
mixPropTests,
8+
propTests,
9+
} from '../../../../tests/playwright';
10+
import {
11+
CadForTest,
12+
CadWithScrollableForTest,
13+
CardOnlyWithBodyForTest,
14+
} from './Card.story';
15+
import { densePropTest } from './_propTests/densePropTest';
16+
17+
test.describe('Card', () => {
18+
test.describe('visual', () => {
19+
[
20+
...propTests.defaultComponentPropTest,
21+
...densePropTest,
22+
...mixPropTests([
23+
propTests.disabledPropTest,
24+
propTests.feedbackColorPropTest,
25+
]),
26+
...propTests.raisedPropTest,
27+
].forEach(({
28+
name,
29+
onBeforeTest,
30+
onBeforeSnapshot,
31+
props,
32+
}) => {
33+
test(name, async ({
34+
mount,
35+
page,
36+
}) => {
37+
if (onBeforeTest) {
38+
await onBeforeTest(page);
39+
}
40+
41+
const component = await mount(
42+
<CadForTest
43+
{...props}
44+
/>,
45+
);
46+
47+
if (onBeforeSnapshot) {
48+
await onBeforeSnapshot(page, component);
49+
}
50+
51+
const screenshot = await component.screenshot();
52+
expect(screenshot).toMatchSnapshot();
53+
});
54+
});
55+
56+
test.describe('composition', () => {
57+
/**
58+
* Card with body and footer is omitted from composition section, because
59+
* it is included in base visual tests.
60+
*/
61+
test.describe('onlyBody', () => {
62+
[
63+
...propTests.defaultComponentPropTest,
64+
].forEach(({
65+
name,
66+
onBeforeTest,
67+
onBeforeSnapshot,
68+
props,
69+
}) => {
70+
test(name, async ({
71+
mount,
72+
page,
73+
}) => {
74+
if (onBeforeTest) {
75+
await onBeforeTest(page);
76+
}
77+
78+
const component = await mount(
79+
<CardOnlyWithBodyForTest
80+
{...props}
81+
/>,
82+
);
83+
84+
if (onBeforeSnapshot) {
85+
await onBeforeSnapshot(page, component);
86+
}
87+
88+
const screenshot = await component.screenshot({ animations: 'disabled' });
89+
expect(screenshot).toMatchSnapshot();
90+
});
91+
});
92+
});
93+
94+
test.describe('scrollView', () => {
95+
[
96+
...propTests.defaultComponentPropTest,
97+
].forEach(({
98+
name,
99+
onBeforeTest,
100+
onBeforeSnapshot,
101+
props,
102+
}) => {
103+
test(name, async ({
104+
mount,
105+
page,
106+
}) => {
107+
if (onBeforeTest) {
108+
await onBeforeTest(page);
109+
}
110+
111+
const component = await mount(
112+
<CadWithScrollableForTest
113+
{...props}
114+
/>,
115+
);
116+
117+
if (onBeforeSnapshot) {
118+
await onBeforeSnapshot(page, component);
119+
}
120+
121+
const screenshot = await component.screenshot({ animations: 'disabled' });
122+
expect(screenshot).toMatchSnapshot();
123+
});
124+
});
125+
});
126+
});
127+
});
128+
129+
test.describe('non-visual', () => {
130+
test('id', async ({ mount }) => {
131+
const id = 'test-id';
132+
133+
const component = await mount(
134+
<CadForTest
135+
id={id}
136+
/>,
137+
);
138+
139+
await expect(component.locator(`div[id=${id}]`)).toHaveAttribute('id', id);
140+
});
141+
});
142+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from 'react';
2+
import type { HTMLAttributes } from 'react';
3+
import {
4+
Card,
5+
CardBody,
6+
CardFooter,
7+
} from '..';
8+
import { TextLink } from '../../TextLink';
9+
import { Button } from '../../Button';
10+
import { ScrollView } from '../../ScrollView';
11+
12+
// Types for story component will be improved when we have full TypeScript support
13+
type CardForTestProps = HTMLAttributes<HTMLDivElement>;
14+
15+
export const CadForTest = ({
16+
...props
17+
}: CardForTestProps) => (
18+
<div style={{ padding: '20px' }}>
19+
<Card {...props}>
20+
<CardBody>
21+
This is a card body.
22+
<TextLink href="/" label="This is a link" />
23+
</CardBody>
24+
<CardFooter>
25+
<Button label="Footer button" />
26+
</CardFooter>
27+
</Card>
28+
</div>
29+
);
30+
31+
export const CadWithScrollableForTest = ({
32+
...props
33+
}: CardForTestProps) => (
34+
<div
35+
style={{
36+
display: 'flex',
37+
height: '400px',
38+
padding: '20px',
39+
width: '500px',
40+
}}
41+
>
42+
<Card {...props}>
43+
<ScrollView arrows>
44+
<CardBody id="card-body">
45+
Hello! I&apos;m scrollable card.
46+
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo
47+
ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis
48+
dis parturient montes, nascetur ridiculus mus. Donec quam felis,
49+
ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa
50+
quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget,
51+
arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
52+
Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras
53+
dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend
54+
tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac,
55+
enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.
56+
Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean
57+
imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper
58+
ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus
59+
eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing
60+
sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar,
61+
hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus.
62+
<TextLink href="/" label="This is a link" />
63+
</CardBody>
64+
</ScrollView>
65+
<CardFooter>
66+
<Button label="Footer button" />
67+
</CardFooter>
68+
</Card>
69+
</div>
70+
);
71+
72+
export const CardOnlyWithBodyForTest = ({
73+
...props
74+
}: CardForTestProps) => (
75+
<div style={{ padding: '20px' }}>
76+
<Card {...props}>
77+
<CardBody>
78+
This is a card body.
79+
<TextLink href="/" label="This is a link" />
80+
</CardBody>
81+
</Card>
82+
</div>
83+
);

0 commit comments

Comments
 (0)