diff --git a/src/common-components/RedirectLogistration.jsx b/src/common-components/RedirectLogistration.jsx index 862845ca..32c9a3cf 100644 --- a/src/common-components/RedirectLogistration.jsx +++ b/src/common-components/RedirectLogistration.jsx @@ -4,7 +4,9 @@ import { getConfig } from '@edx/frontend-platform'; import PropTypes from 'prop-types'; import { Redirect } from 'react-router-dom'; -import { AUTHN_PROGRESSIVE_PROFILING, RECOMMENDATIONS } from '../data/constants'; +import { + AUTHN_PROGRESSIVE_PROFILING, DISCOVER_URL, RECOMMENDATIONS, REDIRECT, +} from '../data/constants'; import { setCookie } from '../data/utils'; const RedirectLogistration = (props) => { @@ -17,6 +19,7 @@ const RedirectLogistration = (props) => { redirectToRecommendationsPage, educationLevel, userId, + isRegistrationEmbedded, } = props; let finalRedirectUrl = ''; @@ -35,6 +38,11 @@ const RedirectLogistration = (props) => { if (redirectToProgressiveProfilingPage) { // TODO: Do we still need this cookie? setCookie('van-504-returning-user', true); + + if (isRegistrationEmbedded) { + window.parent.postMessage({ action: REDIRECT, redirectUrl: `${window.location.origin}${AUTHN_PROGRESSIVE_PROFILING}` }, DISCOVER_URL); + return null; + } const registrationResult = { redirectUrl: finalRedirectUrl, success }; return ( { redirectUrl={registrationResult.redirectUrl} finishAuthUrl={finishAuthUrl} optionalFields={optionalFields} + isRegistrationEmbedded={isRegistrationEmbedded} redirectToProgressiveProfilingPage={ getConfig().ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN && Object.keys(optionalFields).includes('fields') } diff --git a/src/register/tests/RegistrationPage.test.jsx b/src/register/tests/RegistrationPage.test.jsx index bce31429..3023a0fb 100644 --- a/src/register/tests/RegistrationPage.test.jsx +++ b/src/register/tests/RegistrationPage.test.jsx @@ -862,6 +862,41 @@ describe('RegistrationPage', () => { expect(registrationPage.find(`button#${ssoProvider.id}`).hasClass(`btn-tpa btn-${ssoProvider.id}`)).toEqual(true); }); + it('should call the postMessage API when embedded variant is rendered', () => { + getLocale.mockImplementation(() => ('en-us')); + mergeConfig({ + ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN: true, + }); + + window.parent.postMessage = jest.fn(); + + delete window.location; + window.location = { href: getConfig().BASE_URL.concat(AUTHN_PROGRESSIVE_PROFILING), search: '?variant=embedded' }; + + store = mockStore({ + ...initialState, + register: { + ...initialState.register, + registrationResult: { + success: true, + }, + }, + commonComponents: { + optionalFields: { + extended_profile: {}, + fields: { + level_of_education: { name: 'level_of_education', error_message: false }, + }, + }, + }, + }); + const progressiveProfilingPage = mount(reduxWrapper( + , + )); + progressiveProfilingPage.update(); + expect(window.parent.postMessage).toHaveBeenCalledTimes(2); + }); + it('should render icon if icon classes are missing in providers', () => { ssoProvider.iconClass = null; store = mockStore({