From de480f285c74d27cf43b4371741a37a74942d174 Mon Sep 17 00:00:00 2001 From: ProCoderVP <98279986+noobCoderVP@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:51:53 +0530 Subject: [PATCH] fix: fixed failing testcases of build-dashboard.cy.js (#2739) Co-authored-by: Ansh Goyal --- cypress/test/scripts/dashboard/build-dashboard.cy.js | 10 +++++++--- scripts/dashboard/build-dashboard.js | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cypress/test/scripts/dashboard/build-dashboard.cy.js b/cypress/test/scripts/dashboard/build-dashboard.cy.js index cbcee3e09da..9b5487069bb 100644 --- a/cypress/test/scripts/dashboard/build-dashboard.cy.js +++ b/cypress/test/scripts/dashboard/build-dashboard.cy.js @@ -17,9 +17,13 @@ describe('getLabel function', () => { describe('monthsSince function', () => { // Define some sample dates and expected results const today = new Date(); - const oneMonthAgo = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); - const twoMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 2, today.getDate()); - const threeMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 3, today.getDate()); + + // number of miliseconds in a month + const month = 30 * 24 * 60 * 60 * 1000; + + const oneMonthAgo = today - month; + const twoMonthsAgo = today - 2 * month; + const threeMonthsAgo = today - 3 * month; // Write the test cases it('should return 0 for the same date', () => { diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 40146128876..49fbf8b5d4f 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -90,6 +90,7 @@ function getLabel(issue, filter) { function monthsSince(date) { const seconds = Math.floor((new Date() - new Date(date)) / 1000); + // 2592000 = number of seconds in a month = 30 * 24 * 60 * 60 const months = seconds / 2592000; return Math.floor(months); }