-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'arc-themes-release-version-2.0.3' into THEMES-920
- Loading branch information
Showing
28 changed files
with
832 additions
and
50 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
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
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
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
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
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
blocks/identity-block/features/forgot-password/default.jsx
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,61 @@ | ||
import React, { useState } from "react"; | ||
import { useFusionContext } from "fusion:context"; | ||
import getProperties from "fusion:properties"; | ||
import getTranslatedPhrases from "fusion:intl"; | ||
import { Heading, Input, Paragraph } from "@wpmedia/arc-themes-components"; | ||
import HeadlinedSubmitForm from "../../components/headlined-submit-form"; | ||
import useIdentity from "../../components/identity"; | ||
|
||
const BLOCK_CLASS_NAME = "b-forgot-password"; | ||
|
||
const ForgotPassword = () => { | ||
const { arcSite } = useFusionContext(); | ||
const { locale } = getProperties(arcSite); | ||
const phrases = getTranslatedPhrases(locale); | ||
|
||
const { Identity, isInitialized } = useIdentity(); | ||
const [submitted, setSubmitted] = useState(false); | ||
const [error, setError] = useState(); | ||
|
||
if (submitted) { | ||
return ( | ||
<section className={BLOCK_CLASS_NAME}> | ||
<Heading>{phrases.t("identity-block.forgot-password-headline-submitted")}</Heading> | ||
<Paragraph>{phrases.t("identity-block.forgot-password-instruction-submitted")}</Paragraph> | ||
</section> | ||
); | ||
} | ||
|
||
return isInitialized ? ( | ||
<HeadlinedSubmitForm | ||
buttonLabel={phrases.t("identity-block.forgot-password-submit")} | ||
className={BLOCK_CLASS_NAME} | ||
formErrorText={error} | ||
headline={phrases.t("identity-block.forgot-password-headline")} | ||
onSubmit={({ email }) => | ||
Identity.requestResetPassword(email) | ||
.then(() => { | ||
setSubmitted(true); | ||
}) | ||
.catch(() => setError(phrases.t("identity-block.forgot-password-error"))) | ||
} | ||
> | ||
<Paragraph>{phrases.t("identity-block.forgot-password-instruction")}</Paragraph> | ||
<Input | ||
autoComplete="email" | ||
label={phrases.t("identity-block.email")} | ||
name="email" | ||
required | ||
showDefaultError={false} | ||
type="email" | ||
validationErrorMessage={phrases.t("identity-block.email-requirements")} | ||
/> | ||
</HeadlinedSubmitForm> | ||
) : null; | ||
}; | ||
|
||
ForgotPassword.label = "Identity Forgot Password - Arc Block"; | ||
|
||
ForgotPassword.icon = "user-question"; | ||
|
||
export default ForgotPassword; |
12 changes: 12 additions & 0 deletions
12
blocks/identity-block/features/forgot-password/default.story-ignore.jsx
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,12 @@ | ||
import React from "react"; | ||
|
||
import ForgotPassword from "./default"; | ||
|
||
export default { | ||
title: "Blocks/Identity/Blocks/Forgot Password", | ||
parameters: { | ||
chromatic: { viewports: [320, 1200] }, | ||
}, | ||
}; | ||
|
||
export const basic = () => <ForgotPassword />; |
93 changes: 93 additions & 0 deletions
93
blocks/identity-block/features/forgot-password/default.test.jsx
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,93 @@ | ||
import React from "react"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import ForgotPassword from "./default"; | ||
import useIdentity from "../../components/identity"; | ||
|
||
jest.mock("../../components/identity"); | ||
|
||
const resetMock = jest.fn(() => Promise.resolve()); | ||
const resetFailMock = jest.fn(() => Promise.reject()); | ||
|
||
jest.mock("fusion:properties", () => jest.fn(() => ({}))); | ||
|
||
describe("Identity Password Reset Feature", () => { | ||
beforeEach(() => { | ||
useIdentity.mockImplementation(() => ({ | ||
isInitialized: true, | ||
isLoggedIn: () => true, | ||
Identity: { | ||
isLoggedIn: jest.fn(() => false), | ||
getConfig: jest.fn(() => ({})), | ||
requestResetPassword: resetMock, | ||
}, | ||
})); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("renders nothing if identity not initialized", () => { | ||
useIdentity.mockImplementation(() => ({ | ||
isInitialized: false, | ||
isLoggedIn: () => true, | ||
Identity: { | ||
isLoggedIn: jest.fn(() => false), | ||
getConfig: jest.fn(() => ({})), | ||
}, | ||
})); | ||
render(<ForgotPassword />); | ||
expect(screen.queryByRole("form")).toBe(null); | ||
}); | ||
|
||
it("renders", () => { | ||
render(<ForgotPassword />); | ||
expect(screen.queryByRole("form")).not.toBe(null); | ||
}); | ||
|
||
it("shows submit form", () => { | ||
render(<ForgotPassword />); | ||
expect(screen.queryByRole("form")).not.toBe(null); | ||
expect(screen.getByText("identity-block.forgot-password-instruction")).not.toBe(null); | ||
expect(screen.getByLabelText("identity-block.email")).not.toBe(null); | ||
expect(screen.getByRole("button")).not.toBe(null); | ||
}); | ||
|
||
it("uses updates the form on submit", async () => { | ||
render(<ForgotPassword />); | ||
fireEvent.change(screen.getByLabelText("identity-block.email"), { | ||
target: { value: "[email protected]" }, | ||
}); | ||
await fireEvent.click(screen.getByRole("button")); | ||
expect(screen.getByText("identity-block.forgot-password-headline-submitted")).not.toBe(null); | ||
expect(screen.getByText("identity-block.forgot-password-instruction-submitted")).not.toBe(null); | ||
}); | ||
}); | ||
|
||
describe("Identity Password Reset Feature - Failing", () => { | ||
beforeEach(() => { | ||
useIdentity.mockImplementation(() => ({ | ||
isInitialized: true, | ||
isLoggedIn: () => true, | ||
Identity: { | ||
isLoggedIn: jest.fn(() => false), | ||
getConfig: jest.fn(() => ({})), | ||
requestResetPassword: resetFailMock, | ||
}, | ||
})); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("enter error state on failure to submit", async () => { | ||
render(<ForgotPassword />); | ||
fireEvent.change(screen.getByLabelText("identity-block.email"), { | ||
target: { value: "[email protected]" }, | ||
}); | ||
await fireEvent.click(screen.getByRole("button")); | ||
await expect(resetFailMock).toHaveBeenCalled(); | ||
expect(screen.getByText("identity-block.forgot-password-error")).not.toBe(null); | ||
}); | ||
}); |
Oops, something went wrong.