Skip to content

Commit

Permalink
Fixed Dissolution Date bug (#577)
Browse files Browse the repository at this point in the history
* Fixed dissolution date bug

* Updated in response to Sev's comments + added unit tests

* Fixed unit test

* fixed unit test running locally but not with github ci

* Added test case + fixed test

* Added another test case

* another small fix

* trying something out

* Added a test line
  • Loading branch information
JazzarKarim authored Oct 18, 2023
1 parent 334ed48 commit 44bf324
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-create-ui",
"version": "5.5.6",
"version": "5.5.7",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
4 changes: 4 additions & 0 deletions src/rules/date-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ export const DateRuleHelpers = {
isBetweenDates (minDate: Date, maxDate: Date, dateStrToValidate: string): boolean {
if (!dateStrToValidate) return true
const date = new Date(dateStrToValidate) // eg, September 5, 2022
minDate.setHours(0, 0, 0) // Removing the hour to properly compare in case selected date was same as minimum.
maxDate.setHours(23, 59, 59)
return (date >= minDate) && (date <= maxDate)
},
/** Whether date string to validate is not before min date. */
isNotBeforeDate (minDate: Date, dateStrToValidate: string): boolean {
if (!dateStrToValidate) return true
const date = new Date(dateStrToValidate) // eg, September 5, 2022
minDate.setHours(0, 0, 0)
return (date >= minDate)
},
/** Whether date string to validate is not after max date. */
isNotAfterDate (maxDate: Date, dateStrToValidate: string): boolean {
if (!dateStrToValidate) return true
const date = new Date(dateStrToValidate) // eg, September 5, 2022
maxDate.setHours(23, 59, 59)
return (date <= maxDate)
}
}
4 changes: 2 additions & 2 deletions src/views/DissolutionFirm/DissolutionFirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<h2>Business Dissolution Date</h2>
<p class="mt-4 ">
Enter the dissolution date of the business.
The dissolution date must be after the business start date and registration date.
The dissolution date must be on or after the registration date.
The dissolution date cannot be in the future.
</p>
</header>
Expand Down Expand Up @@ -469,7 +469,7 @@ export default class DissolutionFirm extends Mixins(DateMixin) {
/** The minimum start date that can be entered (greater than registration date). */
get startDateMin (): Date {
const date = this.apiToDate(this.getBusinessFoundingDate)
date.setDate(date.getDate() + 1)
date.setDate(date.getDate())
return date
}
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/DissolutionFirm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,28 @@ for (const test of dissolutionFirmTestCases) {
expect(errorMessages.at(0).text()).toBe('Cannot exceed 20 characters')
expect(errorMessages.at(1).text()).toBe('Cannot exceed 20 characters')
})

it('display correct date rules', async () => {
wrapper = mount(
DissolutionFirm,
{ vuetify }
)
const rules = wrapper.vm.startDateRules
store.stateModel.business.foundingDate = '2022-06-06T23:59:59.000+00:00'
store.setCurrentJsDate(new Date('2022-06-14T00:00:00.000'))

expect(rules[0]('')).toBe('Dissolution date is required') // no date is selected
expect(rules[0]('October 16, 2023')).toBe(true) // date is selected
// A date before the registration date is selected (invalid)
expect(rules[1]('June 5, 2022')).toContain('Dissolution Date must be after June 6, 2022 and up to')
expect(rules[1]('June 5, 2022')).toContain('June 14, 2022')
// A valid date is selected (on registration date)
expect(rules[1]('June 6, 2022')).toBe(true)
// A valid date is selected (after registration date and not in the future)
expect(rules[1]('June 7, 2022')).toBe(true)
// An invalid date is selected (in the future)
expect(rules[1]('September 7, 2022')).toContain('Dissolution Date must be after June 6, 2022 and up to')
expect(rules[1]('September 7, 2022')).toContain('June 14, 2022')
})
})
}

0 comments on commit 44bf324

Please sign in to comment.