-
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.
ASUB-8201 Sign In with Apple (#2067)
* Sign In with Apple * fixing linting and tests * fixing test & linting * fixing linting errors * removing update from package.json * fixing linting errors * disable eslint warnings * fixing warnings * fixing sintax * removing keys * removing only * fixing linting errors
- Loading branch information
1 parent
3eb16fc
commit 2c99feb
Showing
21 changed files
with
438 additions
and
62 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
33 changes: 33 additions & 0 deletions
33
blocks/identity-block/components/social-sign-on/_children/AppleSignIn.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,33 @@ | ||
import React from "react"; | ||
import { Button, Icon, useIdentity } from "@wpmedia/arc-themes-components"; | ||
import { useFusionContext } from "fusion:context"; | ||
import getTranslatedPhrases from "fusion:intl"; | ||
|
||
import { SIGN_UP } from "../constants"; | ||
|
||
const AppleIcon = <Icon name="Apple" width={21} height={24} viewBox="0 0 24 24" />; | ||
|
||
function AppleSignIn({ socialSignOnIn, className }) { | ||
const { siteProperties } = useFusionContext(); | ||
const { locale } = siteProperties; | ||
const phrases = getTranslatedPhrases(locale); | ||
const { Identity } = useIdentity(); | ||
|
||
return ( | ||
<Button | ||
id="apple-btn" | ||
variant="secondary-reverse" | ||
onClick={() => Identity.initAppleSignOn()} | ||
iconLeft={AppleIcon} | ||
className={`${className}__Apple`} | ||
> | ||
{socialSignOnIn !== SIGN_UP ? ( | ||
<span>{phrases.t("identity-block.social-signOn-apple-login")}</span> | ||
) : ( | ||
<span>{phrases.t("identity-block.social-signOn-apple-signUp")}</span> | ||
)} | ||
</Button> | ||
); | ||
} | ||
|
||
export default AppleSignIn; |
40 changes: 40 additions & 0 deletions
40
blocks/identity-block/components/social-sign-on/_children/AppleSignIn.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,40 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { useFusionContext } from "fusion:context"; | ||
|
||
import AppleSignIn from "./AppleSignIn"; | ||
|
||
const SITE_PROPS_MOCK = { | ||
breakpoints: { | ||
small: 0, | ||
medium: 768, | ||
large: 992, | ||
}, | ||
websiteAdPath: "news", | ||
dfpId: 701, | ||
}; | ||
|
||
jest.mock("@wpmedia/arc-themes-components", () => ({ | ||
...jest.requireActual("@wpmedia/arc-themes-components"), | ||
Icon: () => <div data-testid="Apple-icon" />, | ||
})); | ||
|
||
describe("Identity Social Login Component", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
useFusionContext.mockReturnValue({ | ||
isAdmin: true, | ||
siteProperties: SITE_PROPS_MOCK, | ||
}); | ||
}); | ||
|
||
it("renders Apple button for signIn", () => { | ||
render(<AppleSignIn socialSignOnIn="Login" />); | ||
expect(screen.getByText("identity-block.social-signOn-apple-login")).not.toBeNull(); | ||
}); | ||
|
||
it("renders Apple button for signUp", () => { | ||
render(<AppleSignIn socialSignOnIn="SignUp" />); | ||
expect(screen.getByText("identity-block.social-signOn-apple-signUp")).not.toBeNull(); | ||
}); | ||
}); |
9 changes: 6 additions & 3 deletions
9
blocks/identity-block/components/social-sign-on/_children/FacebookSignIn.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
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,3 @@ | ||
/* eslint-disable */ | ||
export const LOGIN = "Login"; | ||
export const SIGN_UP = "SignUp" |
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
40 changes: 40 additions & 0 deletions
40
...identity-block/features/account-management/_children/EmailEditableFieldContainer.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,40 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen} from '@testing-library/react'; | ||
import EmailEditableFieldContainer from './EmailEditableFieldContainer'; | ||
|
||
const mockUpdateProfile = jest.fn(() => Promise.resolve()) | ||
const mockIdentity = { | ||
apiOrigin: "http://origin/", | ||
isLoggedIn: jest.fn(() => false), | ||
getConfig: jest.fn(() => ({})), | ||
updateUserProfile: mockUpdateProfile | ||
}; | ||
|
||
jest.mock("@wpmedia/arc-themes-components", () => ({ | ||
...jest.requireActual("@wpmedia/arc-themes-components"), | ||
useIdentity: jest.fn(() => ({ | ||
isInitialized: true, | ||
Identity: { | ||
...mockIdentity, | ||
}, | ||
})) | ||
})); | ||
|
||
describe('EmailEditableFieldContainer', () => { | ||
it('updates email and clears error on successful submission', async () => { | ||
const setEmail = jest.fn(); | ||
render( | ||
<EmailEditableFieldContainer | ||
blockClassName="test-class" | ||
email="[email protected]" | ||
setEmail={setEmail} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByText('identity-block.edit')); | ||
const inputElement = screen.getByLabelText('identity-block.email') | ||
fireEvent.input(inputElement, { target: { value: '[email protected]' } }); | ||
|
||
expect(inputElement.value).toBe('[email protected]'); | ||
}); | ||
}); |
2 changes: 0 additions & 2 deletions
2
...ntity-block/features/account-management/_children/PasswordEditableFieldContainer.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
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
Oops, something went wrong.