-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Save button in password change form (#5256)
* fix Save button in password change form * fix type * change header placement * expect onSubmit to be called with data --------- Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
- Loading branch information
Showing
3 changed files
with
131 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
The "Save" button in Change Password form now submits the form data to Saleor. |
59 changes: 59 additions & 0 deletions
59
src/staff/components/StaffPasswordResetDialog/StaffPasswordResetDialog.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import StaffPasswordResetDialog, { | ||
StaffPasswordResetDialogProps, | ||
} from "./StaffPasswordResetDialog"; | ||
|
||
const defaultProps = { | ||
confirmButtonState: "default", | ||
errors: [], | ||
open: true, | ||
onClose: jest.fn(), | ||
onSubmit: jest.fn(), | ||
} as StaffPasswordResetDialogProps; | ||
|
||
jest.mock("react-intl", () => ({ | ||
useIntl: jest.fn(() => ({ | ||
formatMessage: jest.fn(x => x.defaultMessage), | ||
})), | ||
defineMessages: jest.fn(x => x), | ||
FormattedMessage: ({ defaultMessage }: { defaultMessage: any }) => <>{defaultMessage}</>, | ||
})); | ||
|
||
describe("StaffPasswordResetDialog", () => { | ||
it("renders the form", () => { | ||
// Arrange & Act | ||
render(<StaffPasswordResetDialog {...defaultProps} />); | ||
|
||
// Assert | ||
expect(screen.getByRole("form")).toBeInTheDocument(); | ||
}); | ||
|
||
it("executes onSubmit when submit button is clicked", () => { | ||
// Arrange | ||
const { getByTestId } = render(<StaffPasswordResetDialog {...defaultProps} />); | ||
|
||
const submitButton = screen.getByTestId("submit"); | ||
const oldPasswordInput = getByTestId("old-password-input").querySelector("input"); | ||
const newPasswordInput = getByTestId("new-password-input").querySelector("input"); | ||
|
||
// Act | ||
fireEvent.change(oldPasswordInput!, { | ||
target: { value: "old-password" }, | ||
}); | ||
fireEvent.change(newPasswordInput!, { | ||
target: { value: "new-password" }, | ||
}); | ||
fireEvent.click(submitButton); | ||
|
||
// Assert | ||
expect(defaultProps.onSubmit).toHaveBeenCalledTimes(1); | ||
expect(defaultProps.onSubmit).toHaveBeenCalledWith({ | ||
oldPassword: "old-password", | ||
newPassword: "new-password", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters