@@ -150,30 +150,18 @@ describe('PasswordControl', () => {
150
150
151
151
it ( 'toggles input field type when show password button is clicked' , async ( ) => {
152
152
render ( PasswordControl , {
153
- props : {
154
- name : 'password' ,
155
- label : 'Password' ,
156
- placeholder : 'Password' ,
157
- } ,
153
+ global : { components } ,
154
+ props : { name : 'password' , label : 'Password' } ,
158
155
} ) ;
159
-
160
- const input = screen . getByPlaceholderText ( 'Password' ) ;
156
+ const input = screen . getByLabelText ( 'Password' ) ;
161
157
const showPasswordButton = screen . getByRole ( 'switch' ) ;
162
158
163
- // Initial state: password is hidden (type=password)
164
- expect ( input . getAttribute ( 'type' ) ) . toBe ( 'password' ) ;
165
- expect ( showPasswordButton . getAttribute ( 'aria-checked' ) ) . toBe ( 'false' ) ;
159
+ expect ( input ) . toHaveAttribute ( 'type' , 'password' ) ;
166
160
167
- // Click the button to show password (should change to type=text)
168
161
await fireEvent . click ( showPasswordButton ) ;
162
+ expect ( input ) . toHaveAttribute ( 'type' , 'text' ) ;
169
163
170
- // After clicking, the password should be visible
171
- expect ( input . getAttribute ( 'type' ) ) . toBe ( 'text' ) ;
172
- expect ( showPasswordButton . getAttribute ( 'aria-checked' ) ) . toBe ( 'true' ) ;
173
-
174
- // Click again to hide password (should change back to type=password)
175
164
await fireEvent . click ( showPasswordButton ) ;
176
- expect ( input . getAttribute ( 'type' ) ) . toBe ( 'password' ) ;
177
- expect ( showPasswordButton . getAttribute ( 'aria-checked' ) ) . toBe ( 'false' ) ;
165
+ expect ( input ) . toHaveAttribute ( 'type' , 'password' ) ;
178
166
} ) ;
179
167
} ) ;
0 commit comments