Skip to content

Commit 8445221

Browse files
committed
Transform Layouts jest tests into playwright (#594)
1 parent 0cfcaa8 commit 8445221

File tree

203 files changed

+1658
-798
lines changed

Some content is hidden

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

203 files changed

+1658
-798
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
ButtonGroupForTest,
12+
SelectedButtonGroupForTest,
13+
} from './ButtonGroup.story';
14+
15+
test.describe('ButtonGroup', () => {
16+
test.describe('base', () => {
17+
test.describe('visual', () => {
18+
[
19+
...propTests.defaultComponentPropTest,
20+
...propTests.blockPropTest,
21+
...propTests.disabledPropTest,
22+
...propTests.sizePropTest,
23+
...mixPropTests([
24+
propTests.priorityPropTest,
25+
propTests.disabledPropTest,
26+
]),
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(<ButtonGroupForTest {...props} />);
42+
43+
if (onBeforeSnapshot) {
44+
await onBeforeSnapshot(page, component);
45+
}
46+
47+
const screenshot = await component.screenshot();
48+
expect(screenshot).toMatchSnapshot();
49+
});
50+
});
51+
52+
test.describe('selectedButton', () => {
53+
[
54+
...mixPropTests([
55+
propTests.priorityPropTest,
56+
propTests.disabledPropTest,
57+
]),
58+
].forEach(({
59+
name,
60+
onBeforeTest,
61+
onBeforeSnapshot,
62+
props,
63+
}) => {
64+
test(name, async ({
65+
mount,
66+
page,
67+
}) => {
68+
if (onBeforeTest) {
69+
await onBeforeTest(page);
70+
}
71+
72+
const component = await mount(<SelectedButtonGroupForTest {...props} />);
73+
74+
if (onBeforeSnapshot) {
75+
await onBeforeSnapshot(page, component);
76+
}
77+
78+
const screenshot = await component.screenshot();
79+
expect(screenshot).toMatchSnapshot();
80+
});
81+
});
82+
});
83+
});
84+
});
85+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import type { HTMLAttributes } from 'react';
3+
import { ButtonGroup } from '..';
4+
import { Button } from '../../Button';
5+
6+
// Types for story component will be improved when we have full TypeScript support
7+
type ButtonGroupForTestProps = HTMLAttributes<HTMLFieldSetElement>;
8+
9+
export const ButtonGroupForTest = ({
10+
...props
11+
}: ButtonGroupForTestProps) => (
12+
<ButtonGroup {...props}>
13+
<Button label="Button1" />
14+
<Button label="Button2" />
15+
<Button label="Button3" />
16+
</ButtonGroup>
17+
);
18+
19+
export const SelectedButtonGroupForTest = ({
20+
...props
21+
}: ButtonGroupForTestProps) => (
22+
<ButtonGroup {...props}>
23+
<Button color="selected" label="Button1" />
24+
<Button label="Button2" />
25+
<Button label="Button3" />
26+
</ButtonGroup>
27+
);
28+

src/components/ButtonGroup/__tests__/ButtonGroup.test.jsx

-77
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
import {
3+
expect,
4+
test,
5+
} from '@playwright/experimental-ct-react';
6+
import { propTests } from '../../../../tests/playwright';
7+
import {
8+
FormLayoutForTest,
9+
FormLayoutWithoutChildrenForTest,
10+
} from './FormLayout.story';
11+
import { labelWidthPropTest } from './_propTests/labelWidthPropTest';
12+
import { fieldLayoutPropTest } from './_propTests/fieldLayoutPropTest';
13+
14+
test.describe('FormLayout', () => {
15+
test.describe('base', () => {
16+
/**
17+
* `autoWidth` is not tested because subgrid is already supported in all browsers
18+
* we aim to support within RUI. The issue this property was intended to solve has
19+
* either already been resolved or cannot be reproduced with the tools
20+
* currently available to us.
21+
*/
22+
test.describe('visual', () => {
23+
[
24+
...propTests.defaultComponentPropTest,
25+
...labelWidthPropTest,
26+
...fieldLayoutPropTest,
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(<FormLayoutForTest {...props} />);
42+
43+
if (onBeforeSnapshot) {
44+
await onBeforeSnapshot(page, component);
45+
}
46+
47+
const screenshot = await component.screenshot();
48+
expect(screenshot).toMatchSnapshot();
49+
});
50+
});
51+
});
52+
53+
test.describe('non-visual', () => {
54+
test('pass id into root component', async ({ mount }) => {
55+
const id = 'custom-id';
56+
57+
const component = await mount(
58+
<FormLayoutForTest id={id} />,
59+
);
60+
61+
const root = await component.getAttribute('id');
62+
expect(root).toBe(id);
63+
});
64+
});
65+
66+
test.describe('functionality', () => {
67+
test('render null when no children provided', async ({ mount }) => {
68+
const component = await mount(
69+
<FormLayoutWithoutChildrenForTest />,
70+
);
71+
72+
const innerHTML = await component.innerHTML();
73+
expect(innerHTML).toBe('');
74+
});
75+
});
76+
});
77+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
import type { HTMLAttributes } from 'react';
3+
import {
4+
FormLayout,
5+
FormLayoutCustomField,
6+
} from '..';
7+
import { TextField } from '../../TextField';
8+
import { CheckboxField } from '../../CheckboxField';
9+
import { FileInputField } from '../../FileInputField';
10+
import { Radio } from '../../Radio';
11+
import { SelectField } from '../../SelectField';
12+
import { TextArea } from '../../TextArea';
13+
import { Toggle } from '../../Toggle';
14+
15+
// Types for story component will be improved when we have full TypeScript support
16+
type FormLayoutForTestProps = HTMLAttributes<HTMLDivElement>;
17+
18+
export const FormLayoutForTest = ({
19+
...props
20+
}: FormLayoutForTestProps) => (
21+
<FormLayout {...props}>
22+
<TextField
23+
label={
24+
'Another form element with a very long label that is so '
25+
+ 'long that in the auto mode, it should make the label column '
26+
+ 'grow until the inputs reach the end of the line, but it will '
27+
+ 'not exceed 50 % of the FormLayout width in the limited label '
28+
+ 'width mode'
29+
}
30+
/>
31+
<CheckboxField
32+
checked
33+
label="Label2"
34+
/>
35+
<Radio
36+
label="Label3"
37+
options={[
38+
{
39+
label: 'Value',
40+
value: 'value',
41+
},
42+
{
43+
label: 'Value2',
44+
value: 'value2',
45+
},
46+
]}
47+
value="value"
48+
/>
49+
<SelectField
50+
label="Label4"
51+
options={[
52+
{
53+
label: 'Value1',
54+
value: 'value1',
55+
},
56+
{
57+
label: 'Value2',
58+
value: 'value2',
59+
},
60+
]}
61+
value="value1"
62+
/>
63+
<TextArea label="Label5" />
64+
<Toggle
65+
checked={false}
66+
label="Label6"
67+
/>
68+
<FormLayoutCustomField label="Custom field label">
69+
<TextField label="Label7" />
70+
</FormLayoutCustomField>
71+
<FileInputField label="Attachment label 8" />
72+
</FormLayout>
73+
);
74+
75+
export const FormLayoutWithoutChildrenForTest = ({
76+
...props
77+
}: FormLayoutForTestProps) => (
78+
<FormLayout {...props} />
79+
);

0 commit comments

Comments
 (0)