Skip to content

Commit

Permalink
test(NcDateTime): Works with different languages
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Apr 22, 2024
1 parent 846ebea commit 4f57f6d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/unit/components/NcDateTime/NcDateTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('NcDateTime.vue', () => {
/**
* Use German locale as it uses a different date format than English
*/
it('', () => {
it('Works with absolute timestamps', () => {
const time = Date.UTC(2023, 5, 23, 14, 30)
jest.setSystemTime(time)
const wrapper = mount(NcDateTime, {
Expand All @@ -98,6 +98,31 @@ describe('NcDateTime.vue', () => {
})
})

describe('Work with different languages', () => {
beforeAll(() => {
// mock the language
document.documentElement.lang = 'de'
})
afterAll(() => {
// revert mock
document.documentElement.lang = 'en'
})

it('Works with relative timestamps', () => {
const now = Date.UTC(2023, 5, 24, 14, 0)
jest.setSystemTime(now)

const yesterday = Date.UTC(2023, 5, 23, 13, 59)
const wrapper = mount(NcDateTime, {
propsData: {
timestamp: yesterday,
},
})

expect(wrapper.text()).toMatch('gestern')
})
})

describe('Shows relative time', () => {
it('works with currentTime == timestamp', () => {
const time = Date.UTC(2023, 5, 23, 14, 30)
Expand Down

0 comments on commit 4f57f6d

Please sign in to comment.