From 255c3752f29ebe6e1c7cc5253959f1e52136da64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Thu, 31 Aug 2023 19:41:58 +0200 Subject: [PATCH] feat(deal-ticket): fix flaky tests (#4667) --- .../components/deal-ticket/deal-ticket-stop-order.spec.tsx | 4 ++-- .../src/components/deal-ticket/deal-ticket.spec.tsx | 4 ++-- libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx index ce1762733..c15023da1 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-stop-order.spec.tsx @@ -432,9 +432,9 @@ describe('StopOrder', () => { }); it('sets expiry time/date to now if expiry is changed to checked', async () => { - const now = Math.round(Date.now() / 1000) * 1000; + const now = 24 * 60 * 60 * 1000; render(generateJsx()); - jest.spyOn(global.Date, 'now').mockImplementationOnce(() => now); + jest.spyOn(global.Date, 'now').mockImplementation(() => now); await userEvent.click(screen.getByTestId(expire)); // expiry time/date was empty it should be set to now diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx index 8de33126a..5008c2b59 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx @@ -590,9 +590,9 @@ describe('DealTicket', () => { it('sets expiry time/date to now if expiry is changed to checked', async () => { const datePicker = 'date-picker-field'; - const now = Math.round(Date.now() / 1000) * 1000; + const now = 24 * 60 * 60 * 1000; render(generateJsx()); - jest.spyOn(global.Date, 'now').mockImplementationOnce(() => now); + jest.spyOn(global.Date, 'now').mockImplementation(() => now); await userEvent.selectOptions( screen.getByTestId('order-tif'), Schema.OrderTimeInForce.TIME_IN_FORCE_GTT diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx index 7ec2eba85..373f04a12 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx @@ -496,11 +496,12 @@ export const DealTicket = ({ onSelect={(value) => { // If GTT is selected and no expiresAt time is set, or its // behind current time then reset the value to current time + const now = Date.now(); if ( value === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT && - (!expiresAt || new Date(expiresAt).getTime() < Date.now()) + (!expiresAt || new Date(expiresAt).getTime() < now) ) { - setValue('expiresAt', formatForInput(new Date()), { + setValue('expiresAt', formatForInput(new Date(now)), { shouldValidate: true, }); }