From c905ede6fec9fbd5ffdf47a0deab9c7435abd61a Mon Sep 17 00:00:00 2001 From: Maxwell Frank Date: Tue, 2 Aug 2022 19:57:32 +0000 Subject: [PATCH] fix: cohorts disabled when 'all learners' is selected --- .../bulk-email-form/BulkEmailForm.jsx | 8 ++++++++ .../bulk-email-recipient/BulkEmailRecipient.jsx | 2 +- .../__factories__/bulkEmailFormCohort.factory.js | 7 +++++++ .../bulk-email-form/test/BulkEmailForm.test.jsx | 14 +++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/components/bulk-email-tool/bulk-email-form/data/__factories__/bulkEmailFormCohort.factory.js diff --git a/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm.jsx b/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm.jsx index 8817335..bc0e532 100644 --- a/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm.jsx +++ b/src/components/bulk-email-tool/bulk-email-form/BulkEmailForm.jsx @@ -122,6 +122,14 @@ function BulkEmailForm(props) { const onRecipientChange = (event) => { if (event.target.checked) { dispatch(addRecipient(event.target.value)); + // if "All Learners" is checked then we want to remove any cohorts, verified learners, and audit learners + if (event.target.value === 'learners') { + editor.emailRecipients.forEach(recipient => { + if (/^cohort/.test(recipient) || /^track/.test(recipient)) { + dispatch(removeRecipient(recipient)); + } + }); + } } else { dispatch(removeRecipient(event.target.value)); } diff --git a/src/components/bulk-email-tool/bulk-email-form/bulk-email-recipient/BulkEmailRecipient.jsx b/src/components/bulk-email-tool/bulk-email-form/bulk-email-recipient/BulkEmailRecipient.jsx index c58172a..2bafefc 100644 --- a/src/components/bulk-email-tool/bulk-email-form/bulk-email-recipient/BulkEmailRecipient.jsx +++ b/src/components/bulk-email-tool/bulk-email-form/bulk-email-recipient/BulkEmailRecipient.jsx @@ -69,6 +69,7 @@ export default function BulkEmailRecipient(props) { group === DEFAULT_GROUPS.ALL_LEARNERS)} className="col col-lg-4 col-sm-6 col-12" > group === (DEFAULT_GROUPS.AUDIT || DEFAULT_GROUPS.VERIFIED))} className="col col-lg-4 col-sm-6 col-12" > - + ); } @@ -91,6 +93,16 @@ describe('bulk-email-form', () => { fireEvent.click(await screen.findByRole('button', { name: /continue/i })); expect(await screen.findByText('An error occured while attempting to send the email.')).toBeInTheDocument(); }); + test('Checking "All Learners" disables each learner group', async () => { + render(renderBulkEmailForm()); + fireEvent.click(screen.getByRole('checkbox', { name: 'All Learners' })); + const verifiedLearners = screen.getByRole('checkbox', { name: 'Learners in the verified certificate track' }); + const auditLearners = screen.getByRole('checkbox', { name: 'Learners in the audit track' }); + const { cohorts } = cohortFactory.build(); + cohorts.forEach(cohort => expect(screen.getByRole('checkbox', { name: `Cohort: ${cohort}` })).toBeDisabled()); + expect(verifiedLearners).toBeDisabled(); + expect(auditLearners).toBeDisabled(); + }); test('Shows scheduling form when checkbox is checked and submit is changed', async () => { render(renderBulkEmailForm()); const scheduleCheckbox = screen.getByText('Schedule this email for a future date');