Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit d177422

Browse files
committed
test: Improve and refactor test cases
1 parent f9b1e0d commit d177422

File tree

10 files changed

+158
-428
lines changed

10 files changed

+158
-428
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ module.exports = {
2626
'no-unused-vars': 'off',
2727
'@typescript-eslint/no-unused-vars': 'error',
2828
},
29+
overrides: [
30+
{
31+
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
32+
env: {
33+
jest: true,
34+
},
35+
},
36+
],
2937
};

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
transform: {
44
'^.+\\.vue$': 'vue-jest',
55
},
6+
setupFiles: ['./tests/setup.ts'],
67
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
2626
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife",
2727
"build:css": "cross-env NODE_ENV=production sass src/Vue3DatePicker/style/main.scss dist/main.css --style compressed",
28-
"test": "vue-cli-service test:unit"
28+
"test": "cross-env NODE_ENV=test vue-cli-service test:unit"
2929
},
3030
"devDependencies": {
3131
"@babel/core": "^7.15.8",

tests/setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Just in case some test fail, to exit test, otherwise it will report as passed
2+
process.on('unhandledRejection', (err) => {
3+
fail(err);
4+
});

tests/unit/calendars.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('Calendar component', () => {
2+
it('', () => {
3+
console.log('to be added');
4+
});
5+
});

tests/unit/format.spec.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/unit/props.spec.ts

Lines changed: 0 additions & 190 deletions
This file was deleted.

tests/unit/utils.spec.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import {
2+
getArrayInArray,
3+
getCalendarDays,
4+
getDayNames,
5+
getMonths,
6+
getYears,
7+
} from '../../src/Vue3DatePicker/utils/util';
8+
import {
9+
getDefaultPattern,
10+
parseFreeInput,
11+
resetDateTime,
12+
setDateTime,
13+
} from '../../src/Vue3DatePicker/utils/date-utils';
14+
15+
describe('Utils and date utils formatting', () => {
16+
it('Should get calendar days', () => {
17+
const days = getCalendarDays(0, 2021, 1, false);
18+
19+
expect(days).toHaveLength(5);
20+
expect(days[0].days).toHaveLength(7);
21+
expect(days[0].days[0].text).toEqual(28);
22+
});
23+
24+
it('Should get calendar days starting from sunday', () => {
25+
const days = getCalendarDays(0, 2021, 0, false);
26+
expect(days).toHaveLength(6);
27+
expect(days[0].days[0].text).toEqual(27);
28+
});
29+
30+
it('Should get calendar days with hidden offset dats', () => {
31+
const days = getCalendarDays(0, 2021, 1, true);
32+
33+
expect(days).toHaveLength(5);
34+
expect(days[0].days[0].text).toEqual('');
35+
});
36+
37+
it('Should group array by 3', () => {
38+
const items = getArrayInArray(Array.from(Array(10).keys()));
39+
40+
expect(items).toHaveLength(4);
41+
expect(items[0]).toHaveLength(3);
42+
});
43+
44+
it('Should get day names', () => {
45+
const days = getDayNames('de', 1);
46+
47+
expect(days).toHaveLength(7);
48+
expect(days[1]).toEqual('Di');
49+
});
50+
51+
it('Should generate years', () => {
52+
const years = getYears([2021, 2025]);
53+
54+
expect(years).toHaveLength(5);
55+
expect(years[1].value).toEqual(2022);
56+
});
57+
58+
it('Should get month values', () => {
59+
const months = getMonths('en', 'long');
60+
61+
expect(months).toHaveLength(12);
62+
expect(months[0].text).toEqual('January');
63+
});
64+
65+
it('Should get default pattern', () => {
66+
const patternDef = getDefaultPattern(null, true, false, false, true);
67+
const patternMonthPicker = getDefaultPattern(null, true, true, false, false);
68+
69+
expect(patternDef).toEqual('MM/dd/yyyy, HH:mm');
70+
expect(patternMonthPicker).toEqual('MM/yyyy');
71+
});
72+
73+
it('Should parse free input', () => {
74+
const date = parseFreeInput('01/01/2021', 'MM/dd/yyyy, HH:mm');
75+
76+
expect(date).toBeDefined();
77+
expect(date?.getMonth()).toEqual(0);
78+
});
79+
80+
it('Should reset date time', () => {
81+
const date = new Date();
82+
const resetDate = resetDateTime(date);
83+
84+
expect(resetDate.getHours()).toEqual(0);
85+
expect(resetDate.getMinutes()).toEqual(0);
86+
expect(resetDate.getSeconds()).toEqual(0);
87+
expect(resetDate.getMilliseconds()).toEqual(0);
88+
});
89+
90+
it('Should set date time', () => {
91+
const date = setDateTime(new Date(), 12, 12);
92+
93+
expect(date.getHours()).toEqual(12);
94+
expect(date.getMinutes()).toEqual(12);
95+
});
96+
});

0 commit comments

Comments
 (0)