-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix: enzyme testing replaced by react tester #36159
base: master
Are you sure you want to change the base?
Changes from 18 commits
3a3b9b1
7ff5004
dc8557c
16397a1
3cf6c79
3f800ad
60f6746
34b532e
ac8f8a0
033c973
4fef66f
1a69f00
b7f10bb
f7a4847
4b0f48b
9e9f55f
9ace7e8
22320b2
6dac593
9b659e3
6b855af
a757c7b
b68a54c
4f0da14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
// eslint-disable-next-line no-redeclare | ||
/* global jest,test,describe,expect */ | ||
import { Button } from '@edx/paragon'; | ||
import BlockBrowserContainer from 'BlockBrowser/components/BlockBrowser/BlockBrowserContainer'; | ||
import { Provider } from 'react-redux'; | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import store from '../../data/store'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import store from '../../data/store'; | ||
import Main from './Main'; | ||
|
||
describe('ProblemBrowser Main component', () => { | ||
const courseId = 'testcourse'; | ||
const problemResponsesEndpoint = '/api/problem_responses/'; | ||
const taskStatusEndpoint = '/api/task_status/'; | ||
const excludedBlockTypes = []; | ||
const reportDownloadEndpoint = '/api/download_report/'; | ||
|
||
test('render with basic parameters', () => { | ||
const component = renderer.create( | ||
render( | ||
<Provider store={store}> | ||
<Main | ||
courseId={courseId} | ||
|
@@ -28,15 +27,16 @@ describe('ProblemBrowser Main component', () => { | |
onSelectBlock={jest.fn()} | ||
selectedBlock={null} | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
reportDownloadEndpoint={reportDownloadEndpoint} | ||
ShowBtnUi="false" | ||
/> | ||
</Provider>, | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
expect(screen.getByRole('button', { name: 'Select a section or problem' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('render with selected block', () => { | ||
const component = renderer.create( | ||
render( | ||
<Provider store={store}> | ||
<Main | ||
courseId={courseId} | ||
|
@@ -47,16 +47,17 @@ describe('ProblemBrowser Main component', () => { | |
onSelectBlock={jest.fn()} | ||
selectedBlock="some-selected-block" | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
reportDownloadEndpoint={reportDownloadEndpoint} | ||
ShowBtnUi="false" | ||
/> | ||
</Provider>, | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
expect(screen.getByRole('button', { name: 'Select a section or problem' })).toBeInTheDocument(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test also used to use a snapshot. That snapshot resulted in the following output
This test is now only checking for the To merge this PR this test needs to be updated to test everything it used to be testing. |
||
|
||
test('fetch course block on toggling dropdown', () => { | ||
test('fetch course block on toggling dropdown', async () => { | ||
const fetchCourseBlocksMock = jest.fn(); | ||
const component = renderer.create( | ||
render( | ||
<Provider store={store}> | ||
<Main | ||
courseId={courseId} | ||
|
@@ -67,30 +68,67 @@ describe('ProblemBrowser Main component', () => { | |
onSelectBlock={jest.fn()} | ||
selectedBlock="some-selected-block" | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
reportDownloadEndpoint={reportDownloadEndpoint} | ||
ShowBtnUi="false" | ||
/> | ||
</Provider>, | ||
); | ||
// eslint-disable-next-line prefer-destructuring | ||
const instance = component.root.children[0].instance; | ||
instance.handleToggleDropdown(); | ||
expect(fetchCourseBlocksMock.mock.calls.length).toBe(1); | ||
const toggleButton = screen.getByRole('button', { name: 'Select a section or problem' }); | ||
await userEvent.click(toggleButton); | ||
expect(fetchCourseBlocksMock).toHaveBeenCalledTimes(1); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 This test does a perfect job of replicating the behavior from before using RTL! 🎉 |
||
|
||
test('display dropdown on toggling dropdown', () => { | ||
const component = shallow( | ||
<Main | ||
courseId={courseId} | ||
createProblemResponsesReportTask={jest.fn()} | ||
excludeBlockTypes={excludedBlockTypes} | ||
fetchCourseBlocks={jest.fn()} | ||
problemResponsesEndpoint={problemResponsesEndpoint} | ||
onSelectBlock={jest.fn()} | ||
selectedBlock="some-selected-block" | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
/>, | ||
test('display dropdown on toggling dropdown', async () => { | ||
brian-smith-tcril marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render( | ||
<Provider store={store}> | ||
<Main | ||
courseId={courseId} | ||
createProblemResponsesReportTask={jest.fn()} | ||
excludeBlockTypes={excludedBlockTypes} | ||
fetchCourseBlocks={jest.fn()} | ||
problemResponsesEndpoint={problemResponsesEndpoint} | ||
onSelectBlock={jest.fn()} | ||
selectedBlock="some-selected-block" | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
reportDownloadEndpoint={reportDownloadEndpoint} | ||
ShowBtnUi="false" | ||
/> | ||
</Provider>, | ||
); | ||
expect(component.find(BlockBrowserContainer).length).toBeFalsy(); | ||
component.find(Button).find({ label: 'Select a section or problem' }).simulate('click'); | ||
expect(component.find(BlockBrowserContainer).length).toBeTruthy(); | ||
|
||
expect(screen.queryByText('Some expected block name')).toBeNull(); | ||
const toggleButton = screen.getByRole('button', { name: 'Select a section or problem' }); | ||
await userEvent.click(toggleButton); | ||
const blockName = screen.queryByText('Some expected block name'); | ||
expect(blockName).toBeNull(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit odd to me, it's expecting the query for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if the way I modified it is right, but the tests passed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if the way I modified it is right, but the tests passed. |
||
}); | ||
|
||
test('hide dropdown on second toggle', async () => { | ||
render( | ||
<Provider store={store}> | ||
<Main | ||
courseId={courseId} | ||
createProblemResponsesReportTask={jest.fn()} | ||
excludeBlockTypes={excludedBlockTypes} | ||
fetchCourseBlocks={jest.fn()} | ||
problemResponsesEndpoint={problemResponsesEndpoint} | ||
onSelectBlock={jest.fn()} | ||
selectedBlock="some-selected-block" | ||
taskStatusEndpoint={taskStatusEndpoint} | ||
reportDownloadEndpoint={reportDownloadEndpoint} | ||
ShowBtnUi="false" | ||
/> | ||
</Provider>, | ||
); | ||
const toggleButton = screen.getByRole('button', { name: 'Select a section or problem' }); | ||
|
||
await userEvent.click(toggleButton); | ||
await waitFor(() => { | ||
expect(screen.queryByText('Select a section or problem')).not.toBeNull(); | ||
}); | ||
await userEvent.click(toggleButton); | ||
await waitFor(() => { | ||
expect(screen.queryByText('Some expected block name')).toBeNull(); | ||
}); | ||
}); | ||
}); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test used to use a snapshot. That snapshot resulted in the following output
This test is now only checking for the
'Select a section or problem'
button. That is a large change in behavior from before.To merge this PR this test needs to be updated to test everything it used to be testing.