Skip to content

Commit

Permalink
Merge pull request #552 from nextcloud/feat/code-cov-datets
Browse files Browse the repository at this point in the history
Add missing test cases for `date.ts`
  • Loading branch information
ChristophWurst committed Jan 10, 2023
2 parents 520ffe2 + 4509f0e commit 46e95a3
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 32 deletions.
35 changes: 28 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
},
"devDependencies": {
"@nextcloud/browserslist-config": "^2.3.0",
"@nextcloud/typings": "^1.0.0",
"@nextcloud/typings": "^1.6.0",
"@rollup/plugin-typescript": "^11.0.0",
"@types/jest": "^29.2.5",
"@types/node-gettext": "^3.0",
"@zamiell/typedoc-plugin-not-exported": "^0.2.0",
"check-es-compat": "^2.2.0",
Expand Down
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 46e95a3

Please sign in to comment.