-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Localised date format based on the user's browser language. * Added jsdom as the jest environment. * Moved date related functions from main.js into date-helper.js. * Added tests for formatDate to make sure the date formatting is working correctly based on the user's browser language.
- Loading branch information
Showing
7 changed files
with
1,279 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { wrathDates } from "../__fixtures__/wotlk-dates.js"; | ||
import { formatDate, getWOTLKHolidays } from "../helpers/date-helper.js"; | ||
|
||
let languageGetter; | ||
|
||
beforeEach(() => { | ||
languageGetter = jest.spyOn(window.navigator, "language", "get"); | ||
}); | ||
|
||
it("should format the date correctly for British users", () => { | ||
languageGetter.mockReturnValue("en-GB"); | ||
const date = new Date(Date.UTC(2022, 9, 15, 0, 0, 0)); // 15/10/2022 | ||
|
||
const actual = formatDate(date); | ||
const expected = "15/10/2022"; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it("should format the date correctly for American users", () => { | ||
languageGetter.mockReturnValue("en-US"); | ||
const date = new Date(Date.UTC(2022, 9, 15, 0, 0, 0)); // 15/10/2022 | ||
|
||
const actual = formatDate(date); | ||
const expected = "10/15/2022"; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it("should contain the correct WOTLK dates for 2022", () => { | ||
const holidays = getWOTLKHolidays(2022); | ||
for (let i = 0; i < holidays.length; i++) { | ||
for (let j = 0; j < holidays[i].length; j++) { | ||
const firstKey = wrathDates[i][j].key; | ||
const secondKey = holidays[i][j].key; | ||
|
||
const firstDateStr = | ||
wrathDates[i][j].date === "" | ||
? wrathDates[i][j].date | ||
: wrathDates[i][j].date.toLocaleDateString(); | ||
const secondDateStr = | ||
holidays[i][j].date === "" | ||
? holidays[i][j].date | ||
: holidays[i][j].date.toLocaleDateString(); | ||
|
||
expect(firstKey).toEqual(secondKey); | ||
expect(firstDateStr).toEqual(secondDateStr); | ||
} | ||
} | ||
}); |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"testEnvironment": "jsdom" | ||
} |
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
Oops, something went wrong.