Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Dec 13, 2023
1 parent c548d45 commit d6b09c5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = createConfig('eslint', {
rules: {
'react/function-component-definition': 'off',
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
},
overrides: [
{
Expand Down
6 changes: 5 additions & 1 deletion plugins/communications-app/CheckBoxForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const CheckBoxForm = ({ isChecked, handleChange, label }) => (
</Container>
);

CheckBoxForm.defaultProps = {
handleChange: () => {},
};

CheckBoxForm.propTypes = {
isChecked: PropTypes.bool.isRequired,
handleChange: PropTypes.func.isRequired,
handleChange: PropTypes.func,
label: PropTypes.string.isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
exports[`PluggableComponent renders correctly 1`] = `
<div>
<div
class="pgn__form-group"
class="pgn__form-group p-3 border border-success-300"
data-testid="plugin-input"
>
<label
class="pgn__form-label"
class="pgn__form-label h3 text-primary-500"
for="randomID"
>
Hello
</label>
<div
class="pgn__form-control-decorator-group"
class="row container-fluid"
>
<input
class="form-control is-valid"
id="randomID"
/>
<div
class="pgn__form-control-decorator-group col-3"
>
<input
class="form-control is-valid"
id="randomID"
/>
</div>
<p
class="col-8"
>
@openedx-plugins/communications-app-input-form
</p>
</div>
<div
class="pgn__form-control-description pgn__form-text pgn__form-text-valid"
Expand Down
1 change: 0 additions & 1 deletion src/components/PluggableComponent/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { render, waitFor, screen } from '@testing-library/react';
import PluggableComponent from '.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function BulkEmailForm(props) {
id="checkbox-form"
as="communications-app-check-box-form"
label="checkbox label - @openedx-plugins/communications-app-check-box-form"
onChange={() => null}
isChecked
>
<h1>Checkbox -default</h1>
</PluggableComponent>
Expand All @@ -292,7 +292,7 @@ function BulkEmailForm(props) {
<h1>Input -default</h1>
</PluggableComponent>
{/* this will return default child if the plugin has not been installed */}
<PluggableComponent id="input-form" as="communications-app-card">
<PluggableComponent id="card-form" as="communications-app-card">
<Card className="my-4 p-3 col-6 border border-success-300 w-100">
<Card.ImageCap
src="https://picsum.photos/360/200/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { formatDate } from '../../../../utils/formatDateAndTime';
import cohortFactory from '../data/__factories__/bulkEmailFormCohort.factory';

jest.mock('../../text-editor/TextEditor');
jest.mock('../../../PluggableComponent', () => () => null);

const appendMock = jest.spyOn(FormData.prototype, 'append');
const dispatchMock = jest.fn();
Expand Down
20 changes: 11 additions & 9 deletions src/components/bulk-email-tool/test/BulkEmailTool.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import { Factory } from 'rosie';
import { camelCaseObject } from '@edx/frontend-platform';
import {
render, screen, cleanup, initializeMockApp,
render, screen, cleanup, initializeMockApp, act,
} from '../../../setupTest';
import BulkEmailTool from '../BulkEmailTool';
import { CourseMetadataContext } from '../../page-container/PageContainer';
Expand Down Expand Up @@ -67,14 +67,16 @@ describe('BulkEmailTool', () => {
const cohorts = { cohorts: [] };
const courseInfo = Factory.build('courseMetadata');
const courseMetadata = buildCourseMetadata(cohorts, courseInfo);
renderBulkEmailTool(courseMetadata);
// verify all tab data expected is displayed within our component
expect(await screen.findByText('Course')).toBeTruthy();
expect(await screen.findByText('Discussion')).toBeTruthy();
expect(await screen.findByText('Wiki')).toBeTruthy();
expect(await screen.findByText('Progress')).toBeTruthy();
expect(await screen.findByText('Instructor')).toBeTruthy();
expect(await screen.findByText('Dates')).toBeTruthy();
await act(async () => {
renderBulkEmailTool(courseMetadata);
// verify all tab data expected is displayed within our component
expect(screen.findByText('Course')).toBeTruthy();
expect(screen.findByText('Discussion')).toBeTruthy();
expect(screen.findByText('Wiki')).toBeTruthy();
expect(screen.findByText('Progress')).toBeTruthy();
expect(screen.findByText('Instructor')).toBeTruthy();
expect(screen.findByText('Dates')).toBeTruthy();
});
});

test('BulkEmailTool renders error page on no staff user', async () => {
Expand Down

0 comments on commit d6b09c5

Please sign in to comment.