From fe34acf314e9efdf4cd1a411f247d4c085ceced7 Mon Sep 17 00:00:00 2001 From: Dmytro <98233552+DmytroAlipov@users.noreply.github.com> Date: Mon, 20 Feb 2023 10:36:04 +0200 Subject: [PATCH] feat: display or sign in with (#749) --- src/login/LoginPage.jsx | 12 +-- src/login/tests/LoginPage.test.jsx | 156 +++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 6 deletions(-) diff --git a/src/login/LoginPage.jsx b/src/login/LoginPage.jsx index 46205007..605da2c0 100644 --- a/src/login/LoginPage.jsx +++ b/src/login/LoginPage.jsx @@ -170,12 +170,12 @@ class LoginPage extends React.Component { return ( <> - {((!isEnterpriseLoginDisabled && isSocialAuthActive) || (isEnterpriseLoginDisabled && isInstitutionAuthActive)) - && ( -
- {intl.formatMessage(messages['login.other.options.heading'])} -
- )} + {(isSocialAuthActive || (isEnterpriseLoginDisabled && isInstitutionAuthActive)) + && ( +
+ {intl.formatMessage(messages['login.other.options.heading'])} +
+ )} {(!isEnterpriseLoginDisabled && isSocialAuthActive) && ( diff --git a/src/login/tests/LoginPage.test.jsx b/src/login/tests/LoginPage.test.jsx index 45556a20..4c984013 100644 --- a/src/login/tests/LoginPage.test.jsx +++ b/src/login/tests/LoginPage.test.jsx @@ -236,6 +236,162 @@ describe('LoginPage', () => { expect(loginPage.text().includes('Or sign in with:')).toBe(false); }); + it('should show sign-in header providers (ENABLE ENTERPRISE LOGIN)', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + providers: [{ + ...ssoProvider, + }], + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(true); + expect(loginPage.text().includes('Company or school credentials')).toBe(true); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(false); + }); + + it('should show sign-in header with providers (DISABLE ENTERPRISE LOGIN)', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: true, + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + providers: [{ + ...ssoProvider, + }], + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(true); + expect(loginPage.text().includes('Company or school credentials')).toBe(false); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(false); + + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + }); + + it('should not show sign-in header without Providers and secondary Providers (ENABLE ENTERPRISE LOGIN)', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(false); + expect(loginPage.text().includes('Company or school credentials')).toBe(false); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(false); + }); + + it('should not show sign-in header without Providers and secondary Providers (DISABLE ENTERPRISE LOGIN)', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: true, + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(false); + expect(loginPage.text().includes('Company or school credentials')).toBe(false); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(false); + + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + }); + + it('should show sign-in header with secondary Providers and without Providers', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: true, + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + secondaryProviders: [{ + ...secondaryProviders, + }], + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(true); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(true); + + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + }); + + it('should show sign-in header with Providers and secondary Providers', () => { + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: true, + }); + + store = mockStore({ + ...initialState, + commonComponents: { + ...initialState.commonComponents, + thirdPartyAuthContext: { + ...initialState.commonComponents.thirdPartyAuthContext, + providers: [{ + ...ssoProvider, + }], + secondaryProviders: [{ + ...secondaryProviders, + }], + }, + }, + }); + + const loginPage = mount(reduxWrapper()); + expect(loginPage.text().includes('Or sign in with:')).toBe(true); + expect(loginPage.text().includes('Company or school credentials')).toBe(false); + expect(loginPage.text().includes('Institution/campus credentials')).toBe(true); + + mergeConfig({ + DISABLE_ENTERPRISE_LOGIN: '', + }); + }); + // ******** test alert messages ******** it('should match login error message', () => {