@navikt/ds-react 0.17.17 → 0.17.20
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/cjs/form/search/Search.js +11 -17
- package/cjs/form/search/SearchButton.js +1 -1
- package/esm/form/search/Search.d.ts +4 -4
- package/esm/form/search/Search.js +13 -19
- package/esm/form/search/Search.js.map +1 -1
- package/esm/form/search/SearchButton.js +1 -1
- package/esm/form/search/SearchButton.js.map +1 -1
- package/package.json +13 -13
- package/src/accordion/accordion.stories.tsx +82 -70
- package/src/alert/alert.stories.tsx +85 -95
- package/src/button/button.stories.tsx +142 -130
- package/src/card/stories/card.stories.mdx +1 -1
- package/src/card/stories/card.stories.tsx +1 -1
- package/src/form/checkbox/Checkbox.test.tsx +12 -8
- package/src/form/radio/Radio.test.tsx +7 -4
- package/src/form/search/Search.tsx +22 -24
- package/src/form/search/SearchButton.tsx +1 -1
- package/src/form/search/search-themes.stories.tsx +52 -0
- package/src/form/search/search.stories.tsx +10 -3
- package/src/page-header/stories/header.stories.mdx +1 -1
- package/src/page-header/stories/header.stories.tsx +1 -1
- package/src/step-indicator/stories/step-indicator.stories.mdx +1 -1
- package/src/step-indicator/stories/step-indicator.stories.tsx +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Alert } from ".";
|
|
3
|
-
import { BodyLong, Heading } from "..";
|
|
3
|
+
import { BodyLong, Heading as DsHeading } from "..";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: "ds-react/
|
|
6
|
+
title: "ds-react/Alert",
|
|
7
7
|
component: Alert,
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -14,111 +14,101 @@ const variants: Array<"error" | "warning" | "info" | "success"> = [
|
|
|
14
14
|
"success",
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const Default = (props) => (
|
|
18
|
+
<Alert
|
|
19
|
+
variant={props.variant}
|
|
20
|
+
size={props.size}
|
|
21
|
+
fullWidth={props.fullWidth}
|
|
22
|
+
inline={props.inline}
|
|
23
|
+
>
|
|
24
|
+
{props.children}
|
|
25
|
+
</Alert>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
Default.args = {
|
|
29
|
+
variant: "info",
|
|
30
|
+
children: "Id elit esse enim reprehenderit enim nisi veniam nostrud.",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Small = () => {
|
|
18
34
|
return (
|
|
19
|
-
|
|
20
|
-
<h1>Alert</h1>
|
|
35
|
+
<div className="colgap">
|
|
21
36
|
{variants.map((variant, i) => (
|
|
22
|
-
<Alert key={variant} variant={variant}>
|
|
37
|
+
<Alert key={variant} variant={variant} size="small">
|
|
23
38
|
{new Array(i + 1).fill(
|
|
24
39
|
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
|
25
40
|
)}
|
|
26
41
|
</Alert>
|
|
27
42
|
))}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</Alert>
|
|
36
|
-
))}
|
|
37
|
-
</div>
|
|
38
|
-
<h2>Alert fullWidth</h2>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const FullWidth = () => {
|
|
48
|
+
return (
|
|
49
|
+
<div className="colgap">
|
|
39
50
|
{variants.map((variant, i) => (
|
|
40
|
-
<Alert
|
|
51
|
+
<Alert key={variant} variant={variant} fullWidth>
|
|
41
52
|
{new Array(i + 1).fill(
|
|
42
53
|
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
|
43
54
|
)}
|
|
44
55
|
</Alert>
|
|
45
56
|
))}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
<Alert key={variant} variant={variant} size="small">
|
|
103
|
-
<Heading spacing size="small" level="3">
|
|
104
|
-
Aliquip duis est in commodo pariatur
|
|
105
|
-
</Heading>
|
|
106
|
-
<BodyLong spacing>
|
|
107
|
-
Ullamco ullamco laborum et commodo sint culpa cupidatat culpa qui
|
|
108
|
-
laboris ex. Labore ex occaecat proident qui qui fugiat magna.
|
|
109
|
-
Fugiat sint commodo consequat eu aute.
|
|
110
|
-
</BodyLong>
|
|
111
|
-
<Heading level="4" size="xsmall" spacing>
|
|
112
|
-
Ullamco eiusmod Lorem eiusmod eu.
|
|
113
|
-
</Heading>
|
|
114
|
-
<BodyLong>
|
|
115
|
-
Ullamco ullamco laborum et commodo sint culpa cupidatat culpa qui
|
|
116
|
-
laboris ex. Labore ex occaecat proident qui qui fugiat magna.
|
|
117
|
-
Fugiat sint commodo consequat eu aute.
|
|
118
|
-
</BodyLong>
|
|
119
|
-
</Alert>
|
|
120
|
-
))}
|
|
121
|
-
</div>
|
|
122
|
-
</>
|
|
57
|
+
{variants.map((variant, i) => (
|
|
58
|
+
<Alert key={variant} variant={variant} fullWidth size="small">
|
|
59
|
+
{new Array(i + 1).fill(
|
|
60
|
+
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
|
61
|
+
)}
|
|
62
|
+
</Alert>
|
|
63
|
+
))}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const Inline = () => {
|
|
69
|
+
return (
|
|
70
|
+
<div className="colgap">
|
|
71
|
+
{variants.map((variant, i) => (
|
|
72
|
+
<Alert key={variant} variant={variant} inline>
|
|
73
|
+
{new Array(i + 1).fill(
|
|
74
|
+
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
|
75
|
+
)}
|
|
76
|
+
</Alert>
|
|
77
|
+
))}
|
|
78
|
+
{variants.map((variant, i) => (
|
|
79
|
+
<Alert key={variant} variant={variant} inline size="small">
|
|
80
|
+
{new Array(i + 1).fill(
|
|
81
|
+
"Id elit esse enim reprehenderit enim nisi veniam nostrud."
|
|
82
|
+
)}
|
|
83
|
+
</Alert>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const Heading = () => {
|
|
90
|
+
return (
|
|
91
|
+
<div className="colgap">
|
|
92
|
+
<Alert variant="info">
|
|
93
|
+
<DsHeading spacing size="small" level="3">
|
|
94
|
+
Aliquip duis est in commodo pariatur
|
|
95
|
+
</DsHeading>
|
|
96
|
+
<BodyLong>
|
|
97
|
+
Ullamco ullamco laborum et commodo sint culpa cupidatat culpa qui
|
|
98
|
+
laboris ex. Labore ex occaecat proident qui qui fugiat magna. Fugiat
|
|
99
|
+
sint commodo consequat eu aute.
|
|
100
|
+
</BodyLong>
|
|
101
|
+
</Alert>
|
|
102
|
+
<Alert variant="info" size="small">
|
|
103
|
+
<DsHeading spacing size="xsmall" level="3">
|
|
104
|
+
Aliquip duis est in commodo pariatur
|
|
105
|
+
</DsHeading>
|
|
106
|
+
<BodyLong>
|
|
107
|
+
Ullamco ullamco laborum et commodo sint culpa cupidatat culpa qui
|
|
108
|
+
laboris ex. Labore ex occaecat proident qui qui fugiat magna. Fugiat
|
|
109
|
+
sint commodo consequat eu aute.
|
|
110
|
+
</BodyLong>
|
|
111
|
+
</Alert>
|
|
112
|
+
</div>
|
|
123
113
|
);
|
|
124
114
|
};
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Star } from "@navikt/ds-icons";
|
|
2
|
+
import React from "react";
|
|
2
3
|
import { Button } from "./index";
|
|
3
|
-
import { Success } from "@navikt/ds-icons";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: "ds-react/
|
|
6
|
+
title: "ds-react/Button",
|
|
7
7
|
component: Button,
|
|
8
8
|
parameters: {
|
|
9
9
|
chromatic: { delay: 300 },
|
|
10
10
|
},
|
|
11
|
+
argTypes: {
|
|
12
|
+
variant: {
|
|
13
|
+
control: {
|
|
14
|
+
type: "radio",
|
|
15
|
+
options: ["primary", "secondary", "tertiary", "danger"],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
control: {
|
|
20
|
+
type: "radio",
|
|
21
|
+
options: ["medium", "small"],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
11
25
|
};
|
|
12
26
|
|
|
13
|
-
const Section = ({ children }) => (
|
|
14
|
-
<div
|
|
15
|
-
style={{
|
|
16
|
-
display: "flex",
|
|
17
|
-
gap: 16,
|
|
18
|
-
gridAutoFlow: "column",
|
|
19
|
-
justifyContent: "start",
|
|
20
|
-
padding: 24,
|
|
21
|
-
paddingLeft: 0,
|
|
22
|
-
}}
|
|
23
|
-
>
|
|
24
|
-
{children}
|
|
25
|
-
</div>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
27
|
const variants: Array<"primary" | "secondary" | "tertiary" | "danger"> = [
|
|
29
28
|
"primary",
|
|
30
29
|
"secondary",
|
|
@@ -39,119 +38,132 @@ const varSwitch = {
|
|
|
39
38
|
danger: "Danger",
|
|
40
39
|
};
|
|
41
40
|
|
|
42
|
-
export const
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
export const Default = (props) => {
|
|
42
|
+
return (
|
|
43
|
+
<Button variant={props.variant} size={props.size} loading={props.loading}>
|
|
44
|
+
{props.icon ? <Star /> : null}
|
|
45
|
+
{props.children}
|
|
46
|
+
{props.icon ? <Star /> : null}
|
|
47
|
+
</Button>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
Default.args = {
|
|
52
|
+
icon: false,
|
|
53
|
+
loading: false,
|
|
54
|
+
children: "Knapp",
|
|
55
|
+
};
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
{
|
|
55
|
-
<Button key={variant} variant={variant}>
|
|
56
|
-
{varSwitch[variant]}
|
|
57
|
-
</Button>
|
|
58
|
-
))}
|
|
59
|
-
</Section>
|
|
60
|
-
<h2>disabled</h2>
|
|
61
|
-
<Section>
|
|
62
|
-
{variants.map((variant) => (
|
|
63
|
-
<Button key={variant} variant={variant} disabled>
|
|
64
|
-
{varSwitch[variant]}
|
|
65
|
-
</Button>
|
|
66
|
-
))}
|
|
67
|
-
</Section>
|
|
68
|
-
<h2>As link</h2>
|
|
69
|
-
<Section>
|
|
70
|
-
{variants.map((variant) => (
|
|
71
|
-
<Button as="a" key={variant} variant={variant} href="the-link">
|
|
72
|
-
{varSwitch[variant]}
|
|
73
|
-
</Button>
|
|
74
|
-
))}
|
|
75
|
-
</Section>
|
|
76
|
-
<h2>Small</h2>
|
|
77
|
-
<Section>
|
|
78
|
-
{variants.map((variant) => (
|
|
79
|
-
<Button key={variant} variant={variant} size="small">
|
|
80
|
-
{varSwitch[variant]}
|
|
81
|
-
</Button>
|
|
82
|
-
))}
|
|
83
|
-
</Section>
|
|
84
|
-
<h2>Xsmall</h2>
|
|
85
|
-
<Section>
|
|
86
|
-
{variants.map((variant) => (
|
|
87
|
-
<Button key={variant} variant={variant} size="xsmall">
|
|
88
|
-
{varSwitch[variant]}
|
|
89
|
-
</Button>
|
|
90
|
-
))}
|
|
91
|
-
</Section>
|
|
92
|
-
<h2>Button w/icon</h2>
|
|
93
|
-
<Section>
|
|
94
|
-
{variants.map((variant) => (
|
|
95
|
-
<Button key={variant} variant={variant}>
|
|
96
|
-
{variant} <Success />
|
|
97
|
-
</Button>
|
|
98
|
-
))}
|
|
99
|
-
</Section>
|
|
100
|
-
<Section>
|
|
101
|
-
{variants.map((variant) => (
|
|
102
|
-
<Button key={variant} variant={variant}>
|
|
103
|
-
<span className="navds-sr-only">Success ikon</span>
|
|
104
|
-
<Success />
|
|
105
|
-
</Button>
|
|
106
|
-
))}
|
|
107
|
-
</Section>
|
|
108
|
-
<h2>Small w/icon</h2>
|
|
109
|
-
<Section>
|
|
110
|
-
{variants.map((variant) => (
|
|
111
|
-
<Button key={variant} variant={variant} size="small">
|
|
112
|
-
<Success /> {variant}
|
|
113
|
-
</Button>
|
|
114
|
-
))}
|
|
115
|
-
</Section>
|
|
116
|
-
<Section>
|
|
117
|
-
{variants.map((variant) => (
|
|
118
|
-
<Button key={variant} variant={variant} size="small">
|
|
119
|
-
<span className="navds-sr-only">Success ikon</span>
|
|
120
|
-
<Success />
|
|
121
|
-
</Button>
|
|
122
|
-
))}
|
|
123
|
-
</Section>
|
|
124
|
-
<h2>Button w/loader</h2>
|
|
125
|
-
<Button onClick={toggleLoading}>Toggle loaders</Button>
|
|
126
|
-
<Button onClick={() => setContent((content) => `${content} wat`)}>
|
|
127
|
-
Change content
|
|
57
|
+
export const Small = () => (
|
|
58
|
+
<div className="rowgap">
|
|
59
|
+
{variants.map((variant) => (
|
|
60
|
+
<Button key={variant} variant={variant} size="small">
|
|
61
|
+
{varSwitch[variant]}
|
|
128
62
|
</Button>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{varSwitch[variant]}
|
|
152
|
-
</Button>
|
|
153
|
-
))}
|
|
154
|
-
</Section>
|
|
63
|
+
))}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export const XSmall = () => (
|
|
68
|
+
<div className="rowgap">
|
|
69
|
+
{variants.map((variant) => (
|
|
70
|
+
<Button key={variant} variant={variant} size="xsmall">
|
|
71
|
+
{varSwitch[variant]}
|
|
72
|
+
</Button>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export const Loading = () => (
|
|
78
|
+
<div className="colgap">
|
|
79
|
+
<div className="rowgap">
|
|
80
|
+
{variants.map((variant) => (
|
|
81
|
+
<Button key={variant} variant={variant} loading>
|
|
82
|
+
{varSwitch[variant]}
|
|
83
|
+
</Button>
|
|
84
|
+
))}
|
|
155
85
|
</div>
|
|
156
|
-
|
|
157
|
-
|
|
86
|
+
<div className="rowgap">
|
|
87
|
+
{variants.map((variant) => (
|
|
88
|
+
<Button key={variant} variant={variant} loading size="small">
|
|
89
|
+
{varSwitch[variant]}
|
|
90
|
+
</Button>
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
<div className="rowgap">
|
|
94
|
+
{variants.map((variant) => (
|
|
95
|
+
<Button key={variant} variant={variant} loading size="xsmall">
|
|
96
|
+
{varSwitch[variant]}
|
|
97
|
+
</Button>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
export const Icon = () => (
|
|
104
|
+
<div className="colgap">
|
|
105
|
+
<div className="rowgap">
|
|
106
|
+
{variants.map((variant) => (
|
|
107
|
+
<Button key={variant} variant={variant}>
|
|
108
|
+
<Star />
|
|
109
|
+
</Button>
|
|
110
|
+
))}
|
|
111
|
+
</div>
|
|
112
|
+
<div className="rowgap">
|
|
113
|
+
{variants.map((variant) => (
|
|
114
|
+
<Button key={variant} variant={variant} size="small">
|
|
115
|
+
<Star />
|
|
116
|
+
</Button>
|
|
117
|
+
))}
|
|
118
|
+
</div>
|
|
119
|
+
<div className="rowgap">
|
|
120
|
+
{variants.map((variant) => (
|
|
121
|
+
<Button key={variant} variant={variant} size="xsmall">
|
|
122
|
+
<Star />
|
|
123
|
+
</Button>
|
|
124
|
+
))}
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
export const IconWText = () => (
|
|
130
|
+
<div className="colgap">
|
|
131
|
+
<div className="rowgap">
|
|
132
|
+
{variants.map((variant) => (
|
|
133
|
+
<Button key={variant} variant={variant}>
|
|
134
|
+
<Star />
|
|
135
|
+
{varSwitch[variant]}
|
|
136
|
+
<Star />
|
|
137
|
+
</Button>
|
|
138
|
+
))}
|
|
139
|
+
</div>
|
|
140
|
+
<div className="rowgap">
|
|
141
|
+
{variants.map((variant) => (
|
|
142
|
+
<Button key={variant} variant={variant} size="small">
|
|
143
|
+
<Star />
|
|
144
|
+
{varSwitch[variant]}
|
|
145
|
+
<Star />
|
|
146
|
+
</Button>
|
|
147
|
+
))}
|
|
148
|
+
</div>
|
|
149
|
+
<div className="rowgap">
|
|
150
|
+
{variants.map((variant) => (
|
|
151
|
+
<Button key={variant} variant={variant} size="xsmall">
|
|
152
|
+
<Star />
|
|
153
|
+
{varSwitch[variant]}
|
|
154
|
+
<Star />
|
|
155
|
+
</Button>
|
|
156
|
+
))}
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
export const Link = () => (
|
|
162
|
+
<div className="rowgap">
|
|
163
|
+
{variants.map((variant) => (
|
|
164
|
+
<Button key={variant} variant={variant} as="a" href="#thecakeisalie">
|
|
165
|
+
{varSwitch[variant]}
|
|
166
|
+
</Button>
|
|
167
|
+
))}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
@@ -6,11 +6,12 @@ import { Checkbox, CheckboxGroup } from ".";
|
|
|
6
6
|
|
|
7
7
|
const firstArgumentOfFirstCall = (fn: jest.Mock) => fn.mock.calls[0][0];
|
|
8
8
|
|
|
9
|
-
test("checkbox group chains onChange calls", () => {
|
|
9
|
+
test("checkbox group chains onChange calls", async () => {
|
|
10
10
|
const onGroupChange = jest.fn();
|
|
11
11
|
const onChange = jest.fn();
|
|
12
12
|
const value = faker.datatype.string();
|
|
13
13
|
const label = faker.datatype.string();
|
|
14
|
+
const user = userEvent.setup();
|
|
14
15
|
|
|
15
16
|
render(
|
|
16
17
|
<CheckboxGroup legend="legend" onChange={onGroupChange}>
|
|
@@ -20,7 +21,7 @@ test("checkbox group chains onChange calls", () => {
|
|
|
20
21
|
</CheckboxGroup>
|
|
21
22
|
);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
await user.click(screen.getByLabelText(label));
|
|
24
25
|
|
|
25
26
|
expect(onGroupChange).toBeCalledTimes(1);
|
|
26
27
|
expect(onGroupChange).toBeCalledWith([value]);
|
|
@@ -36,21 +37,24 @@ describe("Checkbox handles controlled-state correctly", () => {
|
|
|
36
37
|
</CheckboxGroup>
|
|
37
38
|
);
|
|
38
39
|
|
|
39
|
-
test("Checkbox is still checked after click when controlled", () => {
|
|
40
|
+
test("Checkbox is still checked after click when controlled", async () => {
|
|
41
|
+
const user = userEvent.setup();
|
|
40
42
|
render(<CheckboxComponent value={["value1", "value2"]} />);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
await user.click(screen.getByLabelText("label1"));
|
|
44
|
+
await user.click(screen.getByLabelText("label2"));
|
|
43
45
|
|
|
44
46
|
expect((screen.getByLabelText("label1") as HTMLInputElement).checked).toBe(
|
|
45
47
|
true
|
|
46
48
|
);
|
|
49
|
+
|
|
47
50
|
expect((screen.getByLabelText("label2") as HTMLInputElement).checked).toBe(
|
|
48
51
|
true
|
|
49
52
|
);
|
|
50
53
|
});
|
|
51
54
|
|
|
52
|
-
test("onChange called with expected values", () => {
|
|
55
|
+
test("onChange called with expected values", async () => {
|
|
53
56
|
const onGroupChange = jest.fn();
|
|
57
|
+
const user = userEvent.setup();
|
|
54
58
|
|
|
55
59
|
render(
|
|
56
60
|
<CheckboxComponent
|
|
@@ -59,11 +63,11 @@ describe("Checkbox handles controlled-state correctly", () => {
|
|
|
59
63
|
/>
|
|
60
64
|
);
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
await user.click(screen.getByLabelText("label1"));
|
|
63
67
|
|
|
64
68
|
expect(onGroupChange).lastCalledWith(["value2"]);
|
|
65
69
|
|
|
66
|
-
|
|
70
|
+
await user.click(screen.getByLabelText("label2"));
|
|
67
71
|
|
|
68
72
|
expect(onGroupChange).lastCalledWith(["value1"]);
|
|
69
73
|
});
|
|
@@ -31,7 +31,9 @@ describe("Controlled RadioGroup", () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe("Uncontrolled RadioGroup", () => {
|
|
34
|
-
test("handles state correctly", () => {
|
|
34
|
+
test("handles state correctly", async () => {
|
|
35
|
+
const user = userEvent.setup();
|
|
36
|
+
|
|
35
37
|
render(<Group />);
|
|
36
38
|
|
|
37
39
|
const input1 = screen.getByLabelText(label1) as HTMLInputElement;
|
|
@@ -40,13 +42,14 @@ describe("Uncontrolled RadioGroup", () => {
|
|
|
40
42
|
expect(input1.checked).toBe(false);
|
|
41
43
|
expect(input2.checked).toBe(false);
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
await user.click(screen.getByLabelText(label2));
|
|
44
46
|
|
|
45
47
|
expect(input1.checked).toBe(false);
|
|
46
48
|
expect(input2.checked).toBe(true);
|
|
47
49
|
});
|
|
48
50
|
|
|
49
|
-
test("handles defaultValue correctly", () => {
|
|
51
|
+
test("handles defaultValue correctly", async () => {
|
|
52
|
+
const user = userEvent.setup();
|
|
50
53
|
render(<Group defaultValue={value1} />);
|
|
51
54
|
|
|
52
55
|
const input1 = screen.getByLabelText(label1) as HTMLInputElement;
|
|
@@ -55,7 +58,7 @@ describe("Uncontrolled RadioGroup", () => {
|
|
|
55
58
|
expect(input1.checked).toBe(true);
|
|
56
59
|
expect(input2.checked).toBe(false);
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
await user.click(screen.getByLabelText(label2));
|
|
59
62
|
|
|
60
63
|
expect(input1.checked).toBe(false);
|
|
61
64
|
expect(input2.checked).toBe(true);
|