Skip to content

Commit

Permalink
fix: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed May 30, 2023
1 parent 099833a commit 126a9b4
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 173 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "fedx-scripts eslint --ext .js --ext .jsx .",
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
"test": "TZ=UTC fedx-scripts jest --passWithNoTests"
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests"
},
"bugs": {
"url": "https://github.com/openedx/frontend-app-account/issues"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import configureStore from 'redux-mock-store';
import {
fireEvent,
render,
screen,
} from '@testing-library/react';
import { createMemoryHistory } from 'history';

import * as auth from '@edx/frontend-platform/auth';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
Expand All @@ -28,8 +27,6 @@ jest.mock('react-redux', () => ({
jest.mock('@edx/frontend-platform/auth');
jest.mock('../../data/selectors', () => jest.fn().mockImplementation(() => ({ certPreferenceSelector: () => ({}) })));

const history = createMemoryHistory();

const IntlCertificatePreference = injectIntl(CertificatePreference);

const mockStore = configureStore();
Expand All @@ -42,7 +39,7 @@ describe('NameChange', () => {
const labelText = 'If checked, this name will appear on your certificates and public-facing records.';

const reduxWrapper = children => (
<Router history={history}>
<Router>
<IntlProvider locale="en">
<Provider store={store}>{children}</Provider>
</IntlProvider>
Expand Down
9 changes: 3 additions & 6 deletions src/account-settings/name-change/test/NameChange.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import configureStore from 'redux-mock-store';
import {
fireEvent,
render,
screen,
} from '@testing-library/react';
import { createMemoryHistory } from 'history';

import * as auth from '@edx/frontend-platform/auth';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
Expand All @@ -28,8 +27,6 @@ jest.mock('react-redux', () => ({
jest.mock('@edx/frontend-platform/auth');
jest.mock('../../data/selectors', () => jest.fn().mockImplementation(() => ({ nameChangeSelector: () => ({}) })));

const history = createMemoryHistory();

const IntlNameChange = injectIntl(NameChange);

const mockStore = configureStore();
Expand All @@ -39,7 +36,7 @@ describe('NameChange', () => {
let store = {};

const reduxWrapper = children => (
<Router history={history}>
<Router>
<IntlProvider locale="en">
<Provider store={store}>{children}</Provider>
</IntlProvider>
Expand Down Expand Up @@ -168,6 +165,6 @@ describe('NameChange', () => {
props.saveState = 'complete';

render(reduxWrapper(<IntlNameChange {...props} />));
expect(history.location.pathname).toEqual('/id-verification');
expect(window.location.pathname).toEqual('/id-verification');
});
});
52 changes: 39 additions & 13 deletions src/account-settings/test/__snapshots__/JumpNav.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#basic-information"
isActive={[Function]}
onClick={[Function]}
>
Account Information
Expand All @@ -23,8 +25,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#profile-information"
isActive={[Function]}
onClick={[Function]}
>
Profile Information
Expand All @@ -34,8 +38,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#social-media"
isActive={[Function]}
onClick={[Function]}
>
Social Media Links
Expand All @@ -45,8 +51,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#site-preferences"
isActive={[Function]}
onClick={[Function]}
>
Site Preferences
Expand All @@ -56,8 +64,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#linked-accounts"
isActive={[Function]}
onClick={[Function]}
>
Linked Accounts
Expand All @@ -67,8 +77,10 @@ exports[`JumpNav should not render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#delete-account"
isActive={[Function]}
onClick={[Function]}
>
Delete My Account
Expand All @@ -90,8 +102,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#basic-information"
isActive={[Function]}
onClick={[Function]}
>
Account Information
Expand All @@ -101,8 +115,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#profile-information"
isActive={[Function]}
onClick={[Function]}
>
Profile Information
Expand All @@ -112,8 +128,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#demographics-information"
isActive={[Function]}
onClick={[Function]}
>
Optional Information
Expand All @@ -123,8 +141,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#social-media"
isActive={[Function]}
onClick={[Function]}
>
Social Media Links
Expand All @@ -134,8 +154,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#site-preferences"
isActive={[Function]}
onClick={[Function]}
>
Site Preferences
Expand All @@ -145,8 +167,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#linked-accounts"
isActive={[Function]}
onClick={[Function]}
>
Linked Accounts
Expand All @@ -156,8 +180,10 @@ exports[`JumpNav should render Optional Information link 1`] = `
className=""
>
<a
aria-current={null}
aria-current="page"
className="active"
href="/#delete-account"
isActive={[Function]}
onClick={[Function]}
>
Delete My Account
Expand Down
2 changes: 1 addition & 1 deletion src/id-verification/panels/GetNameIdPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const GetNameIdPanel = (props) => {
const handleSubmit = (e) => {
e.preventDefault();
if (idPhotoName) {
navigate(nextPanelSlug, { replace: true });
navigate(nextPanelSlug);
}
};

Expand Down
18 changes: 6 additions & 12 deletions src/id-verification/panels/SummaryPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ const SummaryPanel = (props) => {
/>
<Link
className="btn btn-outline-primary"
to={{
pathname: '/id-verification/take-portrait-photo',
state: { fromSummary: true },
}}
to="/id-verification/take-portrait-photo"
state={{ fromSummary: true }}
data-testid="portrait-retake"
>
{props.intl.formatMessage(messages['id.verification.review.portrait.retake'])}
Expand All @@ -192,10 +190,8 @@ const SummaryPanel = (props) => {
/>
<Link
className="btn btn-outline-primary"
to={{
pathname: '/id-verification/take-id-photo',
state: { fromSummary: true },
}}
to="/id-verification/take-id-photo"
state={{ fromSummary: true }}
data-testid="id-retake"
>
{props.intl.formatMessage(messages['id.verification.review.id.retake'])}
Expand All @@ -220,10 +216,8 @@ const SummaryPanel = (props) => {
{!profileDataManager && (
<Link
className="btn btn-link ml-3 px-0"
to={{
pathname: '/id-verification/get-name-id',
state: { fromSummary: true },
}}
to="/id-verification/get-name-id"
state={{ fromSummary: true }}
>
<FormattedMessage
id="id.verification.account.name.edit"
Expand Down
11 changes: 4 additions & 7 deletions src/id-verification/tests/AccessBlocked.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { BrowserRouter as Router } from 'react-router-dom';
import {
render, cleanup, act, screen,
} from '@testing-library/react';
Expand All @@ -12,8 +11,6 @@ import AccessBlocked from '../AccessBlocked';

const IntlAccessBlocked = injectIntl(AccessBlocked);

const history = createMemoryHistory();

describe('AccessBlocked', () => {
const defaultProps = {
intl: {},
Expand All @@ -28,7 +25,7 @@ describe('AccessBlocked', () => {
defaultProps.error = ERROR_REASONS.EXISTING_REQUEST;

await act(async () => render((
<Router history={history}>
<Router>
<IntlProvider locale="en">
<IntlAccessBlocked {...defaultProps} />
</IntlProvider>
Expand All @@ -44,7 +41,7 @@ describe('AccessBlocked', () => {
defaultProps.error = ERROR_REASONS.COURSE_ENROLLMENT;

await act(async () => render((
<Router history={history}>
<Router>
<IntlProvider locale="en">
<IntlAccessBlocked {...defaultProps} />
</IntlProvider>
Expand All @@ -60,7 +57,7 @@ describe('AccessBlocked', () => {
defaultProps.error = ERROR_REASONS.CANNOT_VERIFY;

await act(async () => render((
<Router history={history}>
<Router>
<IntlProvider locale="en">
<IntlAccessBlocked {...defaultProps} />
</IntlProvider>
Expand Down
Loading

0 comments on commit 126a9b4

Please sign in to comment.