@@ -8,7 +8,11 @@ import {
8
8
propTests ,
9
9
} from '../../../../tests/playwright' ;
10
10
import { partialDisabledOptionsPropTest } from './_propTests/partialDisabledOptionsPropTest' ;
11
- import { RadioForTest } from './Radio.story' ;
11
+ import {
12
+ RadioForTest ,
13
+ RadioForFormLayoutTests ,
14
+ } from './Radio.story' ;
15
+ import type { RadioForFormLayoutTestsProps } from './Radio.story' ;
12
16
13
17
const options = [
14
18
{
@@ -30,119 +34,155 @@ const options = [
30
34
} ,
31
35
] ;
32
36
33
- test . describe ( 'CheckboxField' , ( ) => {
34
- test . describe ( 'visual' , ( ) => {
35
- [
36
- ...propTests . defaultComponentPropTest ,
37
- ...propTests . requiredPropTest ,
38
- ...propTests . labelPropTest ,
39
- ...propTests . isLabelVisiblePropTest ,
40
- ...propTests . renderAsRequiredPropTest ,
41
- ...propTests . layoutPropTest ,
42
- ...mixPropTests ( [
43
- propTests . validationStatePropTest ,
44
- propTests . validationTextPropTest ,
45
- propTests . disabledPropTest ,
46
- ] ) ,
47
- ...mixPropTests ( [
48
- propTests . validationStatePropTest ,
49
- propTests . helpTextPropTest ,
50
- ] ) ,
51
- ...mixPropTests ( [
52
- partialDisabledOptionsPropTest ,
53
- propTests . validationStatePropTest ,
54
- ] ) ,
55
- ] . forEach ( ( {
56
- name,
57
- onBeforeTest,
58
- onBeforeSnapshot,
59
- props,
60
- } ) => {
61
- test ( name , async ( {
62
- mount,
63
- page,
37
+ test . describe ( 'Radio' , ( ) => {
38
+ test . describe ( 'base' , ( ) => {
39
+ test . describe ( 'visual' , ( ) => {
40
+ [
41
+ ...propTests . defaultComponentPropTest ,
42
+ ...propTests . requiredPropTest ,
43
+ ...propTests . labelPropTest ,
44
+ ...propTests . isLabelVisiblePropTest ,
45
+ ...propTests . renderAsRequiredPropTest ,
46
+ ...propTests . layoutPropTest ,
47
+ ...mixPropTests ( [
48
+ propTests . validationStatePropTest ,
49
+ propTests . validationTextPropTest ,
50
+ propTests . disabledPropTest ,
51
+ ] ) ,
52
+ ...mixPropTests ( [
53
+ propTests . validationStatePropTest ,
54
+ propTests . helpTextPropTest ,
55
+ ] ) ,
56
+ ...mixPropTests ( [
57
+ partialDisabledOptionsPropTest ,
58
+ propTests . validationStatePropTest ,
59
+ ] ) ,
60
+ ] . forEach ( ( {
61
+ name,
62
+ onBeforeTest,
63
+ onBeforeSnapshot,
64
+ props,
64
65
} ) => {
65
- if ( onBeforeTest ) {
66
- await onBeforeTest ( page ) ;
67
- }
66
+ test ( name , async ( {
67
+ mount,
68
+ page,
69
+ } ) => {
70
+ if ( onBeforeTest ) {
71
+ await onBeforeTest ( page ) ;
72
+ }
73
+
74
+ const component = await mount (
75
+ < RadioForTest
76
+ { ...props }
77
+ /> ,
78
+ ) ;
79
+
80
+ if ( onBeforeSnapshot ) {
81
+ await onBeforeSnapshot ( page , component ) ;
82
+ }
83
+
84
+ const screenshot = await component . screenshot ( ) ;
85
+ expect ( screenshot ) . toMatchSnapshot ( ) ;
86
+ } ) ;
87
+ } ) ;
88
+ } ) ;
89
+
90
+ test . describe ( 'non-visual' , ( ) => {
91
+ test ( 'id' , async ( { mount } ) => {
92
+ const radioId = 'radioId' ;
93
+ const label = 'radioLabel' ;
68
94
69
95
const component = await mount (
70
96
< RadioForTest
71
- { ...props }
97
+ id = { radioId }
98
+ label = { label }
99
+ options = { options }
72
100
/> ,
73
101
) ;
74
102
75
- if ( onBeforeSnapshot ) {
76
- await onBeforeSnapshot ( page , component ) ;
77
- }
78
-
79
- const screenshot = await component . screenshot ( ) ;
80
- expect ( screenshot ) . toMatchSnapshot ( ) ;
103
+ await expect ( component ) . toHaveAttribute ( 'id' , radioId ) ;
104
+ await expect ( component . getByText ( label ) . first ( ) ) . toHaveAttribute ( 'id' , `${ radioId } __label` ) ;
105
+ await expect ( component . getByText ( label ) . last ( ) ) . toHaveAttribute ( 'id' , `${ radioId } __displayLabel` ) ;
106
+ await expect ( component . getByText ( options [ 0 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 0 ] . key } __labelText` ) ;
107
+ await expect ( component . getByText ( options [ 1 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 1 ] . key } __labelText` ) ;
108
+ await expect ( component . getByText ( options [ 2 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 2 ] . value } __labelText` ) ;
109
+ await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 0 ] . key } ]` ) ) . not . toBeEmpty ( ) ;
110
+ await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 1 ] . key } ]` ) ) . not . toBeEmpty ( ) ;
111
+ await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 2 ] . value } ]` ) ) . not . toBeEmpty ( ) ;
112
+ await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 0 ] . key } __label]` ) ) . not . toBeEmpty ( ) ;
113
+ await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 1 ] . key } __label]` ) ) . not . toBeEmpty ( ) ;
114
+ await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 2 ] . value } __label]` ) ) . not . toBeEmpty ( ) ;
81
115
} ) ;
82
116
} ) ;
83
- } ) ;
84
117
85
- test . describe ( 'non-visual' , ( ) => {
86
- test ( 'id' , async ( { mount } ) => {
87
- const radioId = 'radioId' ;
88
- const label = 'radioLabel' ;
89
-
90
- const component = await mount (
91
- < RadioForTest
92
- id = { radioId }
93
- label = { label }
94
- options = { options }
95
- /> ,
96
- ) ;
97
-
98
- await expect ( component ) . toHaveAttribute ( 'id' , radioId ) ;
99
- await expect ( component . getByText ( label ) . first ( ) ) . toHaveAttribute ( 'id' , `${ radioId } __label` ) ;
100
- await expect ( component . getByText ( label ) . last ( ) ) . toHaveAttribute ( 'id' , `${ radioId } __displayLabel` ) ;
101
- await expect ( component . getByText ( options [ 0 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 0 ] . key } __labelText` ) ;
102
- await expect ( component . getByText ( options [ 1 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 1 ] . key } __labelText` ) ;
103
- await expect ( component . getByText ( options [ 2 ] . label ) ) . toHaveAttribute ( 'id' , `${ radioId } __item__${ options [ 2 ] . value } __labelText` ) ;
104
- await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 0 ] . key } ]` ) ) . not . toBeEmpty ( ) ;
105
- await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 1 ] . key } ]` ) ) . not . toBeEmpty ( ) ;
106
- await expect ( component . locator ( `input[id=${ radioId } __item__${ options [ 2 ] . value } ]` ) ) . not . toBeEmpty ( ) ;
107
- await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 0 ] . key } __label]` ) ) . not . toBeEmpty ( ) ;
108
- await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 1 ] . key } __label]` ) ) . not . toBeEmpty ( ) ;
109
- await expect ( component . locator ( `label[id=${ radioId } __item__${ options [ 2 ] . value } __label]` ) ) . not . toBeEmpty ( ) ;
118
+ test . describe ( 'functionality' , ( ) => {
119
+ test ( 'calls synthetic event onChange()' , async ( { mount } ) => {
120
+ let changeCalled = false ;
121
+
122
+ const component = await mount (
123
+ < RadioForTest
124
+ onChange = { ( ) => {
125
+ changeCalled = true ;
126
+ } }
127
+ options = { options }
128
+ /> ,
129
+ ) ;
130
+
131
+ await component . getByText ( options [ 1 ] . label ) . click ( { force : true } ) ;
132
+ expect ( changeCalled ) . toBeTruthy ( ) ;
133
+ } ) ;
134
+ test ( 'check on space press when focused' , async ( { mount } ) => {
135
+ let changeCalled = false ;
136
+ const testId = 'testId' ;
137
+
138
+ const component = await mount (
139
+ < RadioForTest
140
+ id = { testId }
141
+ onChange = { ( ) => { changeCalled = true ; } }
142
+ options = { options }
143
+ /> ,
144
+ ) ;
145
+
146
+ const input = component . locator ( `input[id=${ testId } __item__${ options [ 1 ] . key } ]` ) ;
147
+ await input . focus ( ) ;
148
+ await input . press ( 'Space' ) ;
149
+ expect ( changeCalled ) . toBeTruthy ( ) ;
150
+ } ) ;
110
151
} ) ;
111
152
} ) ;
112
153
113
- test . describe ( 'functionality' , ( ) => {
114
- test ( 'calls synthetic event onChange()' , async ( { mount } ) => {
115
- let changeCalled = false ;
116
-
117
- const component = await mount (
118
- < RadioForTest
119
- onChange = { ( ) => {
120
- changeCalled = true ;
121
- } }
122
- options = { options }
123
- /> ,
124
- ) ;
125
-
126
- await component . getByText ( options [ 1 ] . label ) . click ( { force : true } ) ;
127
- expect ( changeCalled ) . toBeTruthy ( ) ;
128
- } ) ;
154
+ test . describe ( 'formLayout' , ( ) => {
155
+ test . describe ( 'visual' , ( ) => {
156
+ [
157
+ ...propTests . layoutPropTest ,
158
+ ] . forEach ( ( {
159
+ name,
160
+ onBeforeTest,
161
+ onBeforeSnapshot,
162
+ props,
163
+ } ) => {
164
+ test ( name , async ( {
165
+ mount,
166
+ page,
167
+ } ) => {
168
+ if ( onBeforeTest ) {
169
+ await onBeforeTest ( page ) ;
170
+ }
129
171
130
- test ( 'check on space press when focused' , async ( { mount } ) => {
131
- let changeCalled = false ;
132
- const testId = 'testId' ;
133
-
134
- const component = await mount (
135
- < RadioForTest
136
- id = { testId }
137
- onChange = { ( ) => { changeCalled = true ; } }
138
- options = { options }
139
- /> ,
140
- ) ;
141
-
142
- const input = component . locator ( `input[id=${ testId } __item__${ options [ 1 ] . key } ]` ) ;
143
- await input . focus ( ) ;
144
- await input . press ( 'Space' ) ;
145
- expect ( changeCalled ) . toBeTruthy ( ) ;
172
+ const component = await mount (
173
+ < RadioForFormLayoutTests
174
+ { ...props as unknown as RadioForFormLayoutTestsProps }
175
+ /> ,
176
+ ) ;
177
+
178
+ if ( onBeforeSnapshot ) {
179
+ await onBeforeSnapshot ( page , component ) ;
180
+ }
181
+
182
+ const screenshot = await component . screenshot ( ) ;
183
+ expect ( screenshot ) . toMatchSnapshot ( ) ;
184
+ } ) ;
185
+ } ) ;
146
186
} ) ;
147
187
} ) ;
148
188
} ) ;
0 commit comments