From bbbb79306a01156a32d70d5fcb8cd6474ef15655 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Thu, 23 Jul 2020 15:59:31 +0200 Subject: [PATCH] refactor: Use sleep from utils --- src/components/ModalStack.jsx | 3 +-- src/ducks/client/checks.js | 3 +-- src/ducks/client/checks.spec.js | 3 +-- src/utils/effects.js | 5 +---- test/e2e/alerts/alerts.e2e.spec.js | 3 +-- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/components/ModalStack.jsx b/src/components/ModalStack.jsx index 65ca8e6fd5..550c415385 100644 --- a/src/components/ModalStack.jsx +++ b/src/components/ModalStack.jsx @@ -7,8 +7,7 @@ import React, { useState } from 'react' import Modal from 'cozy-ui/transpiled/react/Modal' import { ViewStackContext } from 'cozy-ui/transpiled/react' - -const sleep = duration => new Promise(resolve => setTimeout(resolve, duration)) +import sleep from 'utils/sleep' // Same as in cozy-ui const useStack = (initialState, options = {}) => { diff --git a/src/ducks/client/checks.js b/src/ducks/client/checks.js index df44719fa6..675c18cd6b 100644 --- a/src/ducks/client/checks.js +++ b/src/ducks/client/checks.js @@ -1,8 +1,7 @@ import matches from 'lodash/matches' import { triggerStates } from 'cozy-client/dist/models/trigger' import { triggersConn } from 'doctypes' - -const sleep = delay => new Promise(resolve => setTimeout(resolve, delay)) +import sleep from 'utils/sleep' const policies = { 'never-executed': triggerState => diff --git a/src/ducks/client/checks.spec.js b/src/ducks/client/checks.spec.js index cdb6f401b6..6b1e9d5a77 100644 --- a/src/ducks/client/checks.spec.js +++ b/src/ducks/client/checks.spec.js @@ -1,8 +1,7 @@ import StartupChecksPlugin from './checks' import CozyClient from 'cozy-client' import merge from 'lodash/merge' - -const sleep = delay => new Promise(resolve => setTimeout(resolve, delay)) +import sleep from 'utils/sleep' describe('startup checks', () => { beforeEach(() => { diff --git a/src/utils/effects.js b/src/utils/effects.js index a9809a5a8b..7e4407f5df 100644 --- a/src/utils/effects.js +++ b/src/utils/effects.js @@ -1,7 +1,4 @@ -const sleep = duration => - new Promise(resolve => { - setTimeout(resolve, duration) - }) +import sleep from 'utils/sleep' const shakeClassName = 'u-shake' diff --git a/test/e2e/alerts/alerts.e2e.spec.js b/test/e2e/alerts/alerts.e2e.spec.js index 69c4f2aac6..3360b3b0b7 100644 --- a/test/e2e/alerts/alerts.e2e.spec.js +++ b/test/e2e/alerts/alerts.e2e.spec.js @@ -20,6 +20,7 @@ import { } from 'ducks/client/utils' import { runService, makeToken } from 'test/e2e/utils' import assert from '../../../src/utils/assert' +import sleep from 'utils/sleep' const SOFTWARE_ID = 'banks.alerts-e2e' @@ -63,8 +64,6 @@ const checkPushForScenario = async (pushServer, scenario) => { } } -const sleep = duration => new Promise(resolve => setTimeout(resolve, duration)) - const runScenario = async (client, scenario, options) => { assert(client, 'No client') await importACHData(client, scenario.data)