Skip to content

Commit

Permalink
fix: resolve console warnings in tests (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-amir committed Apr 1, 2024
1 parent 60a6c97 commit e9af062
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/base-container/tests/BaseContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe('Base component tests', () => {
it('should show default layout', () => {
const { container } = render(
<IntlProvider locale="en">
<BaseContainer />
<BaseContainer>
<div>Test Content</div>
</BaseContainer>
</IntlProvider>,
LargeScreen,
);
Expand All @@ -32,7 +34,9 @@ describe('Base component tests', () => {

const { container } = render(
<IntlProvider locale="en">
<BaseContainer showWelcomeBanner={false} />
<BaseContainer showWelcomeBanner={false}>
<div>Test Content</div>
</BaseContainer>
</IntlProvider>,
LargeScreen,
);
Expand Down
20 changes: 10 additions & 10 deletions src/common-components/tests/EmbeddedRegistrationRoute.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getConfig } from '@edx/frontend-platform';
import { render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';

import { REGISTER_EMBEDDED_PAGE } from '../../data/constants';
import { PAGE_NOT_FOUND, REGISTER_EMBEDDED_PAGE } from '../../data/constants';
import EmbeddedRegistrationRoute from '../EmbeddedRegistrationRoute';

import {
Expand All @@ -27,6 +27,10 @@ const TestApp = () => (
path={REGISTER_EMBEDDED_PAGE}
element={<EmbeddedRegistrationRoute><span>Embedded Register Page</span></EmbeddedRegistrationRoute>}
/>
<Route
path={PAGE_NOT_FOUND}
element={<span>Page not found</span>}
/>
</Routes>
</div>
</Router>
Expand All @@ -45,15 +49,13 @@ describe('EmbeddedRegistrationRoute', () => {

it('should not render embedded register page if host query param is not available in the url', async () => {
let embeddedRegistrationPage = null;

await act(async () => {
const { container } = await render(routerWrapper());
embeddedRegistrationPage = container;
});

const spanElement = embeddedRegistrationPage.querySelector('span');

expect(spanElement).toBeNull();
const renderedPage = embeddedRegistrationPage.querySelector('span');
expect(renderedPage.textContent).toBe('Page not found');
});

it('should render embedded register page if host query param is available in the url (embedded)', async () => {
Expand All @@ -64,15 +66,13 @@ describe('EmbeddedRegistrationRoute', () => {
};

let embeddedRegistrationPage = null;

await act(async () => {
const { container } = await render(routerWrapper());
embeddedRegistrationPage = container;
});

const spanElement = embeddedRegistrationPage.querySelector('span');

expect(spanElement).toBeTruthy();
expect(spanElement.textContent).toBe('Embedded Register Page');
const renderedPage = embeddedRegistrationPage.querySelector('span');
expect(renderedPage).toBeTruthy();
expect(renderedPage.textContent).toBe('Embedded Register Page');
});
});
28 changes: 14 additions & 14 deletions src/login/tests/LoginFailure.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('LoginFailureMessage', () => {
it('should match non compliant password error message', () => {
props = {
errorCode: NON_COMPLIANT_PASSWORD_EXCEPTION,
failureCount: 0,
errorCount: 0,
};

render(
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('LoginFailureMessage', () => {
supportLink: 'http://support.openedx.test',
},
errorCode: INACTIVE_USER,
failureCount: 0,
errorCount: 0,
};

render(
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('LoginFailureMessage', () => {
resetLink: '/reset',
},
errorCode: FAILED_LOGIN_ATTEMPT,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -127,7 +127,7 @@ describe('LoginFailureMessage', () => {
resetLink: '/reset',
},
errorCode: INCORRECT_EMAIL_PASSWORD,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -147,7 +147,7 @@ describe('LoginFailureMessage', () => {
it('test match user account locked out', () => {
props = {
errorCode: ACCOUNT_LOCKED_OUT,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -171,7 +171,7 @@ describe('LoginFailureMessage', () => {
resetLink: '/reset',
},
errorCode: INCORRECT_EMAIL_PASSWORD,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -191,7 +191,7 @@ describe('LoginFailureMessage', () => {
it('should match rate limit error message', () => {
props = {
errorCode: FORBIDDEN_REQUEST,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -211,7 +211,7 @@ describe('LoginFailureMessage', () => {
it('should match internal server error message', () => {
props = {
errorCode: INTERNAL_SERVER_ERROR,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -231,7 +231,7 @@ describe('LoginFailureMessage', () => {
it('should match invalid form error message', () => {
props = {
errorCode: INVALID_FORM,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -250,7 +250,7 @@ describe('LoginFailureMessage', () => {
it('should match internal server of error message', () => {
props = {
errorCode: 'invalid-error-code',
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -269,7 +269,7 @@ describe('LoginFailureMessage', () => {
it('should match tpa authentication failed error message', () => {
props = {
errorCode: TPA_AUTHENTICATION_FAILURE,
failureCount: 0,
errorCount: 0,
context: { errorMessage: 'An error occurred' },
};

Expand All @@ -295,7 +295,7 @@ describe('LoginFailureMessage', () => {
it('should show modal that nudges users to change password', () => {
props = {
errorCode: NUDGE_PASSWORD_CHANGE,
failureCount: 0,
errorCount: 0,
};

render(
Expand All @@ -321,7 +321,7 @@ describe('LoginFailureMessage', () => {
it('should show modal that requires users to change password', () => {
props = {
errorCode: REQUIRE_PASSWORD_CHANGE,
failureCount: 0,
errorCount: 0,
};

render(
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('LoginFailureMessage', () => {
tpaHint: 'google-auth2',
},
errorCode: ALLOWED_DOMAIN_LOGIN_ERROR,
failureCount: 0,
errorCount: 0,
};

render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('ProgressiveProfilingTests', () => {
optionalFields,
},
});
getAuthenticatedUser.mockReturnValue({ userId: 3, username: 'abc123' });
getAuthenticatedUser.mockReturnValue({ userId: 3, username: 'abc123', name: 'Test User' });
});

// ******** test form links and modal ********
Expand Down
3 changes: 3 additions & 0 deletions src/recommendations/ProductCard/BaseCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const BaseCard = ({
footer,
handleOnClick,
isLoading,
redirectUrl,
}) => (
<div className="recommendation-card" key={`container-${uuid}`}>
<Hyperlink
target="_blank"
className="card-box d-inline"
showLaunchIcon={false}
destination={redirectUrl}
onClick={handleOnClick}
>
<Card
Expand Down Expand Up @@ -67,6 +69,7 @@ BaseCard.propTypes = {
customHeaderImage: PropTypes.string.isRequired,
schoolLogo: PropTypes.string.isRequired,
isLoading: PropTypes.bool,
redirectUrl: PropTypes.string.isRequired,
handleOnClick: PropTypes.func.isRequired,
};

Expand Down
4 changes: 3 additions & 1 deletion src/recommendations/ProductCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const ProductCard = ({
`recommendation.product-card.pill-text.${createCodeFriendlyProduct(productType)}`
],
);
const handleCardClick = () => {
const handleCardClick = (event) => {
event.preventDefault();
trackRecommendationClick(
product,
position + 1,
Expand All @@ -83,6 +84,7 @@ const ProductCard = ({
productType={productType}
variant={variant}
isLoading={isLoading}
redirectUrl={product.url || product?.activeCourseRun?.marketingUrl}
footer={(
<Footer
quickFacts={product.degree?.quickFacts}
Expand Down
28 changes: 24 additions & 4 deletions src/recommendations/data/tests/mockedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const mockedRecommendedProducts = [
image: {
src: 'test_src',
},
owners: [],
owners: [
{
name: 'Test Org',
logoImageUrl: 'http://logourl.com',
},
],
title: 'test_title',
uuid: 'test_uuid',
objectID: 'course-test_uuid',
Expand All @@ -37,7 +42,12 @@ const mockedRecommendedProducts = [
image: {
src: 'test_src',
},
owners: [],
owners: [
{
name: 'Test Org',
logoImageUrl: 'http://logourl.com',
},
],
title: 'test_title',
uuid: 'test_uuid2',
objectID: 'course-test_uuid',
Expand All @@ -60,7 +70,12 @@ const mockedRecommendedProducts = [
image: {
src: 'test_src',
},
owners: [],
owners: [
{
name: 'Test Org',
logoImageUrl: 'http://logourl.com',
},
],
title: 'test_title',
uuid: 'test_uuid3',
objectID: 'course-test_uuid',
Expand All @@ -83,7 +98,12 @@ const mockedRecommendedProducts = [
image: {
src: 'test_src',
},
owners: [],
owners: [
{
name: 'Test Org',
logoImageUrl: 'http://logourl.com',
},
],
title: 'test_title',
uuid: 'test_uuid4',
objectID: 'course-test_uuid',
Expand Down
11 changes: 8 additions & 3 deletions src/recommendations/data/tests/parser.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import processCourseSearchResult from '../algoliaResultsParser';

describe('AlgoliaResultsParserTests', () => {
const dataToBeProcessed = {
activeRunKey: 'course-v1:TEST_COURSE_RUN',
activeRunType: 'test_course_run_type',
active_run_key: 'course-v1:TEST_COURSE_RUN',
active_run_type: 'test_course_run_type',
marketingUrl: 'test_marketingUrl',
minEffort: 1,
maxEffort: 2,
weeksToComplete: 3,
allowedIn: [],
blockedIn: [],
cardImageUrl: 'test_src',
owners: [],
owners: [
{
name: 'Test Org',
logoImageUrl: 'http://logourl.com',
},
],
title: 'test_title',
uuid: 'test_uuid',
recentEnrollmentCount: 1,
Expand Down
5 changes: 4 additions & 1 deletion src/reset-password/tests/ResetPasswordPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { configure, injectIntl, IntlProvider } from '@edx/frontend-platform/i18n
import {
fireEvent, render, screen,
} from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { MemoryRouter } from 'react-router-dom';
import configureStore from 'redux-mock-store';

Expand Down Expand Up @@ -102,7 +103,9 @@ describe('ResetPasswordPage', () => {
fireEvent.change(confirmPasswordInput, { target: { value: password } });

const resetPasswordButton = screen.getByRole('button', { name: /Reset password/i, id: 'submit-new-password' });
fireEvent.click(resetPasswordButton);
await act(async () => {
fireEvent.click(resetPasswordButton);
});
expect(store.dispatch).toHaveBeenCalledWith(
resetPassword({ new_password1: password, new_password2: password }, props.token, {}),
);
Expand Down

0 comments on commit e9af062

Please sign in to comment.