Skip to content

Commit

Permalink
feat: implement SHOW_REGISTRATION_LINKS setting
Browse files Browse the repository at this point in the history
  • Loading branch information
CefBoud committed Oct 12, 2023
1 parent cfb839d commit ccbd87d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 80 deletions.
5 changes: 3 additions & 2 deletions src/common-components/EnterpriseSSO.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import messages from './messages';
const EnterpriseSSO = (props) => {
const { formatMessage } = useIntl();
const tpaProvider = props.provider;
const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false;
const hideRegistrationLink = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false
|| getConfig().SHOW_REGISTRATION_LINKS === false;

const handleSubmit = (e, url) => {
e.preventDefault();
Expand Down Expand Up @@ -71,7 +72,7 @@ const EnterpriseSSO = (props) => {
className="w-100"
onClick={(e) => handleClick(e)}
>
{disablePublicAccountCreation
{hideRegistrationLink
? formatMessage(messages['enterprisetpa.login.button.text.public.account.creation.disabled'])
: formatMessage(messages['enterprisetpa.login.button.text'])}
</Button>
Expand Down
8 changes: 7 additions & 1 deletion src/common-components/Logistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Logistration = (props) => {
const [institutionLogin, setInstitutionLogin] = useState(false);
const [key, setKey] = useState('');
const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false;
const hideRegistrationLink = getConfig().SHOW_REGISTRATION_LINKS === false;

useEffect(() => {
const authService = getAuthService();
Expand Down Expand Up @@ -108,7 +109,7 @@ const Logistration = (props) => {
<Tab title={tabTitle} eventKey={selectedPage === LOGIN_PAGE ? LOGIN_PAGE : REGISTER_PAGE} />
</Tabs>
)
: (!isValidTpaHint() && (
: (!isValidTpaHint() && !hideRegistrationLink && (
<Tabs defaultActiveKey={selectedPage} id="controlled-tab" onSelect={handleOnSelect}>
<Tab title={formatMessage(messages['logistration.register'])} eventKey={REGISTER_PAGE} />
<Tab title={formatMessage(messages['logistration.sign.in'])} eventKey={LOGIN_PAGE} />
Expand All @@ -118,6 +119,11 @@ const Logistration = (props) => {
<Redirect to={updatePathWithQueryParams(key)} />
)}
<div id="main-content" className="main-content">
{!institutionLogin && !isValidTpaHint() && hideRegistrationLink && (
<h3 className="mb-4.5">
{formatMessage(messages[selectedPage === LOGIN_PAGE ? 'logistration.sign.in' : 'logistration.register'])}
</h3>
)}
{selectedPage === LOGIN_PAGE
? <LoginPage institutionLogin={institutionLogin} handleInstitutionLogin={handleInstitutionLogin} />
: (
Expand Down
153 changes: 76 additions & 77 deletions src/common-components/tests/Logistration.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ import React from 'react';
import { Provider } from 'react-redux';

import { getConfig, mergeConfig } from '@edx/frontend-platform';
import * as analytics from '@edx/frontend-platform/analytics';
import * as auth from '@edx/frontend-platform/auth';
import { sendPageEvent, sendTrackEvent } from '@edx/frontend-platform/analytics';
import { configure, injectIntl, IntlProvider } from '@edx/frontend-platform/i18n';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';
import configureStore from 'redux-mock-store';

import { COMPLETE_STATE, LOGIN_PAGE } from '../../data/constants';
import {
COMPLETE_STATE, LOGIN_PAGE, REGISTER_PAGE,
} from '../../data/constants';
import { backupRegistrationForm } from '../../register/data/actions';
import { clearThirdPartyAuthContextErrorMessage } from '../data/actions';
import { RenderInstitutionButton } from '../InstitutionLogistration';
import Logistration from '../Logistration';

jest.mock('@edx/frontend-platform/analytics');
jest.mock('@edx/frontend-platform/analytics', () => ({
sendPageEvent: jest.fn(),
sendTrackEvent: jest.fn(),
}));
jest.mock('@edx/frontend-platform/auth');
analytics.sendPageEvent = jest.fn();

const mockStore = configureStore();
const IntlLogistration = injectIntl(Logistration);
Expand All @@ -40,8 +43,47 @@ describe('Logistration', () => {
</IntlProvider>
);

const initialState = {
register: {
registrationFormData: {
configurableFormFields: {
marketingEmailsOptIn: true,
},
formFields: {
name: '', email: '', username: '', password: '',
},
emailSuggestion: {
suggestion: '', type: '',
},
errors: {
name: '', email: '', username: '', password: '',
},
},
registrationResult: { success: false, redirectUrl: '' },
registrationError: {},
usernameSuggestions: [],
validationApiRateLimited: false,
},
commonComponents: {
thirdPartyAuthContext: {
providers: [],
secondaryProviders: [],
},
},
login: {
loginResult: { success: false, redirectUrl: '' },
},
};

beforeEach(() => {
auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, username: 'test-user' }));
store = mockStore(initialState);
jest.mock('@edx/frontend-platform/auth', () => ({
getAuthenticatedUser: jest.fn(() => ({
userId: 3,
username: 'test-user',
})),
}));

configure({
loggingService: { logError: jest.fn() },
config: {
Expand All @@ -56,52 +98,48 @@ describe('Logistration', () => {
mergeConfig({
ALLOW_PUBLIC_ACCOUNT_CREATION: true,
});
store = mockStore({
register: {
registrationResult: { success: false, redirectUrl: '' },
registrationError: {},
},
commonComponents: {
thirdPartyAuthContext: {
providers: [],
secondaryProviders: [],
},
},
});

const logistration = mount(reduxWrapper(<IntlLogistration />));

expect(logistration.find('#main-content').find('RegistrationPage').exists()).toBeTruthy();
});

it('should render login page', () => {
store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
commonComponents: {
thirdPartyAuthContext: {
providers: [],
secondaryProviders: [],
},
},
});

const props = { selectedPage: LOGIN_PAGE };
const logistration = mount(reduxWrapper(<IntlLogistration {...props} />));

expect(logistration.find('#main-content').find('LoginPage').exists()).toBeTruthy();
});

it('should render login/register headings when show registration links is disabled', () => {
mergeConfig({
SHOW_REGISTRATION_LINKS: false,
});

let props = { selectedPage: LOGIN_PAGE };
let logistration = mount(reduxWrapper(<IntlLogistration {...props} />));

// verifying sign in heading
expect(logistration.find('#main-content').find('h3').text()).toEqual('Sign in');

// register page is still accessible when SHOW_REGISTRATION_LINKS is false
// but it needs to be accessed directly
props = { selectedPage: REGISTER_PAGE };
logistration = mount(reduxWrapper(<IntlLogistration {...props} />));

// verifying register heading
expect(logistration.find('#main-content').find('h3').text()).toEqual('Register');
});

it('should render only login page when public account creation is disabled', () => {
mergeConfig({
ALLOW_PUBLIC_ACCOUNT_CREATION: false,
DISABLE_ENTERPRISE_LOGIN: 'true',
SHOW_REGISTRATION_LINKS: 'true',
});

store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
...initialState,
commonComponents: {
thirdPartyAuthContext: {
currentProvider: null,
Expand Down Expand Up @@ -131,9 +169,7 @@ describe('Logistration', () => {
});

store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
...initialState,
commonComponents: {
thirdPartyAuthContext: {
currentProvider: null,
Expand Down Expand Up @@ -164,9 +200,7 @@ describe('Logistration', () => {
});

store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
...initialState,
commonComponents: {
thirdPartyAuthContext: {
currentProvider: null,
Expand All @@ -182,8 +216,8 @@ describe('Logistration', () => {
const logistration = mount(reduxWrapper(<IntlLogistration {...props} />));
logistration.find(RenderInstitutionButton).simulate('click', { institutionLogin: true });

expect(analytics.sendTrackEvent).toHaveBeenCalledWith('edx.bi.institution_login_form.toggled', { category: 'user-engagement' });
expect(analytics.sendPageEvent).toHaveBeenCalledWith('login_and_registration', 'institution_login');
expect(sendTrackEvent).toHaveBeenCalledWith('edx.bi.institution_login_form.toggled', { category: 'user-engagement' });
expect(sendPageEvent).toHaveBeenCalledWith('login_and_registration', 'institution_login');

mergeConfig({
DISABLE_ENTERPRISE_LOGIN: '',
Expand All @@ -196,10 +230,7 @@ describe('Logistration', () => {
});

store = mockStore({
register: {
registrationResult: { success: false, redirectUrl: '' },
registrationError: {},
},
...initialState,
commonComponents: {
thirdPartyAuthContext: {
currentProvider: null,
Expand All @@ -224,45 +255,13 @@ describe('Logistration', () => {
});

it('should fire action to backup registration form on tab click', () => {
store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
register: {
registrationResult: { success: false, redirectUrl: '' },
registrationError: {},
},
commonComponents: {
thirdPartyAuthContext: {
providers: [],
secondaryProviders: [],
},
},
});

store.dispatch = jest.fn(store.dispatch);
const logistration = mount(reduxWrapper(<IntlLogistration />));
logistration.find('a[data-rb-event-key="/login"]').simulate('click');
expect(store.dispatch).toHaveBeenCalledWith(backupRegistrationForm());
});

it('should clear tpa context errorMessage tab click', () => {
store = mockStore({
login: {
loginResult: { success: false, redirectUrl: '' },
},
register: {
registrationResult: { success: false, redirectUrl: '' },
registrationError: {},
},
commonComponents: {
thirdPartyAuthContext: {
providers: [],
secondaryProviders: [],
},
},
});

store.dispatch = jest.fn(store.dispatch);
const logistration = mount(reduxWrapper(<IntlLogistration />));
logistration.find('a[data-rb-event-key="/login"]').simulate('click');
Expand Down

0 comments on commit ccbd87d

Please sign in to comment.