Skip to content

Commit

Permalink
feat(utils): Add tests for getRangesByDates
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Sep 26, 2024
1 parent 51c34e8 commit 8d72ff8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,15 @@ QUnit.module('Aria accessibility', {
expectedAriaLabel: `Calendar. The selected dates: ${getFormattedDate(1726938544957)}`,
},
{
value: [ 1726938544957, 1726852144957, 1726765744957 ],
expectedAriaLabel: `Calendar. The selected dates: from ${getFormattedDate(1726765744957)} to ${getFormattedDate(1726938544957)}`,
value: [ '2024-09-21T17:09:04', '2024-09-20T17:09:04', '2024-09-19T17:09:04' ],
expectedAriaLabel: `Calendar. The selected dates: from ${getFormattedDate('2024-09-19T17:09:04')} to ${getFormattedDate('2024-09-21T17:09:04')}`,
},
{
value: [ 1726938544957, 1726852144957, 1726765744957, 1727111344957, 1727197744957 ],
expectedAriaLabel: `Calendar. The selected dates: from ${getFormattedDate(1726765744957)} to ${getFormattedDate(1726938544957)}, from ${getFormattedDate(1727111344957)} to ${getFormattedDate(1727197744957)}`,
value: [ '2024-09-21T17:09:04', '2024-09-20T17:09:04', '2024-09-19T17:09:04', '2024-09-23T17:09:04', '2024-09-24T17:09:04', ],
expectedAriaLabel: `Calendar. The selected dates: from ${getFormattedDate('2024-09-19T17:09:04')} to ${getFormattedDate('2024-09-21T17:09:04')}, from ${getFormattedDate('2024-09-23T17:09:04')} to ${getFormattedDate('2024-09-24T17:09:04')}`,
},
{
value: [ 1726938544957, 1726852144957, 1726765744957, 1727111344957, 1727197744957, 1727434511000 ],
value: [ '2024-09-21T17:09:04', '2024-09-20T17:09:04', '2024-09-19T17:09:04', '2024-09-23T17:09:04', '2024-09-24T17:09:04', '2024-09-27T10:55:11' ],
expectedAriaLabel: 'Calendar. There are 3 selected date ranges',
},
].forEach(({ value, expectedAriaLabel }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@ const { test, module } = QUnit;
module('getRangesByDates', {}, () => {
test('getRangesByDates should generate correctly ranges', function(assert) {
const dates = [
new Date(1726765744957), // 19
new Date(1716745334957), // May 26 2024
'2024-11-27',
'2024-10-27T16:54:10',
1726765744957, // 19
1726852144957, // 20
1726938544957, // 21
1727111344957, // 23
1727197744957, // 24
1727434511000, // 27
'2024-09-26T18:28:10',
'2024-09-20T16:54:48',
'2024-09-21T18:54:21',
'2024-09-23T16:54:04',
'2024-09-24T02:54:12',
'2024-09-27T02:17:07',
'2024-09-26T18:28:11',
'2024-09-25T00:28:10',
];

assert.equal(result.v, 100, 'v value should be rounded');
const result = dateUtils.getRangesByDates(dates);
const expectedResult = [
[
new Date('2024-05-26T00:00:00'),
],
[
new Date('2024-09-20T00:00:00'),
new Date('2024-09-21T00:00:00'),
],
[
new Date('2024-09-23T00:00:00'),
new Date('2024-09-27T00:00:00'),
],
[
new Date('2024-10-27T00:00:00'),
],
[
new Date('2024-11-27T00:00:00'),
]
];

assert.deepEqual(result, expectedResult);
});
});

0 comments on commit 8d72ff8

Please sign in to comment.