@khanacademy/wonder-blocks-form 4.9.2 → 4.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/components/checkbox-core.d.ts +2 -2
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/choice-internal.d.ts +2 -2
- package/dist/components/choice.d.ts +2 -2
- package/dist/components/labeled-text-field.d.ts +9 -1
- package/dist/components/radio-core.d.ts +2 -2
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/text-area.d.ts +2 -2
- package/dist/components/text-field.d.ts +10 -5
- package/dist/es/index.js +93 -48
- package/dist/index.js +93 -48
- package/package.json +7 -7
- package/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap +0 -247
- package/src/__tests__/custom-snapshot.test.tsx +0 -48
- package/src/components/__tests__/checkbox-group.test.tsx +0 -162
- package/src/components/__tests__/checkbox.test.tsx +0 -138
- package/src/components/__tests__/field-heading.test.tsx +0 -225
- package/src/components/__tests__/labeled-text-field.test.tsx +0 -750
- package/src/components/__tests__/radio-group.test.tsx +0 -182
- package/src/components/__tests__/text-area.test.tsx +0 -1286
- package/src/components/__tests__/text-field.test.tsx +0 -562
- package/src/components/checkbox-core.tsx +0 -239
- package/src/components/checkbox-group.tsx +0 -174
- package/src/components/checkbox.tsx +0 -99
- package/src/components/choice-internal.tsx +0 -184
- package/src/components/choice.tsx +0 -157
- package/src/components/field-heading.tsx +0 -169
- package/src/components/group-styles.ts +0 -33
- package/src/components/labeled-text-field.tsx +0 -317
- package/src/components/radio-core.tsx +0 -171
- package/src/components/radio-group.tsx +0 -159
- package/src/components/radio.tsx +0 -82
- package/src/components/text-area.tsx +0 -430
- package/src/components/text-field.tsx +0 -399
- package/src/index.ts +0 -17
- package/src/util/types.ts +0 -85
- package/tsconfig-build.json +0 -19
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import {userEvent} from "@testing-library/user-event";
|
|
4
|
-
|
|
5
|
-
import CheckboxGroup from "../checkbox-group";
|
|
6
|
-
import Choice from "../choice";
|
|
7
|
-
|
|
8
|
-
describe("CheckboxGroup", () => {
|
|
9
|
-
describe("behavior", () => {
|
|
10
|
-
const TestComponent = ({errorMessage}: {errorMessage?: string}) => {
|
|
11
|
-
const [selectedValues, setSelectedValue] = React.useState([
|
|
12
|
-
"a",
|
|
13
|
-
"b",
|
|
14
|
-
]);
|
|
15
|
-
const handleChange = (selectedValues: any) => {
|
|
16
|
-
setSelectedValue(selectedValues);
|
|
17
|
-
};
|
|
18
|
-
return (
|
|
19
|
-
<CheckboxGroup
|
|
20
|
-
label="Test"
|
|
21
|
-
description="test description"
|
|
22
|
-
groupName="test"
|
|
23
|
-
onChange={handleChange}
|
|
24
|
-
selectedValues={selectedValues}
|
|
25
|
-
errorMessage={errorMessage}
|
|
26
|
-
>
|
|
27
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
28
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
29
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
30
|
-
</CheckboxGroup>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
it("has the correct items checked", async () => {
|
|
35
|
-
// Arrange, Act
|
|
36
|
-
render(<TestComponent />);
|
|
37
|
-
|
|
38
|
-
const checkboxes = screen.getAllByRole("checkbox");
|
|
39
|
-
|
|
40
|
-
// Assert
|
|
41
|
-
// a starts off checked
|
|
42
|
-
expect(checkboxes[0]).toBeChecked();
|
|
43
|
-
expect(checkboxes[1]).toBeChecked();
|
|
44
|
-
expect(checkboxes[2]).not.toBeChecked();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("clicking a selected choice deselects it", async () => {
|
|
48
|
-
// Arrange
|
|
49
|
-
render(<TestComponent />);
|
|
50
|
-
|
|
51
|
-
const checkboxes = screen.getAllByRole("checkbox");
|
|
52
|
-
|
|
53
|
-
// Act
|
|
54
|
-
await userEvent.click(checkboxes[0]);
|
|
55
|
-
|
|
56
|
-
// Assert
|
|
57
|
-
expect(checkboxes[0]).not.toBeChecked();
|
|
58
|
-
expect(checkboxes[1]).toBeChecked();
|
|
59
|
-
expect(checkboxes[2]).not.toBeChecked();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should set aria-invalid on choices when there's an error message", async () => {
|
|
63
|
-
// Arrange, Act
|
|
64
|
-
render(<TestComponent errorMessage="there's an error" />);
|
|
65
|
-
|
|
66
|
-
const checkboxes = screen.getAllByRole("checkbox");
|
|
67
|
-
|
|
68
|
-
// Assert
|
|
69
|
-
expect(checkboxes[0]).toHaveAttribute("aria-invalid", "true");
|
|
70
|
-
expect(checkboxes[1]).toHaveAttribute("aria-invalid", "true");
|
|
71
|
-
expect(checkboxes[2]).toHaveAttribute("aria-invalid", "true");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("checks that aria attributes have been added correctly", async () => {
|
|
75
|
-
// Arrange, Act
|
|
76
|
-
render(<TestComponent />);
|
|
77
|
-
|
|
78
|
-
const checkboxes = screen.getAllByRole("checkbox");
|
|
79
|
-
|
|
80
|
-
// Assert
|
|
81
|
-
expect(checkboxes[0]).toHaveAttribute("aria-labelledby", "test-a");
|
|
82
|
-
expect(checkboxes[1]).toHaveAttribute("aria-labelledby", "test-b");
|
|
83
|
-
expect(checkboxes[2]).toHaveAttribute("aria-labelledby", "test-c");
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe("flexible props", () => {
|
|
88
|
-
it("should render with a React.Node label", async () => {
|
|
89
|
-
// Arrange, Act
|
|
90
|
-
render(
|
|
91
|
-
<CheckboxGroup
|
|
92
|
-
label={
|
|
93
|
-
<span>
|
|
94
|
-
label with <strong>strong</strong> text
|
|
95
|
-
</span>
|
|
96
|
-
}
|
|
97
|
-
groupName="test"
|
|
98
|
-
onChange={() => {}}
|
|
99
|
-
selectedValues={[]}
|
|
100
|
-
>
|
|
101
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
102
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
103
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
104
|
-
</CheckboxGroup>,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Assert
|
|
108
|
-
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should render with a React.Node description", async () => {
|
|
112
|
-
// Arrange, Act
|
|
113
|
-
render(
|
|
114
|
-
<CheckboxGroup
|
|
115
|
-
label="label"
|
|
116
|
-
description={
|
|
117
|
-
<span>
|
|
118
|
-
description with <strong>strong</strong> text
|
|
119
|
-
</span>
|
|
120
|
-
}
|
|
121
|
-
groupName="test"
|
|
122
|
-
onChange={() => {}}
|
|
123
|
-
selectedValues={[]}
|
|
124
|
-
>
|
|
125
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
126
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
127
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
128
|
-
</CheckboxGroup>,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// Assert
|
|
132
|
-
expect(await screen.findByText("strong")).toBeInTheDocument();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("should filter out false-y children when rendering", async () => {
|
|
136
|
-
// Arrange, Act
|
|
137
|
-
render(
|
|
138
|
-
<CheckboxGroup
|
|
139
|
-
label="label"
|
|
140
|
-
description="description"
|
|
141
|
-
groupName="test"
|
|
142
|
-
onChange={() => {}}
|
|
143
|
-
selectedValues={[]}
|
|
144
|
-
>
|
|
145
|
-
<Choice label="a" value="a" aria-labelledby="test-a" />
|
|
146
|
-
{/* eslint-disable-next-line no-constant-condition */}
|
|
147
|
-
{false ? (
|
|
148
|
-
<Choice label="b" value="b" aria-labelledby="test-b" />
|
|
149
|
-
) : null}
|
|
150
|
-
<Choice label="c" value="c" aria-labelledby="test-c" />
|
|
151
|
-
{undefined}
|
|
152
|
-
{null}
|
|
153
|
-
</CheckboxGroup>,
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
// Assert
|
|
157
|
-
const checkboxes = screen.getAllByRole("checkbox");
|
|
158
|
-
|
|
159
|
-
expect(checkboxes).toHaveLength(2);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
});
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
|
|
4
|
-
import Checkbox from "../checkbox";
|
|
5
|
-
|
|
6
|
-
describe("Checkbox", () => {
|
|
7
|
-
test("uses the ID prop when it is specified", () => {
|
|
8
|
-
// Arrange, Act
|
|
9
|
-
render(
|
|
10
|
-
<Checkbox
|
|
11
|
-
id="specified-checkbox-id"
|
|
12
|
-
label="Receive assignment reminders for Algebra"
|
|
13
|
-
description="You will receive a reminder 24 hours before each deadline"
|
|
14
|
-
checked={false}
|
|
15
|
-
onChange={() => {}}
|
|
16
|
-
/>,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const checkbox = screen.getByRole("checkbox");
|
|
20
|
-
|
|
21
|
-
// Assert
|
|
22
|
-
expect(checkbox).toHaveAttribute("id", "specified-checkbox-id");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("provides a unique ID when the ID prop is not specified", () => {
|
|
26
|
-
// Arrange, Act
|
|
27
|
-
render(
|
|
28
|
-
<Checkbox
|
|
29
|
-
label="Receive assignment reminders for Algebra"
|
|
30
|
-
description="You will receive a reminder 24 hours before each deadline"
|
|
31
|
-
checked={false}
|
|
32
|
-
onChange={() => {}}
|
|
33
|
-
/>,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const checkbox = screen.getByRole("checkbox");
|
|
37
|
-
|
|
38
|
-
// Assert
|
|
39
|
-
expect(checkbox).toHaveAttribute("id", "uid-choice-1-main");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("clicking the checkbox triggers `onChange`", () => {
|
|
43
|
-
// Arrange
|
|
44
|
-
const onChangeSpy = jest.fn();
|
|
45
|
-
render(
|
|
46
|
-
<Checkbox
|
|
47
|
-
label="Receive assignment reminders for Algebra"
|
|
48
|
-
description="You will receive a reminder 24 hours before each deadline"
|
|
49
|
-
checked={false}
|
|
50
|
-
onChange={onChangeSpy}
|
|
51
|
-
/>,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Act
|
|
55
|
-
const checkbox = screen.getByRole("checkbox");
|
|
56
|
-
checkbox.click();
|
|
57
|
-
|
|
58
|
-
// Assert
|
|
59
|
-
expect(onChangeSpy).toHaveBeenCalled();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("clicks the label triggers `onChange`", () => {
|
|
63
|
-
// Arrange
|
|
64
|
-
const onChangeSpy = jest.fn();
|
|
65
|
-
render(
|
|
66
|
-
<Checkbox
|
|
67
|
-
label="Receive assignment reminders for Algebra"
|
|
68
|
-
description="You will receive a reminder 24 hours before each deadline"
|
|
69
|
-
checked={false}
|
|
70
|
-
onChange={onChangeSpy}
|
|
71
|
-
/>,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
// Act
|
|
75
|
-
const checkboxLabel = screen.getByText(
|
|
76
|
-
"Receive assignment reminders for Algebra",
|
|
77
|
-
);
|
|
78
|
-
checkboxLabel.click();
|
|
79
|
-
|
|
80
|
-
// Assert
|
|
81
|
-
expect(onChangeSpy).toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test.each`
|
|
85
|
-
indeterminateValue | checkedValue
|
|
86
|
-
${true} | ${null}
|
|
87
|
-
${false} | ${true}
|
|
88
|
-
${false} | ${false}
|
|
89
|
-
`(
|
|
90
|
-
"sets the indeterminate property to $indeterminateValue when checked is $checkedValue (with ref)",
|
|
91
|
-
({indeterminateValue, checkedValue}) => {
|
|
92
|
-
// Arrange
|
|
93
|
-
const ref = React.createRef<HTMLInputElement>();
|
|
94
|
-
|
|
95
|
-
// Act
|
|
96
|
-
render(
|
|
97
|
-
<Checkbox
|
|
98
|
-
label="Some label"
|
|
99
|
-
description="Some description"
|
|
100
|
-
checked={checkedValue}
|
|
101
|
-
onChange={() => {}}
|
|
102
|
-
ref={ref}
|
|
103
|
-
/>,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Assert
|
|
107
|
-
expect(ref?.current?.indeterminate).toBe(indeterminateValue);
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
test.each`
|
|
112
|
-
indeterminateValue | checkedValue
|
|
113
|
-
${true} | ${null}
|
|
114
|
-
${false} | ${true}
|
|
115
|
-
${false} | ${false}
|
|
116
|
-
`(
|
|
117
|
-
"sets the indeterminate property to $indeterminateValue when checked is $checkedValue (innerRef)",
|
|
118
|
-
({indeterminateValue, checkedValue}) => {
|
|
119
|
-
// Arrange
|
|
120
|
-
render(
|
|
121
|
-
<Checkbox
|
|
122
|
-
label="Some label"
|
|
123
|
-
description="Some description"
|
|
124
|
-
checked={checkedValue}
|
|
125
|
-
onChange={() => {}}
|
|
126
|
-
/>,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Act
|
|
130
|
-
const inputElement = screen.getByRole(
|
|
131
|
-
"checkbox",
|
|
132
|
-
) as HTMLInputElement;
|
|
133
|
-
|
|
134
|
-
// Assert
|
|
135
|
-
expect(inputElement.indeterminate).toBe(indeterminateValue);
|
|
136
|
-
},
|
|
137
|
-
);
|
|
138
|
-
});
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {render, screen} from "@testing-library/react";
|
|
3
|
-
import {StyleSheet} from "aphrodite";
|
|
4
|
-
|
|
5
|
-
import {I18nInlineMarkup} from "@khanacademy/wonder-blocks-i18n";
|
|
6
|
-
import {Body} from "@khanacademy/wonder-blocks-typography";
|
|
7
|
-
|
|
8
|
-
import FieldHeading from "../field-heading";
|
|
9
|
-
import TextField from "../text-field";
|
|
10
|
-
|
|
11
|
-
describe("FieldHeading", () => {
|
|
12
|
-
it("fieldheading renders the label text", () => {
|
|
13
|
-
// Arrange
|
|
14
|
-
const label = "Label";
|
|
15
|
-
|
|
16
|
-
// Act
|
|
17
|
-
render(
|
|
18
|
-
<FieldHeading
|
|
19
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
20
|
-
label={label}
|
|
21
|
-
/>,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
// Assert
|
|
25
|
-
expect(screen.getByText(label)).toBeInTheDocument();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("fieldheading renders the description text", () => {
|
|
29
|
-
// Arrange
|
|
30
|
-
const description = "Description";
|
|
31
|
-
|
|
32
|
-
// Act
|
|
33
|
-
render(
|
|
34
|
-
<FieldHeading
|
|
35
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
36
|
-
label="Label"
|
|
37
|
-
description={description}
|
|
38
|
-
/>,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// Assert
|
|
42
|
-
expect(screen.getByText(description)).toBeInTheDocument();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("fieldheading renders the error text", () => {
|
|
46
|
-
// Arrange
|
|
47
|
-
const error = "Error";
|
|
48
|
-
|
|
49
|
-
// Act
|
|
50
|
-
render(
|
|
51
|
-
<FieldHeading
|
|
52
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
53
|
-
label="Label"
|
|
54
|
-
error={error}
|
|
55
|
-
/>,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// Assert
|
|
59
|
-
expect(screen.getByRole("alert")).toBeInTheDocument();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("fieldheading adds testId to label", () => {
|
|
63
|
-
// Arrange
|
|
64
|
-
const testId = "testid";
|
|
65
|
-
|
|
66
|
-
// Act
|
|
67
|
-
render(
|
|
68
|
-
<FieldHeading
|
|
69
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
70
|
-
label="Label"
|
|
71
|
-
testId={testId}
|
|
72
|
-
/>,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Assert
|
|
76
|
-
const label = screen.getByTestId(`${testId}-label`);
|
|
77
|
-
expect(label).toBeInTheDocument();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("fieldheading adds testId to description", () => {
|
|
81
|
-
// Arrange
|
|
82
|
-
const testId = "testid";
|
|
83
|
-
|
|
84
|
-
// Act
|
|
85
|
-
render(
|
|
86
|
-
<FieldHeading
|
|
87
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
88
|
-
label="Label"
|
|
89
|
-
description="Description"
|
|
90
|
-
testId={testId}
|
|
91
|
-
/>,
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Assert
|
|
95
|
-
const description = screen.getByTestId(`${testId}-description`);
|
|
96
|
-
expect(description).toBeInTheDocument();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("fieldheading adds testId to error", () => {
|
|
100
|
-
// Arrange
|
|
101
|
-
const testId = "testid";
|
|
102
|
-
|
|
103
|
-
// Act
|
|
104
|
-
render(
|
|
105
|
-
<FieldHeading
|
|
106
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
107
|
-
label="Label"
|
|
108
|
-
error="Error"
|
|
109
|
-
testId={testId}
|
|
110
|
-
/>,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Assert
|
|
114
|
-
const error = screen.getByTestId(`${testId}-error`);
|
|
115
|
-
expect(error).toBeInTheDocument();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("fieldheading adds the correctly formatted id to label's htmlFor", () => {
|
|
119
|
-
// Arrange
|
|
120
|
-
const id = "exampleid";
|
|
121
|
-
const testId = "testid";
|
|
122
|
-
|
|
123
|
-
// Act
|
|
124
|
-
render(
|
|
125
|
-
<FieldHeading
|
|
126
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
127
|
-
label="Label"
|
|
128
|
-
id={id}
|
|
129
|
-
testId={testId}
|
|
130
|
-
/>,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
// Assert
|
|
134
|
-
const label = screen.getByTestId(`${testId}-label`);
|
|
135
|
-
expect(label).toHaveAttribute("for", `${id}-field`);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("fieldheading adds the correctly formatted id to error's id", () => {
|
|
139
|
-
// Arrange
|
|
140
|
-
const id = "exampleid";
|
|
141
|
-
const testId = "testid";
|
|
142
|
-
|
|
143
|
-
// Act
|
|
144
|
-
render(
|
|
145
|
-
<FieldHeading
|
|
146
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
147
|
-
label="Label"
|
|
148
|
-
error="Error"
|
|
149
|
-
id={id}
|
|
150
|
-
testId={testId}
|
|
151
|
-
/>,
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// Assert
|
|
155
|
-
const error = screen.getByRole("alert");
|
|
156
|
-
expect(error).toHaveAttribute("id", `${id}-error`);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("stype prop applies to the fieldheading container", () => {
|
|
160
|
-
// Arrange
|
|
161
|
-
const styles = StyleSheet.create({
|
|
162
|
-
style1: {
|
|
163
|
-
flexGrow: 1,
|
|
164
|
-
background: "blue",
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Act
|
|
169
|
-
const {container} = render(
|
|
170
|
-
<FieldHeading
|
|
171
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
172
|
-
label="Label"
|
|
173
|
-
error="Error"
|
|
174
|
-
style={styles.style1}
|
|
175
|
-
/>,
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
// Assert
|
|
179
|
-
const fieldHeading = container.childNodes[0];
|
|
180
|
-
expect(fieldHeading).toHaveStyle("background: blue");
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("should render a LabelMedium when the 'label' prop is a I18nInlineMarkup", () => {
|
|
184
|
-
// Arrange
|
|
185
|
-
|
|
186
|
-
// Act
|
|
187
|
-
render(
|
|
188
|
-
<FieldHeading
|
|
189
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
190
|
-
label={
|
|
191
|
-
<I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
|
|
192
|
-
{"<b>Test</b> Hello, world!"}
|
|
193
|
-
</I18nInlineMarkup>
|
|
194
|
-
}
|
|
195
|
-
/>,
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
// Assert
|
|
199
|
-
const label = screen.getByText("Hello, world!");
|
|
200
|
-
// LabelMedium has a font-size of 16px
|
|
201
|
-
expect(label).toHaveStyle("font-size: 16px");
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("should render a LabelSmall when the 'description' prop is a I18nInlineMarkup", () => {
|
|
205
|
-
// Arrange
|
|
206
|
-
|
|
207
|
-
// Act
|
|
208
|
-
render(
|
|
209
|
-
<FieldHeading
|
|
210
|
-
field={<TextField id="tf-1" value="" onChange={() => {}} />}
|
|
211
|
-
label={<Body>Hello, world</Body>}
|
|
212
|
-
description={
|
|
213
|
-
<I18nInlineMarkup b={(s: string) => <b>{s}</b>}>
|
|
214
|
-
{"<b>Test</b> description"}
|
|
215
|
-
</I18nInlineMarkup>
|
|
216
|
-
}
|
|
217
|
-
/>,
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
// Assert
|
|
221
|
-
const description = screen.getByText("description");
|
|
222
|
-
// LabelSmall has a font-size of 16px
|
|
223
|
-
expect(description).toHaveStyle("font-size: 14px");
|
|
224
|
-
});
|
|
225
|
-
});
|