Skip to content

Commit fc6f6ac

Browse files
fix: Fix password field story test - correct toggle button aria-label expectations
The test was expecting 'Hide password' initially, but the component correctly starts with 'Show password' when the password is hidden. Updated the test to use proper DOM traversal to find the correct toggle button for each password field, avoiding conflicts with multiple password fields in the form.
1 parent b21950e commit fc6f6ac

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

apps/docs/src/remix-hook-form/password-field.stories.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,31 @@ const testDefaultValues = ({ canvas }: StoryContext) => {
123123

124124
const testPasswordVisibilityToggle = async ({ canvas }: StoryContext) => {
125125
const passwordInput = canvas.getByLabelText('Password');
126-
const toggleButton = canvas.getByLabelText('Show password');
126+
127+
// Find the toggle button within the same form item as the password input
128+
const formItem =
129+
passwordInput.closest('[class*="FormItem"], .form-item, [data-testid="form-item"]') ||
130+
passwordInput.parentElement?.parentElement;
131+
const toggleButton = formItem?.querySelector('button[aria-label="Show password"]') as HTMLElement;
127132

128133
// Initially password should be hidden (type="password")
129134
expect(passwordInput).toHaveAttribute('type', 'password');
130135

131136
// Click toggle to show password
132137
await userEvent.click(toggleButton);
133138
expect(passwordInput).toHaveAttribute('type', 'text');
134-
expect(canvas.getByLabelText('Hide password')).toBeInTheDocument();
139+
140+
// Find the hide button for the same field
141+
const hideButton = formItem?.querySelector('button[aria-label="Hide password"]') as HTMLElement;
142+
expect(hideButton).toBeInTheDocument();
135143

136144
// Click toggle to hide password again
137-
await userEvent.click(canvas.getByLabelText('Hide password'));
145+
await userEvent.click(hideButton);
138146
expect(passwordInput).toHaveAttribute('type', 'password');
139-
expect(canvas.getByLabelText('Show password')).toBeInTheDocument();
147+
148+
// Verify show button is back
149+
const showButtonAgain = formItem?.querySelector('button[aria-label="Show password"]') as HTMLElement;
150+
expect(showButtonAgain).toBeInTheDocument();
140151
};
141152

142153
const testWeakPasswordValidation = async ({ canvas }: StoryContext) => {

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"name": "forms",
33
"version": "0.2.0",
44
"private": true,
5-
"workspaces": [
6-
"apps/*",
7-
"packages/*"
8-
],
5+
"workspaces": ["apps/*", "packages/*"],
96
"scripts": {
107
"start": "yarn dev",
118
"dev": "turbo run dev",

packages/components/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"import": "./dist/ui/index.js"
1919
}
2020
},
21-
"files": [
22-
"dist"
23-
],
21+
"files": ["dist"],
2422
"scripts": {
2523
"prepublishOnly": "yarn run build",
2624
"build": "vite build",

0 commit comments

Comments
 (0)