From 8d72ff874e566e7d99caf098d603e641d1b3ec6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marker=20dao=20=C2=AE?= Date: Thu, 26 Sep 2024 19:20:03 +0200 Subject: [PATCH] feat(utils): Add tests for getRangesByDates --- .../calendar.markup.tests.js | 10 ++--- .../DevExpress.utils/utils.date.tests.js | 38 ++++++++++++++----- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.markup.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.markup.tests.js index 75b417c106be..7c06483a693f 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.markup.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.markup.tests.js @@ -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 }) => { diff --git a/packages/devextreme/testing/tests/DevExpress.utils/utils.date.tests.js b/packages/devextreme/testing/tests/DevExpress.utils/utils.date.tests.js index b320e0d0cb9d..1ecc99117e2d 100644 --- a/packages/devextreme/testing/tests/DevExpress.utils/utils.date.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.utils/utils.date.tests.js @@ -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); }); });