Skip to content

Commit

Permalink
test: refactor tests of toYearList
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Sen Ng (motss) <[email protected]>
  • Loading branch information
motss committed Jan 6, 2024
1 parent 0affbc5 commit 755e9c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
56 changes: 33 additions & 23 deletions src/__tests__/helpers/to-year-list.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import { expect } from '@open-wc/testing';
import { describe, expect, it } from 'vitest';

import { toYearList } from '../../helpers/to-year-list';
import { messageFormatter } from '../test-utils/message-formatter';

describe(toYearList.name, () => {
type CaseYearList = [
min: Date,
max: Date,
expected: number[]
];
const casesYearList: CaseYearList[] = [
[new Date('2020-02-02'), new Date('2020-02-01'), []],
[new Date('2020-02-02'), new Date('2020-02-02'), [2020]],
[new Date('2020-02-02'), new Date('2020-02-03'), [2020]],
[new Date('2019-02-02'), new Date('2020-02-02'), [2019, 2020]],
];
casesYearList.forEach((a) => {
const [testMin, testMax, expected] = a;
it.each<{
$_value: number[];
max: Date;
min: Date;
}>([
{
$_value: [],
max: new Date('2020-02-01'),
min: new Date('2020-02-02'),
},
{
$_value: [2020],
max: new Date('2020-02-02'),
min: new Date('2020-02-02'),
},
{
$_value: [2020],
max: new Date('2020-02-03'),
min: new Date('2020-02-02'),
},
{
$_value: [2019, 2020],
max: new Date('2020-02-02'),
min: new Date('2019-02-02'),
},
])('returns year list (min=$min, max=$max)', ({
$_value,
max,
min,
}) => {
const result = toYearList(min, max);

it(
messageFormatter('returns year list (min=%s, max=%s)', a),
() => {
const result = toYearList(testMin, testMax);

expect(result).deep.equal(expected);
}
);
expect(result).toEqual($_value);
});

});
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default defineConfig({
'**/*test*/helpers/to-next-selectable-date.test.ts',
'**/*test*/helpers/to-next-selected-date.test.ts',
'**/*test*/helpers/to-resolved-date.test.ts',
'**/*test*/helpers/to-year-list.test.ts',
// '**/*test*/date-picker-input/**.test.ts',
],
clearMocks: true,
Expand Down

0 comments on commit 755e9c7

Please sign in to comment.