Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Dissolution Date bug #577

Merged
merged 9 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(0, 0, 0)
return (date >= minDate) && (date <= maxDate)
Copy link
Collaborator Author

@JazzarKarim JazzarKarim Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bit of weird behavior here. When selecting the date as same as registration date, the error (rule) was being shown:
rule is shown

Apparently, the issue is with the hour:
weird dates
The first line is the date while the second one is the minDate. Hence, the rule is being triggered (date < minDate).

Setting the hour to be the same (00:00:00) fixes this issue.

Copy link
Collaborator

@severinbeauvais severinbeauvais Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is indeed the root cause 👍

What do you think about fixing maxDate similarly (and also isNotBeforeDate() and isNotAfterDate()) ? fixed, thanks!

},
/** 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(0, 0, 0)
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
17 changes: 17 additions & 0 deletions tests/unit/DissolutionFirm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,22 @@ 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.setCurrentJsDate(new Date('2022-06-14T12:00:00.000Z'))

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 (after registration date and not in the future)
expect(rules[1]('June 7, 2022')).toBe(true)
})
})
}