Skip to content

Commit 7cd6894

Browse files
committed
test: fix render issues
1 parent ec5065a commit 7cd6894

File tree

13 files changed

+88
-47
lines changed

13 files changed

+88
-47
lines changed

src/Configuration/Customers/CustomerDetailView/tests/EnterpriseCustomerUserDetail.test.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
render,
55
} from '@testing-library/react';
66
import '@testing-library/jest-dom';
7+
import { IntlProvider } from '@edx/frontend-platform/i18n';
78
import {
89
EnterpriseCustomerUserDetail,
910
AdministratorCell,
@@ -20,7 +21,7 @@ describe('EnterpriseCustomerUserDetail', () => {
2021
},
2122
},
2223
};
23-
render(<EnterpriseCustomerUserDetail row={enterpriseCustomerUser} />);
24+
render(<IntlProvider locale="en"><EnterpriseCustomerUserDetail row={enterpriseCustomerUser} /></IntlProvider>);
2425
expect(screen.getByText('ash ketchum')).toBeInTheDocument();
2526
expect(screen.getByText('[email protected]')).toBeInTheDocument();
2627
expect(screen.getByTestId('icon-hyperlink')).toHaveAttribute('href', '/learner-information/[email protected]');
@@ -35,7 +36,7 @@ describe('EnterpriseCustomerUserDetail', () => {
3536
},
3637
},
3738
};
38-
render(<EnterpriseCustomerUserDetail row={pendingEnterpriseCustomerUser} />);
39+
render(<IntlProvider locale="en"><EnterpriseCustomerUserDetail row={pendingEnterpriseCustomerUser} /></IntlProvider>);
3940
expect(screen.getByText('[email protected]')).toBeInTheDocument();
4041
expect(screen.queryByTestId('icon-hyperlink')).not.toBeInTheDocument();
4142
expect(screen.queryByTestId('username-email-hyperlink')).not.toBeInTheDocument();
@@ -50,7 +51,7 @@ describe('EnterpriseCustomerUserDetail', () => {
5051
roleAssignments: ['enterprise_learner'],
5152
},
5253
};
53-
render(<AdministratorCell row={pendingAdmin} />);
54+
render(<IntlProvider locale="en"><AdministratorCell row={pendingAdmin} /></IntlProvider>);
5455
expect(screen.getByText('Pending')).toBeInTheDocument();
5556
});
5657

@@ -63,7 +64,7 @@ describe('EnterpriseCustomerUserDetail', () => {
6364
roleAssignments: ['enterprise_admin'],
6465
},
6566
};
66-
render(<AdministratorCell row={adminRow} />);
67+
render(<IntlProvider locale="en"><AdministratorCell row={adminRow} /></IntlProvider>);
6768
expect(screen.queryByText('Pending')).not.toBeInTheDocument();
6869
});
6970

@@ -78,7 +79,7 @@ describe('EnterpriseCustomerUserDetail', () => {
7879
roleAssignments: ['enterprise_learner'],
7980
},
8081
};
81-
render(<LearnerCell row={learnerRow} />);
82+
render(<IntlProvider locale="en"><LearnerCell row={learnerRow} /></IntlProvider>);
8283
expect(screen.queryByText('Pending')).not.toBeInTheDocument();
8384
});
8485

@@ -92,7 +93,7 @@ describe('EnterpriseCustomerUserDetail', () => {
9293
enterpriseCustomerUser: null,
9394
},
9495
};
95-
render(<LearnerCell row={pendingLearnerRow} />);
96+
render(<IntlProvider locale="en"><LearnerCell row={pendingLearnerRow} /></IntlProvider>);
9697
expect(screen.queryByText('Pending')).toBeInTheDocument();
9798
});
9899
});

src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { renderWithRouter } from '@edx/frontend-enterprise-utils';
33
import { screen, waitFor } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55
import { camelCaseObject } from '@edx/frontend-platform';
6+
import { IntlProvider } from '@edx/frontend-platform/i18n';
67
import { DashboardContext, initialStateValue } from '../../../testData/Dashboard';
78
import DashboardDataTable from '../DashboardDataTable';
89
import { sampleDataTableData } from '../../../testData/constants';
@@ -31,9 +32,11 @@ jest.mock('../../../../data/services/EnterpriseApiService', () => ({
3132
const DashboardDatatableWrapper = ({
3233
value = initialStateValue,
3334
}) => (
34-
<DashboardContext value={value}>
35-
<DashboardDataTable />
36-
</DashboardContext>
35+
<IntlProvider locale="en">
36+
<DashboardContext value={value}>
37+
<DashboardDataTable />
38+
</DashboardContext>
39+
</IntlProvider>
3740
);
3841

3942
describe('DashboardDatatable', () => {

src/Configuration/Provisioning/DashboardDataTable/tests/DashboardTableLinks.test.jsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react/prop-types */
22
import { screen, render } from '@testing-library/react';
33
import { getConfig } from '@edx/frontend-platform';
4+
import { IntlProvider } from '@edx/frontend-platform/i18n';
45
import {
56
CustomerNameHyperlink,
67
DjangoIconHyperlink,
@@ -31,13 +32,13 @@ describe('DashboardTableLinks', () => {
3132
getConfig.mockImplementation(() => ({
3233
FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: 'true',
3334
}));
34-
render(<PlanIdHyperlink row={row} />);
35+
render(<IntlProvider locale="en"><PlanIdHyperlink row={row} /></IntlProvider>);
3536
expect(screen.getByRole('link', { name: '123456789' })).toHaveAttribute('href', '/enterprise-configuration/learner-credit/123456789/view');
3637
});
3738

3839
it('does not render hyperlink if FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION is false', () => {
3940
getConfig.mockReturnValue({ FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: false });
40-
render(<PlanIdHyperlink row={row} />);
41+
render(<IntlProvider locale="en"><PlanIdHyperlink row={row} /></IntlProvider>);
4142
expect(screen.queryByRole('link', { name: '123456789' })).toBeNull();
4243
});
4344
});
@@ -51,13 +52,13 @@ describe('DashboardTableLinks', () => {
5152
getConfig.mockImplementation(() => ({
5253
FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: 'true',
5354
}));
54-
render(<PlanTitleHyperlink row={row} />);
55+
render(<IntlProvider locale="en"><PlanTitleHyperlink row={row} /></IntlProvider>);
5556
expect(screen.getByRole('link', { name: 'Pikachu' })).toHaveAttribute('href', '/enterprise-configuration/learner-credit/123456789/view');
5657
});
5758

5859
it('does not render hyperlink if FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION is false', () => {
5960
getConfig.mockReturnValue({ FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: false });
60-
render(<PlanTitleHyperlink row={row} />);
61+
render(<IntlProvider locale="en"><PlanTitleHyperlink row={row} /></IntlProvider>);
6162
expect(screen.queryByRole('link', { name: 'Pikachu' })).toBeNull();
6263
});
6364
});
@@ -71,13 +72,13 @@ describe('DashboardTableLinks', () => {
7172
getConfig.mockImplementation(() => ({
7273
FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: 'true',
7374
}));
74-
render(<CustomerNameHyperlink row={row} />);
75+
render(<IntlProvider locale="en"><CustomerNameHyperlink row={row} /></IntlProvider>);
7576
expect(screen.getByRole('link', { name: 'Ash Ketchum' })).toHaveAttribute('href', '/enterprise-configuration/learner-credit/123456789/view');
7677
});
7778

7879
it('does not render hyperlink if FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION is false', () => {
7980
getConfig.mockReturnValue({ FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: false });
80-
render(<CustomerNameHyperlink row={row} />);
81+
render(<IntlProvider locale="en"><CustomerNameHyperlink row={row} /></IntlProvider>);
8182
expect(screen.queryByRole('link', { name: 'Ash Ketchum' })).toBeNull();
8283
});
8384
});
@@ -91,7 +92,7 @@ describe('DashboardTableLinks', () => {
9192
getConfig.mockImplementation(() => ({
9293
DJANGO_ADMIN_SUBSIDY_BASE_URL: 'https://pokemons.com',
9394
}));
94-
render(<DjangoIconHyperlink row={row} />);
95+
render(<IntlProvider locale="en"><DjangoIconHyperlink row={row} /></IntlProvider>);
9596
expect(screen.getByTestId('django-admin-link')).toHaveAttribute('href', 'https://pokemons.com/admin/subsidy/subsidy/123456789/change/');
9697
});
9798
});

src/Configuration/Provisioning/ErrorPage/tests/ErrorPageContainer.test.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react/prop-types */
22
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
3-
import { fireEvent, screen } from '@testing-library/react';
3+
import { fireEvent, screen, cleanup } from '@testing-library/react';
4+
import { IntlProvider } from '@edx/frontend-platform/i18n';
45
import ErrorPageContainer from '../ErrorPageContainer';
56
import { ERROR_PAGE_TEXT } from '../data/constants';
67

@@ -16,12 +17,13 @@ jest.mock('react-router-dom', () => ({
1617
}));
1718

1819
describe('<ErrorPageContainerWrapper>', () => {
20+
afterEach(cleanup);
1921
it('Displays the passed error message', () => {
20-
renderWithRouter(<ErrorPageContainer to="/" />);
22+
renderWithRouter(<IntlProvider locale="en"><ErrorPageContainer to="/" /></IntlProvider>);
2123
expect(screen.getByText('Test Error Message', { exact: false })).toBeTruthy();
2224
});
2325
it('Redirects on button click', () => {
24-
renderWithRouter(<ErrorPageContainer to="/" />);
26+
renderWithRouter(<IntlProvider locale="en"><ErrorPageContainer to="/" /></IntlProvider>);
2527
const button = screen.getByText(ERROR_PAGE_TEXT.BUTTON);
2628
expect(button).toBeTruthy();
2729
fireEvent.click(button);

src/Configuration/Provisioning/SubsidyDetailView/PolicyDetailView/tests/CustomCatalogDetail.test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import React from 'react';
22
import { screen } from '@testing-library/react';
33
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
44
import '@testing-library/jest-dom/extend-expect';
5+
import { IntlProvider } from '@edx/frontend-platform/i18n';
6+
57
import CustomCatalogDetail from '../CustomCatalogDetail';
68

79
const mockCatalogTitle = 'Foo Bar Catalog';
810

911
describe('CustomCatalogDetail', () => {
1012
it('renders the component with content', () => {
1113
renderWithRouter(
12-
<CustomCatalogDetail catalogTitle={mockCatalogTitle} />,
14+
<IntlProvider locale="en"><CustomCatalogDetail catalogTitle={mockCatalogTitle} /></IntlProvider>,
1315
);
1416
expect(screen.getByText(mockCatalogTitle)).toBeInTheDocument();
1517
});

src/Configuration/test/ConfigurationPage.test.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { cleanup, render, screen } from '@testing-library/react';
2+
import { IntlProvider } from '@edx/frontend-platform/i18n';
23
import ConfigurationPage from '../ConfigurationPage';
34
import ROUTES from '../../data/constants/routes';
45
import { titleCase } from '../../utils';
56
import CONFIGURATION_PAGE_TEXT from '../data/constants';
67

78
const { CONFIGURATION: { SUB_DIRECTORY } } = ROUTES;
89

10+
const ConfigurationPageWrapper = () => (
11+
<IntlProvider locale="en">
12+
<ConfigurationPage />
13+
</IntlProvider>
14+
);
15+
916
describe('ConfigurationPage', () => {
17+
afterEach(cleanup);
18+
1019
it('renders', () => {
11-
render(<ConfigurationPage />);
20+
render(<ConfigurationPageWrapper />);
1221
expect(screen.getByText(CONFIGURATION_PAGE_TEXT.HEADER)).toBeTruthy();
1322
});
1423
it('renders links to subdirectories', () => {
15-
render(<ConfigurationPage />);
24+
render(<ConfigurationPageWrapper />);
1625
Object.keys(SUB_DIRECTORY).forEach((route) => {
1726
expect(screen.getByText(titleCase(route))).toBeTruthy();
1827
});

src/ProgramEnrollments/ProgramInspector/EnrollmentDetails.test.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { mount } from 'enzyme';
22
import React from 'react';
33
import { MemoryRouter } from 'react-router-dom';
4+
import { IntlProvider } from '@edx/frontend-platform/i18n';
45
import UserMessagesProvider from '../../userMessages/UserMessagesProvider';
56
import EnrollmentDetails from './EnrollmentDetails';
67
import { programInspectorSuccessResponse } from './data/test/programInspector';
78

89
const EnrollmentDetailsWrapper = (props) => (
9-
<MemoryRouter>
10-
<UserMessagesProvider>
11-
<EnrollmentDetails {...props} />
12-
</UserMessagesProvider>
13-
</MemoryRouter>
10+
<IntlProvider locale="en">
11+
<MemoryRouter>
12+
<UserMessagesProvider>
13+
<EnrollmentDetails {...props} />
14+
</UserMessagesProvider>
15+
</MemoryRouter>
16+
</IntlProvider>
1417
);
1518

1619
describe('Enrollment Details', () => {

src/ProgramEnrollments/ProgramInspector/ProgramInspector.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ export default function ProgramInspector() {
140140
defaultValue={activeOrgKey}
141141
onChange={(e) => setActiveOrgKey(e.target.value)}
142142
>
143-
{
144-
getOrgKeyList() && getOrgKeyList()
145-
.map(({ label, value, disabled }) => <option key={value} value={value} disabled={disabled}>{label}</option>)
146-
}
143+
{ getOrgKeyList() && getOrgKeyList().map(
144+
(
145+
{ label, value, disabled },
146+
) => <option key={value} value={value} disabled={disabled}>{label}</option>,
147+
)}
147148
</Form.Control>
148149
</Form.Group>
149150
</div>

src/users/CopyShowHyperLinks.test.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from 'enzyme';
22
import React from 'react';
3+
import { IntlProvider } from '@edx/frontend-platform/i18n';
34
import CopyShowHyperlinks from './CopyShowHyperLinks';
45

56
describe('Copy Show Hyperlinks', () => {
@@ -11,7 +12,7 @@ describe('Copy Show Hyperlinks', () => {
1112
props = {
1213
text,
1314
};
14-
wrapper = mount(<CopyShowHyperlinks {...props} />);
15+
wrapper = mount(<IntlProvider locale="en"><CopyShowHyperlinks {...props} /></IntlProvider>);
1516
});
1617
it('Text Value', () => {
1718
const copy = wrapper.find('a').at(0);

src/users/SingleSignOnRecordCard.test.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { mount } from 'enzyme';
22
import React from 'react';
33
import { camelCaseObject } from '@edx/frontend-platform';
4+
import { IntlProvider } from '@edx/frontend-platform/i18n';
45
import ssoRecordsData from './data/test/ssoRecords';
56
import SingleSignOnRecordCard from './SingleSignOnRecordCard';
67
import { formatDate, formatUnixTimestamp } from '../utils';
78

9+
const SingleSignOnRecordCardWrapper = (props) => (
10+
<IntlProvider locale="en">
11+
<SingleSignOnRecordCard {...props} />
12+
</IntlProvider>
13+
);
14+
815
describe.each(ssoRecordsData)('Single Sign On Record Card', (ssoRecordData) => {
916
// prepare data
1017
const ssoRecordProp = camelCaseObject({
@@ -19,7 +26,7 @@ describe.each(ssoRecordsData)('Single Sign On Record Card', (ssoRecordData) => {
1926
props = {
2027
ssoRecord: ssoRecordProp,
2128
};
22-
wrapper = mount(<SingleSignOnRecordCard {...props} />);
29+
wrapper = mount(<SingleSignOnRecordCardWrapper {...props} />);
2330
});
2431

2532
it('SSO props', () => {
@@ -31,7 +38,7 @@ describe.each(ssoRecordsData)('Single Sign On Record Card', (ssoRecordData) => {
3138
props = {
3239
ssoRecord: null,
3340
};
34-
wrapper = mount(<SingleSignOnRecordCard {...props} />);
41+
wrapper = mount(<SingleSignOnRecordCardWrapper {...props} />);
3542

3643
expect(wrapper.isEmptyRender()).toBeTruthy();
3744
});

0 commit comments

Comments
 (0)