-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from itenium-be/project-extension
Addition of date validations
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
frontend/src/components/controls/other/ProjectValidator.ts
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,11 @@ | ||
import {Moment} from "moment"; | ||
|
||
export const isDateIntervalValid = (startDate: Moment, endDate: Moment | undefined):boolean => { | ||
return startDate.diff(endDate) < 0; | ||
}; | ||
|
||
export const isProjectValid = (startDate: Moment, endDate: Moment | undefined, previousProjectEndDate: Moment):boolean =>{ | ||
const intervalValid = isDateIntervalValid(startDate, endDate) | ||
const projectValid = isDateIntervalValid(previousProjectEndDate, startDate) | ||
return intervalValid && projectValid | ||
} |
74 changes: 74 additions & 0 deletions
74
frontend/src/components/controls/spec/ProjectValidator.spec.ts
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,74 @@ | ||
import moment from "moment" | ||
import { isDateIntervalValid, isProjectValid } from "../other/ProjectValidator" | ||
|
||
describe('ProjectValidator is date inteval valid', () => { | ||
it('Should return true if start date is smaller then end date', () => { | ||
const startDate = moment('2024-01-01') | ||
const endDate = moment('2024-01-31') | ||
|
||
const res = isDateIntervalValid(startDate, endDate) | ||
|
||
expect(res).toBeTruthy() | ||
}) | ||
|
||
it('Should return true if end date is undefined', () => { | ||
const startDate = moment('2024-01-01') | ||
const endDate = undefined | ||
|
||
const res = isDateIntervalValid(startDate, endDate) | ||
|
||
expect(res).toBeTruthy() | ||
}) | ||
|
||
it('Should return false if start date is bigger then end date', () => { | ||
const startDate = moment('2024-02-01') | ||
const endDate = moment('2024-01-31') | ||
|
||
const res = isDateIntervalValid(startDate, endDate) | ||
|
||
expect(res).toBeFalsy() | ||
}) | ||
}) | ||
|
||
|
||
describe('ProjectValidator is project valid', () => { | ||
it('Should return true if previous end date is smaller then new start date and end date is undefined', () => { | ||
const startDate = moment('2024-01-01') | ||
const endDate = undefined | ||
const previousProjectEndDate = moment('2023-12-31') | ||
|
||
const res = isProjectValid(startDate, endDate, previousProjectEndDate) | ||
|
||
expect(res).toBeTruthy() | ||
}) | ||
|
||
it('Should return true if previous end date is smaller then new start date and new end date is bigger then new start date', () => { | ||
const startDate = moment('2024-01-01') | ||
const endDate = moment('2024-01-31') | ||
const previousProjectEndDate = moment('2023-12-31') | ||
|
||
const res = isProjectValid(startDate, endDate, previousProjectEndDate) | ||
|
||
expect(res).toBeTruthy() | ||
}) | ||
|
||
it('Should return false if previous end date is bigger then new start date and new end date is undefined', () => { | ||
const startDate = moment('2024-12-31') | ||
const endDate = undefined | ||
const previousProjectEndDate = moment('2023-01-01') | ||
|
||
const res = isProjectValid(startDate, endDate, previousProjectEndDate) | ||
|
||
expect(res).toBeFalsy() | ||
}) | ||
|
||
it('Should return false if new start date is bigger then new end date', () => { | ||
const startDate = moment('2024-01-02') | ||
const endDate = moment('2023-01-01') | ||
const previousProjectEndDate = moment('2023-01-01') | ||
|
||
const res = isProjectValid(startDate, endDate, previousProjectEndDate) | ||
|
||
expect(res).toBeFalsy() | ||
}) | ||
}) |
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