Skip to content

Commit

Permalink
feat(tests): Add missing test cases for date.ts
Browse files Browse the repository at this point in the history
This increases the code coverage of `date.ts` to 100%.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux committed Jan 10, 2023
1 parent 2574c4f commit 4509f0e
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 24 deletions.
111 changes: 111 additions & 0 deletions tests/date.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/// <reference types="@nextcloud/typings" />
declare var window: Nextcloud.v24.WindowWithGlobals

import { getDayNames, getDayNamesMin, getDayNamesShort, getFirstDay, getMonthNames, getMonthNamesShort } from '../lib/date'

describe('date', () => {
const orginalWarn = console.warn

afterAll(() => {
console.warn = orginalWarn
})
beforeEach(() => {
console.warn = jest.fn()
})

describe('getFirstDay', () => {
// @ts-ignore
afterAll(() => { delete window.firstDay })

it('works without `OC`', () => {
expect(getFirstDay()).toBe(1)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.firstDay = 3
expect(getFirstDay()).toBe(3)
})
})

describe('getDayNames', () => {
// @ts-ignore
afterAll(() => { delete window.dayNames })

it('works without `OC`', () => {
expect(getDayNames().length).toBe(7)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.dayNames = 'a'.repeat(7).split('')
expect(getDayNames()).toBe(window.dayNames)
})
})

describe('getDayNamesShort', () => {
// @ts-ignore
afterAll(() => { delete window.dayNamesShort })

it('works without `OC`', () => {
expect(getDayNamesShort().length).toBe(7)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.dayNamesShort = 'b'.repeat(7).split('')
expect(getDayNamesShort()).toBe(window.dayNamesShort)
})
})

describe('getDayNamesMin', () => {
// @ts-ignore
afterAll(() => { delete window.dayNamesMin })

it('works without `OC`', () => {
expect(getDayNamesMin().length).toBe(7)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.dayNamesMin = 'c'.repeat(7).split('')
expect(getDayNamesMin()).toBe(window.dayNamesMin)
})
})

describe('getMonthNames', () => {
// @ts-ignore
afterAll(() => { delete window.monthNames })

it('works without `OC`', () => {
expect(getMonthNames().length).toBe(12)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.monthNames = 'd'.repeat(12).split('')
expect(getMonthNames()).toBe(window.monthNames)
})
})

describe('getMonthNamesShort', () => {
// @ts-ignore
afterAll(() => { delete window.monthNamesShort })

it('works without `OC`', () => {
expect(getMonthNamesShort().length).toBe(12)
// Warning as fallback is being used
expect(console.warn).toBeCalled()
})

it('works with `OC`', () => {
window.monthNamesShort = 'e'.repeat(12).split('')
expect(getMonthNamesShort()).toBe(window.monthNamesShort)
})
})
})
24 changes: 0 additions & 24 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,3 @@ describe('getCanonicalLocale', () => {
expect(getCanonicalLocale()).toEqual('de-DE')
})
})

test('getFirstDay', () => {
expect(getFirstDay()).toBe(1)
})

test('getDayNames', () => {
expect(getDayNames().length).toBe(7)
})

test('getDayNamesShort', () => {
expect(getDayNamesShort().length).toBe(7)
})

test('getDayNamesMin', () => {
expect(getDayNamesMin().length).toBe(7)
})

test('getMonthNames', () => {
expect(getMonthNames().length).toBe(12)
})

test('getMonthNamesShort', () => {
expect(getMonthNamesShort().length).toBe(12)
})

0 comments on commit 4509f0e

Please sign in to comment.