From 9e26afc3da7e1f9386d13010ea5359b1f83cd7f3 Mon Sep 17 00:00:00 2001 From: FeL <33285268+FelixZilber@users.noreply.github.com> Date: Mon, 28 Jun 2021 09:35:50 +0300 Subject: [PATCH] feat: add isTimePassed function to TestUtils.ts (#234) --- src/commons/TestUtils.ts | 12 ++++++++++++ src/test/specs/TestUtilsSpec.ts | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/commons/TestUtils.ts b/src/commons/TestUtils.ts index 46dd33c71..9e47b01ec 100644 --- a/src/commons/TestUtils.ts +++ b/src/commons/TestUtils.ts @@ -31,6 +31,18 @@ export namespace TestUtils { return str.replace(/[^0-9]/g, ''); } + /** + * Check if number of minutes passed from given time till current time + * @param countDate date to count from + * @param numOfMinutes number of minutes to count + * @private + */ + export function isTimePassed(countDate: Date, numOfMinutes: number): boolean { + const timeInMs = numOfMinutes * 60 * 1000; /* ms */ + + return new Date().valueOf() - countDate.valueOf() > timeInMs; + } + /** * Return generic type of data by provided file path * path File located in wdio config file diff --git a/src/test/specs/TestUtilsSpec.ts b/src/test/specs/TestUtilsSpec.ts index 56904a034..ebed69249 100644 --- a/src/test/specs/TestUtilsSpec.ts +++ b/src/test/specs/TestUtilsSpec.ts @@ -30,4 +30,15 @@ describe('TestUtilsSpec', () => { assert.equal(Number(TestUtils.extractNumbersFromString(str)), expectedNumber); }); }); + describe('isTimePassed', () => { + it('expect to return true', () => { + const expectedDate = new Date(2000, 1); + assert.isTrue(TestUtils.isTimePassed(expectedDate, 5)); + }); + + it('expect to return false', () => { + const expectedDate = new Date(3000, 1); + assert.isNotTrue(TestUtils.isTimePassed(expectedDate, 5)); + }); + }); });