Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate enzyme to RTL #1164

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: remaining test cases
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Jan 29, 2024
commit e554994d38d579b65253107a3a72b473ea00bb72
4 changes: 2 additions & 2 deletions src/components/Admin/AdminSearchForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AdminSearchForm extends React.Component {
value={searchCourseQuery}
onChange={e => this.onCourseSelect(e)}
>
<option value="">All Courses</option>
<option value="" data-testid="form-control-option">All Courses</option>
{courseTitles.map(title => (
<option
value={title}
Expand Down Expand Up @@ -97,7 +97,7 @@ class AdminSearchForm extends React.Component {
})}
disabled={!searchCourseQuery}
>
<option value="">{searchCourseQuery ? 'All Dates' : 'Choose a course'}</option>
<option value="" data-testid="form-control-option">{searchCourseQuery ? 'All Dates' : 'Choose a course'}</option>
{searchCourseQuery && courseDates.map(date => (
<option
value={date}
Expand Down
17 changes: 8 additions & 9 deletions src/components/Admin/AdminSearchForm.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
import { FormControl } from '@edx/paragon';
import { render, screen } from '@testing-library/react';

import AdminSearchForm from './AdminSearchForm';
import SearchBar from '../SearchBar';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand All @@ -19,10 +17,11 @@ const DEFAULT_PROPS = {

describe('<AdminSearchForm />', () => {
it('displays three filters', () => {
const wrapper = mount(<AdminSearchForm {...DEFAULT_PROPS} />);
expect(wrapper.find(FormControl)).toHaveLength(2);
expect(wrapper.find(SearchBar)).toHaveLength(1);
expect(wrapper.find(FormControl).at(1).text()).toContain('Choose a course');
render(<AdminSearchForm {...DEFAULT_PROPS} />);

expect(screen.getAllByTestId('form-control-option')).toHaveLength(2);
expect(screen.getByPlaceholderText('Search by email...')).toBeTruthy();
expect(screen.getAllByTestId('form-control-option')[1].textContent).toContain('Choose a course');
});
[
{ searchQuery: 'foo' },
Expand All @@ -32,8 +31,8 @@ describe('<AdminSearchForm />', () => {
it(`calls searchEnrollmentsList when ${Object.keys(searchParams)[0]} changes`, () => {
const spy = jest.fn();
const props = { ...DEFAULT_PROPS, searchEnrollmentsList: spy };
const wrapper = mount(<AdminSearchForm {...props} />);
wrapper.setProps({ searchParams });
const wrapper = render(<AdminSearchForm {...props} />);
wrapper.rerender(<AdminSearchForm {...props} searchParams={searchParams} />);
expect(spy).toHaveBeenCalledTimes(1);
});
});
Expand Down
39 changes: 39 additions & 0 deletions src/components/Admin/__snapshots__/Admin.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ exports[`<Admin /> renders correctly calls fetchDashboardAnalytics prop 1`] = `
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -742,6 +743,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # cou
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -852,6 +854,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # cou
id="form-field11"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -901,6 +904,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # cou
id="form-field12"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -1565,6 +1569,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -1675,6 +1680,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
id="form-field36"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -1724,6 +1730,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
id="form-field37"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -2388,6 +2395,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -2498,6 +2506,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
id="form-field41"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -2547,6 +2556,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
id="form-field42"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -3211,6 +3221,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders colla
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -3321,6 +3332,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders colla
id="form-field46"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -3370,6 +3382,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders colla
id="form-field47"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -4034,6 +4047,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders full
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -4144,6 +4158,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders full
id="form-field1"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -4193,6 +4208,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders full
id="form-field2"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -4857,6 +4873,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -4967,6 +4984,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
id="form-field31"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -5016,6 +5034,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
id="form-field32"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -5680,6 +5699,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -5790,6 +5810,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
id="form-field26"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -5839,6 +5860,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
id="form-field27"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -6503,6 +6525,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders learn
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -6613,6 +6636,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders learn
id="form-field16"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -6662,6 +6686,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders learn
id="form-field17"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -7326,6 +7351,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders regis
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -7436,6 +7462,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders regis
id="form-field6"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -7485,6 +7512,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders regis
id="form-field7"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -8149,6 +8177,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders top a
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -8259,6 +8288,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders top a
id="form-field21"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -8308,6 +8338,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders top a
id="form-field22"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -9017,6 +9048,7 @@ exports[`<Admin /> renders correctly with dashboard insights data renders dashbo
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -9127,6 +9159,7 @@ exports[`<Admin /> renders correctly with dashboard insights data renders dashbo
id="form-field56"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -9176,6 +9209,7 @@ exports[`<Admin /> renders correctly with dashboard insights data renders dashbo
id="form-field57"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down Expand Up @@ -9365,6 +9399,7 @@ exports[`<Admin /> renders correctly with error state 1`] = `
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -9533,6 +9568,7 @@ exports[`<Admin /> renders correctly with loading state 1`] = `
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -10204,6 +10240,7 @@ exports[`<Admin /> renders correctly with no dashboard insights data 1`] = `
>
<div
class="loading d-flex align-items-center justify-content-center subscriptions"
data-testid="loading-message"
>
Loading...
<span
Expand Down Expand Up @@ -10314,6 +10351,7 @@ exports[`<Admin /> renders correctly with no dashboard insights data 1`] = `
id="form-field51"
>
<option
data-testid="form-control-option"
value=""
>
All Courses
Expand Down Expand Up @@ -10363,6 +10401,7 @@ exports[`<Admin /> renders correctly with no dashboard insights data 1`] = `
id="form-field52"
>
<option
data-testid="form-control-option"
value=""
>
Choose a course
Expand Down
4 changes: 2 additions & 2 deletions src/components/AdminRegisterPage/AdminRegisterPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('<AdminRegisterPage />', () => {
render(<AdminRegisterPageWrapper />);

// verify that the loading skeleton appears during redirect
await waitFor(() => expect(screen.getByText('Loading...')).toBeTruthy());
await waitFor(() => expect(screen.getByTestId('enterprise-app-skeleton')).toBeTruthy());
await waitFor(() => expect(global.location.href).toBeTruthy());
});

Expand All @@ -69,7 +69,7 @@ describe('<AdminRegisterPage />', () => {
data: mockEnterpriseCustomer,
}));
render(<AdminRegisterPageWrapper />);
await waitFor(() => expect(screen.getByText('Loading...')).toBeTruthy());
await waitFor(() => expect(screen.getByTestId('enterprise-app-skeleton')).toBeTruthy());
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ exports[`ManageCodesTabWrapper renders renders loading state correctly 1`] = `
>
<div
class="loading d-flex align-items-center justify-content-center coupons mt-3"
data-testid="loading-message"
>
Loading...
<span
Expand Down
Loading
Loading