-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASSB-1444] Fix error on first render
- Don't try to render a deadline without a date set - Use formatDate so that invalid dates don't cause a render error - Update copy to singular/plural variants
- Loading branch information
1 parent
7ffd92a
commit 944da7a
Showing
6 changed files
with
141 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { shallow, render } from 'enzyme'; | ||
import React from 'react'; | ||
import ConditionReminders from './index'; | ||
import {describe, expect, test} from '@jest/globals' | ||
import {v4 as uuid} from 'uuid' | ||
|
||
function reminderWithDeadline(deadline) { | ||
return { | ||
id: uuid(), | ||
deadline | ||
} | ||
} | ||
|
||
describe('ConditionReminders component', () => { | ||
test('Empty reminders should render nothing', () => { | ||
for (const reminders of [null, []]) { | ||
const wrapper = shallow(<ConditionReminders reminders={reminders}/>); | ||
expect(wrapper.isEmptyRender()).toBe(true); | ||
} | ||
}) | ||
|
||
test('Reminders without a deadline should be ignored', () => { | ||
const reminders = [{id: uuid()}] | ||
const wrapper = shallow(<ConditionReminders reminders={reminders}/>); | ||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}) | ||
|
||
test('When there is one reminder the copy should be singular', () => { | ||
const reminders = [reminderWithDeadline("2025-01-01")] | ||
const wrapper = render(<ConditionReminders reminders={reminders}/>); | ||
expect(wrapper.text()) | ||
.toContain( | ||
"A deadline and automated reminders have been set for this condition" | ||
); | ||
expect(wrapper.text()) | ||
.toContain("This condition has a deadline set for:"); | ||
expect(wrapper.text()) | ||
.toContain( | ||
"Licence holders will receive reminders 1 month before," + | ||
" 1 week before and on the deadline date. ASRU will receive a reminder" + | ||
" when the deadline has passed." | ||
); | ||
}) | ||
|
||
test('When there are two reminders the copy should be plural', () => { | ||
const reminders = [ | ||
reminderWithDeadline("2025-01-01"), | ||
reminderWithDeadline("2025-02-02") | ||
] | ||
const wrapper = render(<ConditionReminders reminders={reminders}/>); | ||
expect(wrapper.text()) | ||
.toContain( | ||
"Deadlines and automated reminders have been set for this condition" | ||
); | ||
expect(wrapper.text()) | ||
.toContain("This condition has deadlines set for:"); | ||
expect(wrapper.text()) | ||
.toContain( | ||
"Licence holders will receive reminders 1 month before, " + | ||
"1 week before and on each deadline date. ASRU will receive reminders " + | ||
"when each deadline has passed." | ||
); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { formatDate, DATE_FORMAT } = require('./utils'); | ||
|
||
describe('formatDate', () => { | ||
test('formats a valid date', () => { | ||
expect(formatDate('2024-01-01', DATE_FORMAT.short)).toBe('1/1/2024'); | ||
}); | ||
|
||
test('returns "-" for empty dates', () => { | ||
expect(formatDate(null, DATE_FORMAT.short)).toBe('-'); | ||
expect(formatDate(undefined, DATE_FORMAT.short)).toBe('-'); | ||
expect(formatDate('', DATE_FORMAT.short)).toBe('-'); | ||
}); | ||
|
||
test('returns "Invalid date entered" for invlaid dates', () => { | ||
expect(formatDate('not a date', DATE_FORMAT.short)).toBe('Invalid date entered'); | ||
expect(formatDate('24-01-01', DATE_FORMAT.short)).toBe('Invalid date entered'); | ||
}); | ||
}); |