-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #68 date time settings per note overview
- Loading branch information
Showing
8 changed files
with
212 additions
and
7 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
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,3 @@ | ||
datetime: | ||
date: "DD/MM/YYYY" | ||
time: "" |
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,5 @@ | ||
datetime: | ||
date: "DD/MM/YYYY" | ||
time: "HH:mm" | ||
humanize: | ||
enabled: true |
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,6 @@ | ||
datetime: | ||
date: "DD/MM/YYYY" | ||
time: "HH:mm" | ||
humanize: | ||
enabled: true | ||
withSuffix: false |
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,102 @@ | ||
import { noteoverview, logging } from "../src/noteoverview"; | ||
import { getOptionsFromFile } from "./tools"; | ||
|
||
describe("Datetime function", function () { | ||
beforeEach(async () => { | ||
jest.spyOn(logging, "silly").mockImplementation(() => {}); | ||
jest.spyOn(logging, "verbose").mockImplementation(() => {}); | ||
jest.spyOn(logging, "info").mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(async () => { | ||
jest.spyOn(logging, "silly").mockReset(); | ||
jest.spyOn(logging, "verbose").mockReset(); | ||
jest.spyOn(logging, "info").mockReset(); | ||
}); | ||
|
||
it(`empty time format`, async () => { | ||
const options = getOptionsFromFile("datetime"); | ||
const optionsObject = await noteoverview.getOptions(options); | ||
|
||
const dateFormat = "DD/MM/YYYY"; | ||
const timeFormat = ""; | ||
|
||
const testDate = new Date(); | ||
const epoch = testDate.getTime(); | ||
const expectedDatetimeFormated = await noteoverview.getDateFormated( | ||
epoch, | ||
dateFormat, | ||
timeFormat | ||
); | ||
|
||
const fields = { | ||
todo_due: epoch, | ||
}; | ||
const result = await noteoverview.getFieldValue( | ||
"todo_due", | ||
fields, | ||
optionsObject | ||
); | ||
expect(result).toBe(`${expectedDatetimeFormated}`); | ||
}); | ||
|
||
it(`humanize format`, async () => { | ||
const options = getOptionsFromFile("datetime_humanize"); | ||
const optionsObject = await noteoverview.getOptions(options); | ||
|
||
const dateFormat = "DD/MM/YYYY"; | ||
const timeFormat = "HH:mm"; | ||
|
||
const testDate = new Date(); | ||
testDate.setDate(new Date().getDate() + 1); | ||
const epochTomorrow = testDate.getTime(); | ||
const expectedDatetimeFormated = await noteoverview.getDateFormated( | ||
epochTomorrow, | ||
dateFormat, | ||
timeFormat | ||
); | ||
|
||
const fields = { | ||
todo_due: epochTomorrow, | ||
}; | ||
const result = await noteoverview.getFieldValue( | ||
"todo_due", | ||
fields, | ||
optionsObject | ||
); | ||
|
||
expect(result).toBe( | ||
`<font title=\"${expectedDatetimeFormated}\">in a day</font>` | ||
); | ||
}); | ||
|
||
it(`humanize without suffix format`, async () => { | ||
const options = getOptionsFromFile("datetime_humanize_withoutSuffix"); | ||
const optionsObject = await noteoverview.getOptions(options); | ||
|
||
const dateFormat = "DD/MM/YYYY"; | ||
const timeFormat = "HH:mm"; | ||
|
||
const testDate = new Date(); | ||
testDate.setDate(new Date().getDate() + 1); | ||
const epochTomorrow = testDate.getTime(); | ||
const expectedDatetimeFormated = await noteoverview.getDateFormated( | ||
epochTomorrow, | ||
dateFormat, | ||
timeFormat | ||
); | ||
|
||
const fields = { | ||
todo_due: epochTomorrow, | ||
}; | ||
const result = await noteoverview.getFieldValue( | ||
"todo_due", | ||
fields, | ||
optionsObject | ||
); | ||
|
||
expect(result).toBe( | ||
`<font title=\"${expectedDatetimeFormated}\">a day</font>` | ||
); | ||
}); | ||
}); |
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