refactor: update tests for ImportGradesButton to use react-unit-test-… (#338)
* fix: update package-lock * chore: update unit test library version * fix: move react-unit-test-utils to dependency * fix: unit-test-utils version * fix: update package-lock
This commit is contained in:
9109
package-lock.json
generated
9109
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,7 @@
|
||||
"@edx/frontend-platform": "^4.2.0",
|
||||
"@edx/paragon": "^20.20.0",
|
||||
"@edx/reactifex": "^2.1.1",
|
||||
"@edx/react-unit-test-utils": "1.5.3",
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.25",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.11.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.11.2",
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ImportGradesButton component render Form 1`] = `
|
||||
<Form
|
||||
action="test-grade-export-url"
|
||||
method="post"
|
||||
>
|
||||
<Form.Group
|
||||
controlId="csv"
|
||||
>
|
||||
<Form.Control
|
||||
className="d-none"
|
||||
data-testid="file-control"
|
||||
label="Upload Grade CSV"
|
||||
onChange={[MockFunction props.handleFileInputChange]}
|
||||
type="file"
|
||||
/>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
`;
|
||||
|
||||
exports[`ImportGradesButton component render snapshot 1`] = `
|
||||
<Fragment>
|
||||
<Form
|
||||
@@ -13,7 +32,7 @@ exports[`ImportGradesButton component render snapshot 1`] = `
|
||||
className="d-none"
|
||||
data-testid="file-control"
|
||||
label="Upload Grade CSV"
|
||||
onChange={[MockFunction]}
|
||||
onChange={[MockFunction props.handleFileInputChange]}
|
||||
type="file"
|
||||
/>
|
||||
</Form.Group>
|
||||
@@ -28,7 +47,7 @@ exports[`ImportGradesButton component render snapshot 1`] = `
|
||||
"id": "gradebook.GradesView.importGradesBtnText",
|
||||
}
|
||||
}
|
||||
onClick={[MockFunction]}
|
||||
onClick={[MockFunction props.handleClickImportGrades]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { shallow } from '@edx/react-unit-test-utils';
|
||||
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { Form } from '@edx/paragon';
|
||||
@@ -18,8 +18,8 @@ describe('ImportGradesButton component', () => {
|
||||
props = {
|
||||
fileInputRef: { current: null },
|
||||
gradeExportUrl: 'test-grade-export-url',
|
||||
handleClickImportGrades: jest.fn(),
|
||||
handleFileInputChange: jest.fn(),
|
||||
handleClickImportGrades: jest.fn().mockName('props.handleClickImportGrades'),
|
||||
handleFileInputChange: jest.fn().mockName('props.handleFileInputChange'),
|
||||
};
|
||||
useImportGradesButtonData.mockReturnValue(props);
|
||||
el = shallow(<ImportGradesButton />);
|
||||
@@ -32,14 +32,15 @@ describe('ImportGradesButton component', () => {
|
||||
});
|
||||
describe('render', () => {
|
||||
test('snapshot', () => {
|
||||
expect(el).toMatchSnapshot();
|
||||
expect(el.snapshot).toMatchSnapshot();
|
||||
});
|
||||
test('Form', () => {
|
||||
expect(el.find(Form).props().action).toEqual(props.gradeExportUrl);
|
||||
expect(el.find(Form.Control).props().onChange).toEqual(props.handleFileInputChange);
|
||||
expect(el.instance.findByType(Form)[0].snapshot).toMatchSnapshot();
|
||||
expect(el.instance.findByType(Form)[0].props.action).toEqual(props.gradeExportUrl);
|
||||
expect(el.instance.findByType(Form.Control)[0].props.onChange).toEqual(props.handleFileInputChange);
|
||||
});
|
||||
test('import button', () => {
|
||||
expect(el.find(NetworkButton).props().onClick).toEqual(props.handleClickImportGrades);
|
||||
expect(el.instance.findByType(NetworkButton)[0].props.onClick).toEqual(props.handleClickImportGrades);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user