Skip to content

Commit

Permalink
refactor: changing BuildEmailFormExtensible to BulkEmailForm
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Mar 20, 2024
1 parent 39b9941 commit fccfd57
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions plugins/communications-app/BodyForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { Form } from '@openedx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import TextEditor from '@communications-app/src/components/bulk-email-tool/text-editor/TextEditor';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context/reducer';

import messages from './messages';

Expand Down
4 changes: 2 additions & 2 deletions plugins/communications-app/RecipientsForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { Form } from '@openedx/paragon';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context/reducer';

import './styles.scss';

Expand Down
4 changes: 2 additions & 2 deletions plugins/communications-app/ScheduleSection/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import ScheduleEmailForm from '@communications-app/src/components/bulk-email-tool/bulk-email-form/ScheduleEmailForm';
import useMobileResponsive from '@communications-app/src/utils/useMobileResponsive';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context/reducer';

import messages from './messages';

Expand Down
4 changes: 2 additions & 2 deletions plugins/communications-app/SubjectForm/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Form } from '@openedx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context/reducer';

import messages from './messages';

Expand Down
4 changes: 2 additions & 2 deletions plugins/communications-app/TaskAlertModalForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import TaskAlertModal from '@communications-app/src/components/bulk-email-tool/task-alert-modal';
import { getScheduledBulkEmailThunk } from '@communications-app/src/components/bulk-email-tool/bulk-email-task-manager/bulk-email-scheduled-emails-table/data/thunks';
import { BulkEmailContext } from '@communications-app/src/components/bulk-email-tool/bulk-email-context';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BuildEmailFormExtensible/context/reducer';
import { useSelector, useDispatch } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context';
import { actionCreators as formActions } from '@communications-app/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm/context/reducer';

import { postBulkEmailInstructorTask, patchScheduledBulkEmailInstructorTask } from './api';
import { AlertMessage, EditMessage } from './AlertTypes';
Expand Down
4 changes: 2 additions & 2 deletions src/components/bulk-email-tool/BulkEmailTool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Container } from '@openedx/paragon';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import BulkEmailTaskManager from './bulk-email-task-manager/BulkEmailTaskManager';
import NavigationTabs from '../navigation-tabs/NavigationTabs';
import BuildEmailFormExtensible from './bulk-email-form/BuildEmailFormExtensible';
import BulkEmailForm from './bulk-email-form/BulkEmailForm';
import { CourseMetadataContext } from '../page-container/PageContainer';
import { BulkEmailProvider } from './bulk-email-context';
import BackToInstructor from '../navigation-tabs/BackToInstructor';
Expand All @@ -34,7 +34,7 @@ export default function BulkEmailTool() {
</h1>
</div>
<div className="row">
<BuildEmailFormExtensible
<BulkEmailForm
courseId={courseId}
cohorts={courseMetadata.cohorts}
courseModes={courseMetadata.courseModes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useSelector, useDispatch, StateContext, DispatchContext,
} from '.';

describe('BuildEmailFormExtensible stateContext', () => {
describe('BulkEmailForm stateContext', () => {
test('useSelector returns the state', () => {
const { result } = renderHook(() => useSelector((state) => state));
expect(result.current).toEqual(INITIAL_STATE);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { reducer, actionCreators, INITIAL_STATE } from './reducer';

describe('BuildEmailFormExtensible reducer tests', () => {
describe('BulkEmailForm reducer tests', () => {
test('should update the form correctly', () => {
const state = reducer(INITIAL_STATE, actionCreators.updateForm({ emailId: 'example@email.com', newKey: 'test' }));
expect(state.form.emailId).toBe('example@email.com');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import PluggableComponent from '../../../PluggableComponent';
import { withContextProvider, useDispatch } from './context';
import { actionCreators as formActions } from './context/reducer';

const BuildEmailFormExtensible = ({ courseId, cohorts, courseModes }) => {
const BulkEmailForm = ({ courseId, cohorts, courseModes }) => {
const isMobile = useMobileResponsive();
const [{ editor }] = useContext(BulkEmailContext);
const [isTaskAlertOpen, openTaskAlert, closeTaskAlert] = useToggle(false);
Expand Down Expand Up @@ -103,12 +103,12 @@ const BuildEmailFormExtensible = ({ courseId, cohorts, courseModes }) => {
);
};

BuildEmailFormExtensible.defaultProps = {
BulkEmailForm.defaultProps = {
cohorts: [],
courseModes: [],
};

BuildEmailFormExtensible.propTypes = {
BulkEmailForm.propTypes = {
courseId: PropTypes.string.isRequired,
cohorts: PropTypes.arrayOf(PropTypes.string),
courseModes: PropTypes.arrayOf(
Expand All @@ -119,4 +119,4 @@ BuildEmailFormExtensible.propTypes = {
),
};

export default withContextProvider(BuildEmailFormExtensible);
export default withContextProvider(BulkEmailForm);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getConfig } from '@edx/frontend-platform';
import { BulkEmailProvider } from '../../bulk-email-context';
import cohortFactory from '../data/__factories__/bulkEmailFormCohort.factory';

import BuildEmailFormExtensible from '.';
import BulkEmailForm from '.';

// eslint-disable-next-line react/prop-types
jest.mock('../../text-editor/TextEditor', () => ({ value, onChange }) => (
Expand All @@ -30,7 +30,7 @@ jest.mock('@edx/frontend-platform', () => ({ getConfig: jest.fn() }));

getConfig.mockReturnValue({ LMS_BASE_URL: 'http://localhost', SCHEDULE_EMAIL_SECTION: true });

describe('BuildEmailFormExtensible', () => {
describe('BulkEmailForm', () => {
const { cohorts } = cohortFactory.build();

// eslint-disable-next-line react/prop-types
Expand All @@ -40,17 +40,17 @@ describe('BuildEmailFormExtensible', () => {
</IntlProvider>
);

const RenderBuildEmailFormExtensible = () => (
const RenderBulkEmailForm = () => (
<IntlProviderWrapper>
<BulkEmailProvider>
<BuildEmailFormExtensible courseId="test" cohorts={cohorts} />
<BulkEmailForm courseId="test" cohorts={cohorts} />
</BulkEmailProvider>
</IntlProviderWrapper>

);

test('renders the form and shows initial loading states', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(() => {
expect(screen.getByText('Send to')).toBeTruthy();
expect(screen.getByText('Subject')).toBeTruthy();
Expand All @@ -59,7 +59,7 @@ describe('BuildEmailFormExtensible', () => {
});
});
test('it shows a warning when clicking submit', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(async () => {
fireEvent.click(screen.getByText('Send email'));
const warning = await screen.findByText('CAUTION!', { exact: false });
Expand All @@ -68,7 +68,7 @@ describe('BuildEmailFormExtensible', () => {
});

test('Prevent form POST if invalid', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(async () => {
fireEvent.click(screen.getByText('Send email'));
expect(await screen.findByRole('button', { name: /continue/i })).toBeInTheDocument();
Expand All @@ -89,7 +89,7 @@ describe('BuildEmailFormExtensible', () => {
const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock.onPost(`${getConfig().LMS_BASE_URL}/courses/test/instructor/api/send_email`).reply(100);

render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);

await waitFor(async () => {
expect(screen.getByText('Send email')).toBeTruthy();
Expand All @@ -106,7 +106,7 @@ describe('BuildEmailFormExtensible', () => {
});

test('Checking "All Learners" disables each learner group', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(async () => {
fireEvent.click(screen.getByRole('checkbox', { name: 'All Learners' }));
const verifiedLearners = screen.getByRole('checkbox', { name: 'Learners in the verified certificate track' });
Expand All @@ -118,7 +118,7 @@ describe('BuildEmailFormExtensible', () => {
});

test('Shows scheduling form when checkbox is checked and submit is changed', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(async () => {
const scheduleCheckbox = screen.getByText('Schedule this email for a future date');
fireEvent.click(scheduleCheckbox);
Expand All @@ -129,7 +129,7 @@ describe('BuildEmailFormExtensible', () => {
});

test('Prevents sending email when scheduling inputs are empty', async () => {
render(<RenderBuildEmailFormExtensible />);
render(<RenderBulkEmailForm />);
await waitFor(async () => {
const scheduleCheckbox = screen.getByText('Schedule this email for a future date');
fireEvent.click(scheduleCheckbox);
Expand Down

0 comments on commit fccfd57

Please sign in to comment.