@@ -10,107 +10,125 @@ const initialValue = '';
10
10
const baseProps = {
11
11
value : { en : initialValue , de : initialValue } ,
12
12
id : 'rich-text-input' ,
13
+ 'data-testid' : 'rich-text-data-test' ,
13
14
onChange : ( ) => { } ,
14
15
} ;
15
16
16
17
describe ( 'LocalizedRichTextInput' , ( ) => {
17
18
it ( 'should have an HTML name' , ( ) => {
18
- const { getByLabelText } = render (
19
+ const { getByTestId } = render (
19
20
< LocalizedRichTextInput { ...baseProps } name = "foo" selectedLanguage = "en" />
20
21
) ;
21
- expect ( getByLabelText ( 'EN' ) ) . toHaveAttribute ( 'name' , 'foo.en' ) ;
22
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . toHaveAttribute (
23
+ 'name' ,
24
+ 'foo.en'
25
+ ) ;
22
26
} ) ;
23
27
describe ( 'when collapsed' , ( ) => {
24
28
it ( 'should render input the selected languages (en)' , ( ) => {
25
- const { getByLabelText , queryByLabelText } = render (
29
+ const { getByTestId , queryByLabelText } = render (
26
30
< LocalizedRichTextInput { ...baseProps } selectedLanguage = "en" />
27
31
) ;
28
- expect ( getByLabelText ( 'EN' ) ) . toBeInTheDocument ( ) ;
29
- expect ( queryByLabelText ( 'DE' ) ) . not . toBeInTheDocument ( ) ;
32
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . toBeInTheDocument ( ) ;
33
+ expect (
34
+ queryByLabelText ( 'rich-text-data-test-de' )
35
+ ) . not . toBeInTheDocument ( ) ;
30
36
} ) ;
31
37
} ) ;
32
38
33
39
describe ( 'when expanded' , ( ) => {
34
40
it ( 'should render inputs for all the languages (en, de)' , ( ) => {
35
- const { getByLabelText } = render (
41
+ const { getByTestId } = render (
36
42
< LocalizedRichTextInput
37
43
{ ...baseProps }
38
44
selectedLanguage = "en"
39
45
defaultExpandLanguages = { true }
40
46
/>
41
47
) ;
42
- expect ( getByLabelText ( 'EN ') ) . toBeInTheDocument ( ) ;
43
- expect ( getByLabelText ( 'DE ') ) . toBeInTheDocument ( ) ;
48
+ expect ( getByTestId ( 'rich-text-data-test-en ') ) . toBeInTheDocument ( ) ;
49
+ expect ( getByTestId ( 'rich-text-data-test-de ') ) . toBeInTheDocument ( ) ;
44
50
} ) ;
45
51
} ) ;
46
52
describe ( 'when expansion controls are hidden' , ( ) => {
47
53
it ( 'should render one input per language and no hide button' , ( ) => {
48
- const { getByLabelText , queryByLabelText } = render (
54
+ const { getByTestId , queryByLabelText } = render (
49
55
< LocalizedRichTextInput
50
56
{ ...baseProps }
51
57
selectedLanguage = "en"
52
58
hideLanguageExpansionControls = { true }
53
59
/>
54
60
) ;
55
- expect ( getByLabelText ( 'EN ') ) . toBeInTheDocument ( ) ;
56
- expect ( getByLabelText ( 'DE ') ) . toBeInTheDocument ( ) ;
61
+ expect ( getByTestId ( 'rich-text-data-test-en ') ) . toBeInTheDocument ( ) ;
62
+ expect ( getByTestId ( 'rich-text-data-test-de ') ) . toBeInTheDocument ( ) ;
57
63
expect ( queryByLabelText ( / h i d e l a n g u a g e s / i) ) . not . toBeInTheDocument ( ) ;
58
64
} ) ;
59
65
} ) ;
60
66
61
67
describe ( 'when disabled' , ( ) => {
62
68
describe ( 'when expanded' , ( ) => {
63
69
it ( 'should render a disabled input for each language (en, de)' , ( ) => {
64
- const { getByLabelText } = render (
70
+ const { getByLabelText, getByTestId } = render (
65
71
< LocalizedRichTextInput
66
72
{ ...baseProps }
67
73
selectedLanguage = "en"
68
74
isDisabled = { true }
69
75
/>
70
76
) ;
71
77
getByLabelText ( / s h o w a l l l a n g u a g e s / i) . click ( ) ;
72
- expect ( getByLabelText ( 'EN' ) ) . toHaveAttribute ( 'disabled' ) ;
73
- expect ( getByLabelText ( 'DE' ) ) . toHaveAttribute ( 'disabled' ) ;
78
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . toHaveAttribute (
79
+ 'disabled'
80
+ ) ;
81
+ expect ( getByTestId ( 'rich-text-data-test-de' ) ) . toHaveAttribute (
82
+ 'disabled'
83
+ ) ;
74
84
} ) ;
75
85
} ) ;
76
86
describe ( 'when not expanded' , ( ) => {
77
87
it ( 'should render a disabled input' , ( ) => {
78
- const { getByLabelText } = render (
88
+ const { getByTestId } = render (
79
89
< LocalizedRichTextInput
80
90
{ ...baseProps }
81
91
selectedLanguage = "en"
82
92
isDisabled = { true }
83
93
/>
84
94
) ;
85
- expect ( getByLabelText ( 'EN' ) ) . toHaveAttribute ( 'disabled' ) ;
95
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . toHaveAttribute (
96
+ 'disabled'
97
+ ) ;
86
98
} ) ;
87
99
} ) ;
88
100
} ) ;
89
101
describe ( 'when readonly' , ( ) => {
90
102
describe ( 'when expanded' , ( ) => {
91
103
it ( 'should render a readonly input for each language (en, de)' , ( ) => {
92
- const { getByLabelText } = render (
104
+ const { getByLabelText, getByTestId } = render (
93
105
< LocalizedRichTextInput
94
106
{ ...baseProps }
95
107
selectedLanguage = "en"
96
108
isReadOnly = { true }
97
109
/>
98
110
) ;
99
111
getByLabelText ( / s h o w a l l l a n g u a g e s / i) . click ( ) ;
100
- expect ( getByLabelText ( 'EN' ) ) . not . toHaveAttribute ( 'contenteditable' ) ;
101
- expect ( getByLabelText ( 'DE' ) ) . not . toHaveAttribute ( 'contenteditable' ) ;
112
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . not . toHaveAttribute (
113
+ 'contenteditable'
114
+ ) ;
115
+ expect ( getByTestId ( 'rich-text-data-test-de' ) ) . not . toHaveAttribute (
116
+ 'contenteditable'
117
+ ) ;
102
118
} ) ;
103
119
} ) ;
104
120
describe ( 'when not expanded' , ( ) => {
105
121
it ( 'should render a disabled input' , ( ) => {
106
- const { getByLabelText } = render (
122
+ const { getByTestId } = render (
107
123
< LocalizedRichTextInput
108
124
{ ...baseProps }
109
125
selectedLanguage = "en"
110
126
isReadOnly = { true }
111
127
/>
112
128
) ;
113
- expect ( getByLabelText ( 'EN' ) ) . not . toHaveAttribute ( 'contenteditable' ) ;
129
+ expect ( getByTestId ( 'rich-text-data-test-en' ) ) . not . toHaveAttribute (
130
+ 'contenteditable'
131
+ ) ;
114
132
} ) ;
115
133
} ) ;
116
134
} ) ;
@@ -120,15 +138,15 @@ describe('LocalizedRichTextInput', () => {
120
138
de : 'Another error' ,
121
139
} ;
122
140
it ( 'should be open all fields and render errors' , ( ) => {
123
- const { getByLabelText , getByText } = render (
141
+ const { getByText , getByTestId } = render (
124
142
< LocalizedRichTextInput
125
143
{ ...baseProps }
126
144
selectedLanguage = "en"
127
145
errors = { errors }
128
146
/>
129
147
) ;
130
- expect ( getByLabelText ( 'EN ') ) . toBeInTheDocument ( ) ;
131
- expect ( getByLabelText ( 'DE ') ) . toBeInTheDocument ( ) ;
148
+ expect ( getByTestId ( 'rich-text-data-test-en ') ) . toBeInTheDocument ( ) ;
149
+ expect ( getByTestId ( 'rich-text-data-test-de ') ) . toBeInTheDocument ( ) ;
132
150
expect ( getByText ( errors . en ) ) . toBeInTheDocument ( ) ;
133
151
expect ( getByText ( errors . de ) ) . toBeInTheDocument ( ) ;
134
152
} ) ;
@@ -139,15 +157,15 @@ describe('LocalizedRichTextInput', () => {
139
157
de : 'An error' ,
140
158
} ;
141
159
it ( 'should be open all fields and render errors' , ( ) => {
142
- const { getByLabelText , getByText } = render (
160
+ const { getByText , getByTestId } = render (
143
161
< LocalizedRichTextInput
144
162
{ ...baseProps }
145
163
selectedLanguage = "en"
146
164
errors = { errors }
147
165
/>
148
166
) ;
149
- expect ( getByLabelText ( 'EN ') ) . toBeInTheDocument ( ) ;
150
- expect ( getByLabelText ( 'DE ') ) . toBeInTheDocument ( ) ;
167
+ expect ( getByTestId ( 'rich-text-data-test-en ') ) . toBeInTheDocument ( ) ;
168
+ expect ( getByTestId ( 'rich-text-data-test-de ') ) . toBeInTheDocument ( ) ;
151
169
expect ( getByText ( errors . de ) ) . toBeInTheDocument ( ) ;
152
170
} ) ;
153
171
} ) ;
@@ -156,16 +174,18 @@ describe('LocalizedRichTextInput', () => {
156
174
const errors = {
157
175
en : 'A value required' ,
158
176
} ;
159
- const { getByLabelText , getByText , queryByLabelText } = render (
177
+ const { getByText , getByTestId , queryByLabelText } = render (
160
178
< LocalizedRichTextInput
161
179
{ ...baseProps }
162
180
selectedLanguage = "en"
163
181
errors = { errors }
164
182
/>
165
183
) ;
166
- expect ( getByLabelText ( 'EN ') ) . toBeInTheDocument ( ) ;
184
+ expect ( getByTestId ( 'rich-text-data-test-en ') ) . toBeInTheDocument ( ) ;
167
185
expect ( getByText ( errors . en ) ) . toBeInTheDocument ( ) ;
168
- expect ( queryByLabelText ( 'DE' ) ) . not . toBeInTheDocument ( ) ;
186
+ expect (
187
+ queryByLabelText ( 'rich-text-data-test-de' )
188
+ ) . not . toBeInTheDocument ( ) ;
169
189
} ) ;
170
190
} ) ;
171
191
} ) ;
0 commit comments