From 8c94daf305de46fe7ebe3b1c3c5235dc5e5cf3ef Mon Sep 17 00:00:00 2001 From: Attiya Ishaque Date: Thu, 5 Aug 2021 11:41:26 +0500 Subject: [PATCH] fix: Side banner didn't show. (#409) --- src/MainApp.jsx | 31 ++- src/common-components/Logistration.jsx | 51 ++--- .../tests/Logistration.test.jsx | 7 +- src/forgot-password/ForgotPasswordPage.jsx | 159 +++++++------- .../tests/ForgotPasswordPage.test.jsx | 13 +- src/reset-password/ResetPasswordPage.jsx | 103 ++++----- .../tests/ResetPasswordPage.test.jsx | 10 +- src/welcome/WelcomePage.jsx | 195 +++++++++--------- src/welcome/tests/WelcomePage.test.jsx | 10 +- 9 files changed, 310 insertions(+), 269 deletions(-) diff --git a/src/MainApp.jsx b/src/MainApp.jsx index 08157953..3c27975f 100755 --- a/src/MainApp.jsx +++ b/src/MainApp.jsx @@ -3,7 +3,6 @@ import { Redirect, Route, Switch } from 'react-router-dom'; import { AppProvider } from '@edx/frontend-platform/react'; -import BaseComponent from './base-component'; import { UnAuthOnlyRoute, registerIcons, NotFoundPage, Logistration, } from './common-components'; @@ -21,22 +20,20 @@ registerIcons(); const MainApp = () => ( - - - - - - } /> - - - - - - - - - - + + + + + } /> + + + + + + + + + ); diff --git a/src/common-components/Logistration.jsx b/src/common-components/Logistration.jsx index 7848dd7d..bb47abc7 100644 --- a/src/common-components/Logistration.jsx +++ b/src/common-components/Logistration.jsx @@ -16,6 +16,7 @@ import { LOGIN_PAGE, REGISTER_PAGE } from '../data/constants'; import { updatePathWithQueryParams, getTpaHint } from '../data/utils'; import { LoginPage } from '../login'; import { RegistrationPage } from '../register'; +import BaseComponent from '../base-component'; const Logistration = (props) => { const { intl, selectedPage } = props; @@ -51,32 +52,34 @@ const Logistration = (props) => { ); return ( -
- {institutionLogin - ? ( - - - - ) - : ( - <> - {!tpa && ( - - - - - )} - + +
+ {institutionLogin + ? ( + + + + ) + : ( + <> + {!tpa && ( + + + + + )} + + )} + { key && ( + )} - { key && ( - - )} -
- {selectedPage === LOGIN_PAGE - ? - : } +
+ {selectedPage === LOGIN_PAGE + ? + : } +
-
+
); }; diff --git a/src/common-components/tests/Logistration.test.jsx b/src/common-components/tests/Logistration.test.jsx index aa4a19e5..8ddeb563 100644 --- a/src/common-components/tests/Logistration.test.jsx +++ b/src/common-components/tests/Logistration.test.jsx @@ -8,11 +8,13 @@ import { getConfig, mergeConfig } from '@edx/frontend-platform'; import * as analytics from '@edx/frontend-platform/analytics'; import { configure, injectIntl, IntlProvider } from '@edx/frontend-platform/i18n'; +import * as auth from '@edx/frontend-platform/auth'; import Logistration from '../Logistration'; import { RenderInstitutionButton } from '../InstitutionLogistration'; import { COMPLETE_STATE, LOGIN_PAGE } from '../../data/constants'; jest.mock('@edx/frontend-platform/analytics'); +jest.mock('@edx/frontend-platform/auth'); analytics.sendPageEvent = jest.fn(); const mockStore = configureStore(); @@ -36,6 +38,9 @@ describe('Logistration', () => { ); + beforeEach(() => { + auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, username: 'edX' })); + }); it('should render registration page', () => { configure({ loggingService: { logError: jest.fn() }, @@ -163,7 +168,7 @@ describe('Logistration', () => { }); delete window.location; - window.location = { href: getConfig().BASE_URL }; + window.location = { hostname: getConfig().SITE_NAME, href: getConfig().BASE_URL }; const root = mount(reduxWrapper()); root.find(RenderInstitutionButton).simulate('click', { institutionLogin: true }); diff --git a/src/forgot-password/ForgotPasswordPage.jsx b/src/forgot-password/ForgotPasswordPage.jsx index 7fea862d..1e5caae7 100644 --- a/src/forgot-password/ForgotPasswordPage.jsx +++ b/src/forgot-password/ForgotPasswordPage.jsx @@ -27,6 +27,7 @@ import { FormGroup } from '../common-components'; import { DEFAULT_STATE, LOGIN_PAGE, VALID_EMAIL_REGEX } from '../data/constants'; import { updatePathWithQueryParams, windowScrollTo } from '../data/utils'; import ForgotPasswordAlert from './ForgotPasswordAlert'; +import BaseComponent from '../base-component'; const ForgotPasswordPage = (props) => { const { intl, status, submitState } = props; @@ -63,87 +64,89 @@ const ForgotPasswordPage = (props) => { ); return ( -
- setKey(k)}> - - - { key && ( - - )} -
- { - const validationMessage = getValidationMessage(values.email); + +
+ setKey(k)}> + + + { key && ( + + )} +
+ { + const validationMessage = getValidationMessage(values.email); - if (validationMessage !== '') { - windowScrollTo({ left: 0, top: 0, behavior: 'smooth' }); - return { email: validationMessage }; - } + if (validationMessage !== '') { + windowScrollTo({ left: 0, top: 0, behavior: 'smooth' }); + return { email: validationMessage }; + } - return {}; - }} - onSubmit={(values) => { props.forgotPassword(values.email); }} - > - {({ - errors, handleSubmit, setFieldValue, values, - }) => ( - <> - - {intl.formatMessage(messages['forgot.password.page.title'], - { siteName: getConfig().SITE_NAME })} - - -
- -

- {intl.formatMessage(messages['forgot.password.page.heading'])} -

-

- {intl.formatMessage(messages['forgot.password.page.instructions'])} -

- getValidationMessage(values.email)} - handleChange={e => setFieldValue('email', e.target.value)} - handleFocus={() => setValidationError('')} - helpText={[intl.formatMessage(messages['forgot.password.email.help.text'], { platformName })]} - /> - e.preventDefault()} - /> - { - e.preventDefault(); - window.open(supportUrl, '_blank'); - }} - >{intl.formatMessage(messages['need.help.sign.in.text'])} - -

{intl.formatMessage(messages['additional.help.text'])} - {getConfig().INFO_EMAIL} -

- - - )} -
+ return {}; + }} + onSubmit={(values) => { props.forgotPassword(values.email); }} + > + {({ + errors, handleSubmit, setFieldValue, values, + }) => ( + <> + + {intl.formatMessage(messages['forgot.password.page.title'], + { siteName: getConfig().SITE_NAME })} + + +
+ +

+ {intl.formatMessage(messages['forgot.password.page.heading'])} +

+

+ {intl.formatMessage(messages['forgot.password.page.instructions'])} +

+ getValidationMessage(values.email)} + handleChange={e => setFieldValue('email', e.target.value)} + handleFocus={() => setValidationError('')} + helpText={[intl.formatMessage(messages['forgot.password.email.help.text'], { platformName })]} + /> + e.preventDefault()} + /> + { + e.preventDefault(); + window.open(supportUrl, '_blank'); + }} + >{intl.formatMessage(messages['need.help.sign.in.text'])} + +

{intl.formatMessage(messages['additional.help.text'])} + {getConfig().INFO_EMAIL} +

+ + + )} + +
-
+ ); }; diff --git a/src/forgot-password/tests/ForgotPasswordPage.test.jsx b/src/forgot-password/tests/ForgotPasswordPage.test.jsx index 4a22abc6..06a66618 100644 --- a/src/forgot-password/tests/ForgotPasswordPage.test.jsx +++ b/src/forgot-password/tests/ForgotPasswordPage.test.jsx @@ -10,13 +10,15 @@ import { createMemoryHistory } from 'history'; import * as analytics from '@edx/frontend-platform/analytics'; import CookiePolicyBanner from '@edx/frontend-component-cookie-policy-banner'; import { mergeConfig } from '@edx/frontend-platform'; -import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n'; +import { IntlProvider, injectIntl, configure } from '@edx/frontend-platform/i18n'; +import * as auth from '@edx/frontend-platform/auth'; import ForgotPasswordPage from '../ForgotPasswordPage'; import { INTERNAL_SERVER_ERROR, LOGIN_PAGE } from '../../data/constants'; import { PASSWORD_RESET } from '../../reset-password/data/constants'; jest.mock('@edx/frontend-platform/analytics'); +jest.mock('@edx/frontend-platform/auth'); analytics.sendPageEvent = jest.fn(); @@ -49,6 +51,15 @@ describe('ForgotPasswordPage', () => { beforeEach(() => { store = mockStore(initialState); + auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, username: 'edX' })); + configure({ + loggingService: { logError: jest.fn() }, + config: { + ENVIRONMENT: 'production', + LANGUAGE_PREFERENCE_COOKIE_NAME: 'yum', + }, + messages: { 'es-419': {}, de: {}, 'en-us': {} }, + }); props = { forgotPassword: jest.fn(), status: null, diff --git a/src/reset-password/ResetPasswordPage.jsx b/src/reset-password/ResetPasswordPage.jsx index 530d7d7c..3291f7e0 100644 --- a/src/reset-password/ResetPasswordPage.jsx +++ b/src/reset-password/ResetPasswordPage.jsx @@ -29,6 +29,7 @@ import { FORM_SUBMISSION_ERROR, PASSWORD_RESET_ERROR, PASSWORD_VALIDATION_ERROR, TOKEN_STATE, } from './data/constants'; import { updatePathWithQueryParams, windowScrollTo } from '../data/utils'; +import BaseComponent from '../base-component'; const ResetPasswordPage = (props) => { const { intl } = props; @@ -133,58 +134,60 @@ const ResetPasswordPage = (props) => { return ; } else { return ( -
- - {intl.formatMessage(messages['reset.password.page.title'], - { siteName: getConfig().SITE_NAME })} - - - setKey(k)}> - - - { key && ( - - )} -
-
- -

{intl.formatMessage(messages['reset.password'])}

-

{intl.formatMessage(messages['reset.password.page.instructions'])}

-
- setNewPassword(e.target.value)} - handleBlur={(e) => validateInput(e.target.name, e.target.value)} - handleFocus={handleOnFocus} - errorMessage={formErrors.newPassword} - floatingLabel={intl.formatMessage(messages['new.password.label'])} - /> - - handleSubmit(e)} - onMouseDown={(e) => e.preventDefault()} - /> - + +
+ + {intl.formatMessage(messages['reset.password.page.title'], + { siteName: getConfig().SITE_NAME })} + + + setKey(k)}> + + + { key && ( + + )} +
+
+ +

{intl.formatMessage(messages['reset.password'])}

+

{intl.formatMessage(messages['reset.password.page.instructions'])}

+
+ setNewPassword(e.target.value)} + handleBlur={(e) => validateInput(e.target.name, e.target.value)} + handleFocus={handleOnFocus} + errorMessage={formErrors.newPassword} + floatingLabel={intl.formatMessage(messages['new.password.label'])} + /> + + handleSubmit(e)} + onMouseDown={(e) => e.preventDefault()} + /> + +
-
+ ); } return null; diff --git a/src/reset-password/tests/ResetPasswordPage.test.jsx b/src/reset-password/tests/ResetPasswordPage.test.jsx index 5f94c3ed..ce8ab709 100644 --- a/src/reset-password/tests/ResetPasswordPage.test.jsx +++ b/src/reset-password/tests/ResetPasswordPage.test.jsx @@ -9,7 +9,7 @@ import { createMemoryHistory } from 'history'; import * as auth from '@edx/frontend-platform/auth'; import CookiePolicyBanner from '@edx/frontend-component-cookie-policy-banner'; -import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n'; +import { IntlProvider, injectIntl, configure } from '@edx/frontend-platform/i18n'; import { resetPassword } from '../data/actions'; import { PASSWORD_RESET, TOKEN_STATE } from '../data/constants'; @@ -36,6 +36,14 @@ describe('ResetPasswordPage', () => { beforeEach(() => { store = mockStore(); + configure({ + loggingService: { logError: jest.fn() }, + config: { + ENVIRONMENT: 'production', + LANGUAGE_PREFERENCE_COOKIE_NAME: 'yum', + }, + messages: { 'es-419': {}, de: {}, 'en-us': {} }, + }); props = { resetPassword: jest.fn(), status: null, diff --git a/src/welcome/WelcomePage.jsx b/src/welcome/WelcomePage.jsx index 6f466aa8..21526e79 100644 --- a/src/welcome/WelcomePage.jsx +++ b/src/welcome/WelcomePage.jsx @@ -32,6 +32,7 @@ import { RedirectLogistration } from '../common-components'; import { DEFAULT_REDIRECT_URL, DEFAULT_STATE } from '../data/constants'; import { EDUCATION_LEVELS, GENDER_OPTIONS, YEAR_OF_BIRTH_OPTIONS } from '../register/data/constants'; import WelcomePageModal from './WelcomePageModal'; +import BaseComponent from '../base-component'; const WelcomePage = (props) => { const { intl, submitState, showError } = props; @@ -121,104 +122,106 @@ const WelcomePage = (props) => { return ( <> - - {intl.formatMessage(messages['progressive.profiling.page.title'], - { siteName: getConfig().SITE_NAME })} - - - - {props.shouldRedirect ? ( - - ) : null} -
-
-

{intl.formatMessage(messages['progressive.profiling.page.heading'])}

-
-
- {showError ? ( - - {intl.formatMessage(messages['welcome.page.error.heading'])} -

{intl.formatMessage(messages['welcome.page.error.message'])}

-
+ + + {intl.formatMessage(messages['progressive.profiling.page.title'], + { siteName: getConfig().SITE_NAME })} + + + + {props.shouldRedirect ? ( + ) : null} -
- - onChangeHandler(e)} - trailingElement={} - floatingLabel={intl.formatMessage(messages['education.levels.label'])} - > - {getOptions('levelOfEducation')} - - - - onChangeHandler(e)} - trailingElement={} - floatingLabel={intl.formatMessage(messages['year.of.birth.label'])} - > - - {getOptions('yearOfBirth')} - - - - onChangeHandler(e)} - trailingElement={} - floatingLabel={intl.formatMessage(messages['gender.options.label'])} - > - {getOptions('gender')} - - - - - {intl.formatMessage(messages['optional.fields.information.link'])} - - -
- e.preventDefault()} - /> - e.preventDefault()} - /> +
+
+

{intl.formatMessage(messages['progressive.profiling.page.heading'])}

- -
+
+ {showError ? ( + + {intl.formatMessage(messages['welcome.page.error.heading'])} +

{intl.formatMessage(messages['welcome.page.error.message'])}

+
+ ) : null} +
+ + onChangeHandler(e)} + trailingElement={} + floatingLabel={intl.formatMessage(messages['education.levels.label'])} + > + {getOptions('levelOfEducation')} + + + + onChangeHandler(e)} + trailingElement={} + floatingLabel={intl.formatMessage(messages['year.of.birth.label'])} + > + + {getOptions('yearOfBirth')} + + + + onChangeHandler(e)} + trailingElement={} + floatingLabel={intl.formatMessage(messages['gender.options.label'])} + > + {getOptions('gender')} + + + + + {intl.formatMessage(messages['optional.fields.information.link'])} + + +
+ e.preventDefault()} + /> + e.preventDefault()} + /> +
+
+
+
); }; diff --git a/src/welcome/tests/WelcomePage.test.jsx b/src/welcome/tests/WelcomePage.test.jsx index ec803649..d83bfdc2 100644 --- a/src/welcome/tests/WelcomePage.test.jsx +++ b/src/welcome/tests/WelcomePage.test.jsx @@ -8,7 +8,7 @@ import configureStore from 'redux-mock-store'; import { mergeConfig } from '@edx/frontend-platform'; import * as analytics from '@edx/frontend-platform/analytics'; import * as auth from '@edx/frontend-platform/auth'; -import { injectIntl, IntlProvider } from '@edx/frontend-platform/i18n'; +import { injectIntl, IntlProvider, configure } from '@edx/frontend-platform/i18n'; import { saveUserProfile } from '../data/actions'; import WelcomePage from '../WelcomePage'; @@ -50,6 +50,14 @@ describe('WelcomePageTests', () => { beforeEach(() => { store = mockStore({}); auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, username: 'edX' })); + configure({ + loggingService: { logError: jest.fn() }, + config: { + ENVIRONMENT: 'production', + LANGUAGE_PREFERENCE_COOKIE_NAME: 'yum', + }, + messages: { 'es-419': {}, de: {}, 'en-us': {} }, + }); }); it('should submit user profile details on form submission', async () => {