Skip to content

Commit 6a30e72

Browse files
Merge pull request #3496 from SalesforceCommerceCloud/W-20276592.giridhari.gupta.issue.3486.test
@W 20276592 - Added unit test cases
2 parents 7bff5db + e54c4ec commit 6a30e72

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

packages/template-retail-react-app/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## v8.3.0-dev (Nov 05, 2025)
2-
- [Bugfix] Fix Forgot Password link not working from Account Profile password update form [#3487](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3487)
2+
- [Bugfix] Fix Forgot Password link not working from Account Profile password update form [#3493](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3493)
33

44
## v8.2.0 (Nov 04, 2025)
55
- Add support for Rule Based Promotions for Choice of Bonus Products. We are currently supporting only one product level rule based promotion per product [#3418](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3418)

packages/template-retail-react-app/app/components/forms/update-password-fields.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,32 @@ describe('UpdatePasswordFields component', () => {
5858
expect(screen.getByText('Passwords do not match.')).toBeInTheDocument()
5959
expect(onSubmit).not.toHaveBeenCalled()
6060
})
61+
62+
test('does not render "Forgot Password?" button when handleForgotPasswordClick is not provided', () => {
63+
renderWithProviders(<WrapperComponent />)
64+
65+
expect(screen.queryByText(/forgot password/i)).not.toBeInTheDocument()
66+
})
67+
68+
test('renders "Forgot Password?" button when handleForgotPasswordClick is provided', () => {
69+
const handleForgotPasswordClick = jest.fn()
70+
renderWithProviders(
71+
<WrapperComponent handleForgotPasswordClick={handleForgotPasswordClick} />
72+
)
73+
74+
const forgotPasswordButton = screen.getByText(/forgot password/i)
75+
expect(forgotPasswordButton).toBeInTheDocument()
76+
})
77+
78+
test('calls handleForgotPasswordClick when "Forgot Password?" button is clicked', async () => {
79+
const handleForgotPasswordClick = jest.fn()
80+
const {user} = renderWithProviders(
81+
<WrapperComponent handleForgotPasswordClick={handleForgotPasswordClick} />
82+
)
83+
84+
const forgotPasswordButton = screen.getByText(/forgot password/i)
85+
await user.click(forgotPasswordButton)
86+
87+
expect(handleForgotPasswordClick).toHaveBeenCalledTimes(1)
88+
})
6189
})

packages/template-retail-react-app/app/pages/account/index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,26 @@ describe('updating password', function () {
257257

258258
expect(await screen.findByTestId('password-update-error')).toBeInTheDocument()
259259
})
260+
261+
test('navigates to reset-password page when "Forgot Password?" is clicked', async () => {
262+
useCustomerType.mockReturnValue({isRegistered: true, isExternal: false})
263+
const {user} = renderWithProviders(<MockedComponent />, {
264+
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
265+
})
266+
267+
expect(await screen.findByTestId('account-page')).toBeInTheDocument()
268+
expect(await screen.findByTestId('account-detail-page')).toBeInTheDocument()
269+
270+
const el = within(screen.getByTestId('sf-toggle-card-password'))
271+
await user.click(el.getByText(/edit/i))
272+
273+
const forgotPasswordButton = el.getByText(/forgot password/i)
274+
expect(forgotPasswordButton).toBeInTheDocument()
275+
276+
await user.click(forgotPasswordButton)
277+
278+
await waitFor(() => {
279+
expect(window.location.pathname).toBe(`${expectedBasePath}/reset-password`)
280+
})
281+
})
260282
})

packages/template-retail-react-app/app/pages/account/profile.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,47 @@ test('Non ECOM user cannot see the password card', async () => {
115115

116116
expect(screen.queryByText(/Password/i)).not.toBeInTheDocument()
117117
})
118+
119+
describe('AccountDetail component', () => {
120+
test('passes handleForgotPasswordClick prop to PasswordCard when provided', async () => {
121+
sdk.useCustomerType.mockReturnValue({isRegistered: true, isExternal: false})
122+
const handleForgotPasswordClick = jest.fn()
123+
124+
const {user} = renderWithProviders(
125+
<AccountDetail handleForgotPasswordClick={handleForgotPasswordClick} />,
126+
{
127+
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
128+
}
129+
)
130+
131+
await waitFor(() => {
132+
expect(screen.getByText(/Account Details/i)).toBeInTheDocument()
133+
})
134+
135+
const passwordCard = screen.getByTestId('sf-toggle-card-password')
136+
await user.click(within(passwordCard).getByText(/edit/i))
137+
138+
const forgotPasswordButton = screen.getByText(/forgot password/i)
139+
expect(forgotPasswordButton).toBeInTheDocument()
140+
141+
await user.click(forgotPasswordButton)
142+
expect(handleForgotPasswordClick).toHaveBeenCalledTimes(1)
143+
})
144+
145+
test('does not show "Forgot Password?" button when handleForgotPasswordClick is not provided', async () => {
146+
sdk.useCustomerType.mockReturnValue({isRegistered: true, isExternal: false})
147+
148+
const {user} = renderWithProviders(<AccountDetail />, {
149+
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
150+
})
151+
152+
await waitFor(() => {
153+
expect(screen.getByText(/Account Details/i)).toBeInTheDocument()
154+
})
155+
156+
const passwordCard = screen.getByTestId('sf-toggle-card-password')
157+
await user.click(within(passwordCard).getByText(/edit/i))
158+
159+
expect(screen.queryByText(/forgot password/i)).not.toBeInTheDocument()
160+
})
161+
})

0 commit comments

Comments
 (0)