Compare commits

...
Author SHA1 Message Date
Bartłomiej Głownia 979614ccfb feat(deal-ticket): fix flaky test 2023-08-31 14:21:06 +02:00
3 changed files with 7 additions and 6 deletions
@@ -432,9 +432,9 @@ describe('StopOrder', () => {
}); });
it('sets expiry time/date to now if expiry is changed to checked', async () => { 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()); render(generateJsx());
jest.spyOn(global.Date, 'now').mockImplementationOnce(() => now); jest.spyOn(global.Date, 'now').mockImplementation(() => now);
await userEvent.click(screen.getByTestId(expire)); await userEvent.click(screen.getByTestId(expire));
// expiry time/date was empty it should be set to now // expiry time/date was empty it should be set to now
@@ -590,9 +590,9 @@ describe('DealTicket', () => {
it('sets expiry time/date to now if expiry is changed to checked', async () => { it('sets expiry time/date to now if expiry is changed to checked', async () => {
const datePicker = 'date-picker-field'; const datePicker = 'date-picker-field';
const now = Math.round(Date.now() / 1000) * 1000; const now = 24 * 60 * 60 * 1000;
render(generateJsx()); render(generateJsx());
jest.spyOn(global.Date, 'now').mockImplementationOnce(() => now); jest.spyOn(global.Date, 'now').mockImplementation(() => now);
await userEvent.selectOptions( await userEvent.selectOptions(
screen.getByTestId('order-tif'), screen.getByTestId('order-tif'),
Schema.OrderTimeInForce.TIME_IN_FORCE_GTT Schema.OrderTimeInForce.TIME_IN_FORCE_GTT
@@ -496,11 +496,12 @@ export const DealTicket = ({
onSelect={(value) => { onSelect={(value) => {
// If GTT is selected and no expiresAt time is set, or its // If GTT is selected and no expiresAt time is set, or its
// behind current time then reset the value to current time // behind current time then reset the value to current time
const now = Date.now();
if ( if (
value === Schema.OrderTimeInForce.TIME_IN_FORCE_GTT && 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, shouldValidate: true,
}); });
} }