Skip to content

Commit

Permalink
fixing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraPinilla committed Jul 26, 2024
1 parent 00ee42e commit 7566236
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 23 deletions.
23 changes: 10 additions & 13 deletions .storybook/themes/news.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"min-width": 280px
),
"account-management-social-signon-identity": (
"display": "flex",
"display": flex,
"components": (
"icon": (
"margin-inline-end": var(--global-spacing-2)
Expand Down Expand Up @@ -305,19 +305,18 @@
)
),
"account-management-social-signon-identities-error": (
"font-family": "var(--font-family-primary)",
"margin-block-end": "var(--global-spacing-4)",
"font-family": var(--font-family-primary),
"margin-block-end": var(--global-spacing-4),
"components": (
"paragraph": (
"background-color": "var(--status-color-danger-subtle)",
"color": "var(--status-color-danger)",
"padding-block-end": "var(--global-spacing-1)",
"padding-block-start": "var(--global-spacing-1)",
"padding-inline-start": "var(--global-spacing-2)",
"padding-inline-end": "var(--global-spacing-2)"
"background-color": var(--status-color-danger-subtle),
"color": var(--status-color-danger),
"padding-block-end": var(--global-spacing-1),
"padding-block-start": var(--global-spacing-1),
"padding-inline-start": var(--global-spacing-2),
"padding-inline-end": var(--global-spacing-2)
)
)
"desktop": ()
),
"ads-block": (
"components": (
Expand Down Expand Up @@ -3644,7 +3643,6 @@
),
"social-sign-on-button-container-apple-custom": (
"inline-size": 100%
"desktop": ()
)
"social-sign-on-button-container-facebook": (
"justify-content": center,
Expand All @@ -3663,13 +3661,12 @@
"inline-size": 100%,
"components": (
"button-secondary-reverse-hover": (
color": "var(--text-color)
"color": var(--text-color)
),
"icon": (
"fill": #4285F4
)
)
"desktop": ()
),
"social-sign-on-button-container-google": (
"justify-content": center,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React from "react";

import { Button, Icon, usePhrases } from "@wpmedia/arc-themes-components";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React from "react";

import { Button, Icon, usePhrases } from "@wpmedia/arc-themes-components";

Expand Down
66 changes: 61 additions & 5 deletions blocks/identity-block/components/social-sign-on/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ describe("Identity Social Login Component", () => {
<SocialSignOn />
</GoogleSignInProvider>,
);
// don't render any facebook stuff, only show wrapper
const genericElements = screen.getAllByRole("generic");
expect(genericElements.length).toBe(1);
// don't render any button
expect(screen.queryByTestId('fb-login-button')).not.toBeInTheDocument();
expect(screen.queryByTestId('google-sign-in-button')).not.toBeInTheDocument();
expect(screen.queryByTestId('apple-btn')).not.toBeInTheDocument();
});

it("renders only Google button", () => {
it("renders only Google (default) button", () => {
useIdentity.mockImplementation(() => ({
isInitialized: true,
isLoggedIn: () => false,
Expand Down Expand Up @@ -69,7 +70,38 @@ describe("Identity Social Login Component", () => {
expect(screen.queryByTestId('fb-login-button')).not.toBeInTheDocument();
});

it("renders only Facebook button", () => {
it("renders only Google (custom) button", () => {
useIdentity.mockImplementation(() => ({
isInitialized: true,
isLoggedIn: () => false,
Identity: {
configOptions: {
googleClientId: true,
facebookAppId: false,
},
initFacebookLogin: () => {},
initializeFacebook: () => {},
},
}));
usePhrases.mockImplementation(() => ({
t: jest
.fn()
.mockReturnValue(
"Sign-in prompt was suppressed by the user or dismissed. Please try again later or use another sign-in method.",
),
}));

render(
<GoogleSignInProvider>
<SocialSignOn onError={() => null} redirectURL="#" customButtons={true} />
</GoogleSignInProvider>,
);

expect(screen.getByTestId('custom-google-signin-btn')).toBeInTheDocument();
expect(screen.queryByTestId('fb-login-button')).not.toBeInTheDocument();
});

it("renders only Facebook (default) button", () => {
useIdentity.mockImplementation(() => ({
isInitialized: true,
isLoggedIn: () => false,
Expand All @@ -93,6 +125,30 @@ describe("Identity Social Login Component", () => {
expect(screen.queryByTestId('google-sign-in-button')).not.toBeInTheDocument();
});

it("renders only Facebook (custom) button", () => {
useIdentity.mockImplementation(() => ({
isInitialized: true,
isLoggedIn: () => false,
Identity: {
configOptions: {
googleClientId: false,
facebookAppId: true,
},
initFacebookLogin: () => {},
initializeFacebook: () => {},
},
}));

render(
<GoogleSignInProvider>
<SocialSignOn onError={() => null} redirectURL="#" customButtons={true} />
</GoogleSignInProvider>,
);

expect(screen.getByTestId('facebook-btn')).toBeInTheDocument();
expect(screen.queryByTestId('google-sign-in-button')).not.toBeInTheDocument();
});

it("renders", () => {
useIdentity.mockImplementation(() => ({
isInitialized: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ function SocialSignOnEditableFieldContainer({
const connectText = phrases.t("identity-block.connect-identity");
const disconnectText = phrases.t("identity-block.disconnect-account");

const onConnectIdentity = useCallback((type) => {
const onConnectIdentity = useCallback(() => {
switch (type) {
case "Google":
window.google.accounts.id.prompt((notification) => {
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
// eslint-disable-next-line
alert(googleNotification);
document.cookie = "g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT";
window.google.accounts.id.prompt();
Expand All @@ -38,7 +39,7 @@ function SocialSignOnEditableFieldContainer({
default:
break;
}
}, [googleNotification, Identity]);
}, [googleNotification, Identity, type]);

return (
<div className={`${blockClassName}__social-signOn-edit`}>
Expand All @@ -62,7 +63,7 @@ function SocialSignOnEditableFieldContainer({
className={`${blockClassName}__social-signOn-button-connect`}
size="medium"
variant="primary"
onClick={() => onConnectIdentity(type)}
onClick={() => onConnectIdentity()}
>
{connectText}
</Button>
Expand Down

0 comments on commit 7566236

Please sign in to comment.