Skip to content

Commit 0d1c727

Browse files
committed
fixup! Transform Layouts jest tests into playwright (#594)
1 parent 6944c3b commit 0d1c727

File tree

85 files changed

+290
-309
lines changed

Some content is hidden

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

85 files changed

+290
-309
lines changed

src/components/ButtonGroup/__tests__/ButtonGroup.spec.tsx

+1-64
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
import {
1111
ButtonGroupForTest,
1212
SelectedButtonGroupForTest,
13-
ButtonGroupWithFeedbackIconForTest,
14-
ButtonGroupWithLabelForTest,
1513
} from './ButtonGroup.story';
1614

1715
test.describe('ButtonGroup', () => {
@@ -21,9 +19,9 @@ test.describe('ButtonGroup', () => {
2119
...propTests.defaultComponentPropTest,
2220
...propTests.blockPropTest,
2321
...propTests.disabledPropTest,
22+
...propTests.sizePropTest,
2423
...mixPropTests([
2524
propTests.priorityPropTest,
26-
propTests.sizePropTest,
2725
propTests.disabledPropTest,
2826
]),
2927
].forEach(({
@@ -82,67 +80,6 @@ test.describe('ButtonGroup', () => {
8280
});
8381
});
8482
});
85-
86-
test.describe('buttonWithFeedbackIcon', () => {
87-
[
88-
...mixPropTests([
89-
propTests.priorityPropTest,
90-
propTests.disabledPropTest,
91-
]),
92-
].forEach(({
93-
name,
94-
onBeforeTest,
95-
onBeforeSnapshot,
96-
props,
97-
}) => {
98-
test(name, async ({
99-
mount,
100-
page,
101-
}) => {
102-
if (onBeforeTest) {
103-
await onBeforeTest(page);
104-
}
105-
106-
const component = await mount(<ButtonGroupWithFeedbackIconForTest {...props} />);
107-
108-
if (onBeforeSnapshot) {
109-
await onBeforeSnapshot(page, component);
110-
}
111-
112-
const screenshot = await component.screenshot();
113-
expect(screenshot).toMatchSnapshot();
114-
});
115-
});
116-
});
117-
118-
test.describe('groupLabel', () => {
119-
[
120-
...propTests.defaultComponentPropTest,
121-
].forEach(({
122-
name,
123-
onBeforeTest,
124-
onBeforeSnapshot,
125-
props,
126-
}) => {
127-
test(name, async ({
128-
mount,
129-
page,
130-
}) => {
131-
if (onBeforeTest) {
132-
await onBeforeTest(page);
133-
}
134-
135-
const component = await mount(<ButtonGroupWithLabelForTest {...props} />);
136-
137-
if (onBeforeSnapshot) {
138-
await onBeforeSnapshot(page, component);
139-
}
140-
141-
const screenshot = await component.screenshot();
142-
expect(screenshot).toMatchSnapshot();
143-
});
144-
});
145-
});
14683
});
14784
});
14885
});

src/components/ButtonGroup/__tests__/ButtonGroup.story.tsx

-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import type { HTMLAttributes } from 'react';
33
import { ButtonGroup } from '..';
44
import { Button } from '../../Button';
5-
import { TestIcon } from '../../../../tests/playwright';
65

76
// Types for story component will be improved when we have full TypeScript support
87
type ButtonGroupForTestProps = HTMLAttributes<HTMLFieldSetElement>;
@@ -27,31 +26,3 @@ export const SelectedButtonGroupForTest = ({
2726
</ButtonGroup>
2827
);
2928

30-
export const ButtonGroupWithFeedbackIconForTest = ({
31-
...props
32-
}: ButtonGroupForTestProps) => (
33-
<ButtonGroup {...props}>
34-
<Button
35-
feedbackIcon={<TestIcon />}
36-
label="Button1"
37-
/>
38-
<Button label="Button2" />
39-
<Button label="Button3" />
40-
</ButtonGroup>
41-
);
42-
43-
export const ButtonGroupWithLabelForTest = ({
44-
...props
45-
}: ButtonGroupForTestProps) => (
46-
<>
47-
<label htmlFor="label" id="label">Group label:</label>
48-
<ButtonGroup
49-
{...props}
50-
aria-labelledby="label"
51-
>
52-
<Button label="Button1" />
53-
<Button label="Button2" />
54-
<Button label="Button3" />
55-
</ButtonGroup>
56-
</>
57-
);

src/components/FormLayout/__tests__/FormLayout.spec.tsx

+4-105
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@ import {
66
import { propTests } from '../../../../tests/playwright';
77
import {
88
FormLayoutForTest,
9-
FormLayoutWithCustomFieldForTest,
109
FormLayoutWithoutChildrenForTest,
1110
} from './FormLayout.story';
12-
import { fieldWidthPropTest } from './_propTests/fieldWidthPropTest';
11+
import { labelWidthPropTest } from './_propTests/labelWidthPropTest';
1312
import { fieldLayoutPropTest } from './_propTests/fieldLayoutPropTest';
14-
import { autoWidthPropTest } from './_propTests/autoWidthPropTest';
15-
import { customFieldLabelAlignmentPropTest } from './_propTests/customFieldTests/customFieldLabelAlignmentPropTest';
16-
import { customFieldValidationStatesPropTest } from './_propTests/customFieldTests/customFieldValidationStatesPropTest';
17-
import { customFieldInnerFieldSizePropTest } from './_propTests/customFieldTests/customFieldInnerFieldSizePropTest';
18-
import { customFieldRequiredPropTest } from './_propTests/customFieldTests/customFieldRequiredPropTest';
1913

2014
test.describe('FormLayout', () => {
2115
test.describe('base', () => {
2216
test.describe('visual', () => {
2317
[
2418
...propTests.defaultComponentPropTest,
25-
...fieldWidthPropTest,
26-
...autoWidthPropTest,
19+
...labelWidthPropTest,
2720
...fieldLayoutPropTest,
2821
].forEach(({
2922
name,
@@ -52,7 +45,7 @@ test.describe('FormLayout', () => {
5245
});
5346

5447
test.describe('non-visual', () => {
55-
test('Pass id into root component', async ({ mount }) => {
48+
test('pass id into root component', async ({ mount }) => {
5649
const id = 'custom-id';
5750

5851
const component = await mount(
@@ -65,7 +58,7 @@ test.describe('FormLayout', () => {
6558
});
6659

6760
test.describe('functionality', () => {
68-
test('Render null when no children provided', async ({ mount }) => {
61+
test('render null when no children provided', async ({ mount }) => {
6962
const component = await mount(
7063
<FormLayoutWithoutChildrenForTest />,
7164
);
@@ -75,98 +68,4 @@ test.describe('FormLayout', () => {
7568
});
7669
});
7770
});
78-
79-
test.describe('withCustomField', () => {
80-
test.describe('visual', () => {
81-
[
82-
...customFieldLabelAlignmentPropTest,
83-
...customFieldValidationStatesPropTest,
84-
...customFieldInnerFieldSizePropTest,
85-
...customFieldRequiredPropTest,
86-
].forEach(({
87-
name,
88-
onBeforeTest,
89-
onBeforeSnapshot,
90-
props,
91-
customFieldLayoutProps,
92-
customFieldProps,
93-
}) => {
94-
test(name, async ({
95-
mount,
96-
page,
97-
}) => {
98-
if (onBeforeTest) {
99-
await onBeforeTest(page);
100-
}
101-
102-
const component = await mount(
103-
<FormLayoutWithCustomFieldForTest
104-
{...props}
105-
customFieldLayoutProps={customFieldLayoutProps}
106-
customFieldProps={customFieldProps}
107-
/>,
108-
);
109-
110-
if (onBeforeSnapshot) {
111-
await onBeforeSnapshot(page, component);
112-
}
113-
114-
const screenshot = await component.screenshot();
115-
expect(screenshot).toMatchSnapshot();
116-
});
117-
});
118-
});
119-
120-
test.describe('non-visual', () => {
121-
test('Pass id into custom field', async ({ mount }) => {
122-
const id = 'custom-id';
123-
124-
const component = await mount(
125-
<FormLayoutWithCustomFieldForTest
126-
customFieldLayoutProps={{
127-
fieldLayout: 'horizontal',
128-
id,
129-
label: 'CustomLayoutFieldLabel',
130-
}}
131-
customFieldProps={{
132-
label: 'CustomFieldLabel',
133-
}}
134-
/>,
135-
);
136-
137-
await expect(component.locator(`div[id=${id}]`)).not.toBeEmpty();
138-
await expect(component.locator(`div[id=${id}__label]`)).not.toBeEmpty();
139-
await expect(component.locator(`div[id=${id}__field]`)).not.toBeEmpty();
140-
});
141-
142-
test('Render label with labelForId', async ({ mount }) => {
143-
const id = 'custom-id';
144-
const labelForId = 'custom-labelForId';
145-
146-
const component = await mount(
147-
<FormLayoutWithCustomFieldForTest
148-
customFieldLayoutProps={{
149-
id,
150-
label: 'CustomFieldLabel',
151-
labelForId,
152-
}}
153-
customFieldProps={{
154-
label: 'CustomFieldLabel',
155-
}}
156-
/>,
157-
);
158-
159-
await expect(component.locator(`label[id=${id}__label][for=${labelForId}]`)).not.toBeEmpty();
160-
});
161-
});
162-
163-
test.describe('functionality', () => {
164-
test('Render null when no children to custom field provided', async ({ mount }) => {
165-
const component = await mount(<FormLayoutWithCustomFieldForTest />);
166-
167-
const numberOfInputComponents = await component.getByRole('textbox').count();
168-
expect(numberOfInputComponents).toBe(2);
169-
});
170-
});
171-
});
17271
});

src/components/FormLayout/__tests__/FormLayout.story.tsx

+56-25
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,70 @@ import {
55
FormLayoutCustomField,
66
} from '..';
77
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';
814

915
// Types for story component will be improved when we have full TypeScript support
1016
type FormLayoutForTestProps = HTMLAttributes<HTMLDivElement>;
11-
type FormLayoutWithCustomFieldForTestProps = FormLayoutForTestProps & {
12-
customFieldLayoutProps: HTMLAttributes<HTMLDivElement>;
13-
customFieldProps: HTMLAttributes<HTMLDivElement>;
14-
};
1517

1618
export const FormLayoutForTest = ({
1719
...props
1820
}: FormLayoutForTestProps) => (
1921
<FormLayout {...props}>
20-
<TextField label="Label1" />
21-
<TextField label="Label2" />
22-
<TextField label="Label3" />
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" />
2372
</FormLayout>
2473
);
2574

@@ -28,21 +77,3 @@ export const FormLayoutWithoutChildrenForTest = ({
2877
}: FormLayoutForTestProps) => (
2978
<FormLayout {...props} />
3079
);
31-
32-
export const FormLayoutWithCustomFieldForTest = (props: FormLayoutWithCustomFieldForTestProps) => {
33-
const {
34-
customFieldLayoutProps,
35-
customFieldProps,
36-
...restProps
37-
} = props;
38-
39-
return (
40-
<FormLayout {...restProps}>
41-
<TextField label="Label1" />
42-
<TextField label="Label2" />
43-
<FormLayoutCustomField {...customFieldLayoutProps}>
44-
{customFieldProps ? <TextField {...customFieldProps} /> : null}
45-
</FormLayoutCustomField>
46-
</FormLayout>
47-
);
48-
};

0 commit comments

Comments
 (0)