Skip to content

Commit

Permalink
fix: tests, logo + add Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Nov 20, 2023
1 parent debf834 commit 9d5270e
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 109 deletions.
2 changes: 1 addition & 1 deletion public/images/common/recovery-pending.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 98 additions & 85 deletions src/components/dashboard/RecoveryInProgress/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useBlockTimestamp } from '@/hooks/useBlockTimestamp'
import { useHasFeature } from '@/hooks/useChains'
import { useAppSelector } from '@/store'
import { render } from '@testing-library/react'
import { BigNumber } from 'ethers'
import { RecoveryInProgress, _getCountdown } from '.'

import { _getCountdown, _RecoveryInProgress } from '.'
import type { RecoveryQueueItem, RecoveryState } from '@/store/recoverySlice'

describe('getCountdown', () => {
it('should convert 0 seconds to 0 days, 0 hours, and 0 minutes', () => {
Expand All @@ -27,89 +26,99 @@ describe('getCountdown', () => {
})
})

jest.mock('@/hooks/useBlockTimestamp')
jest.mock('@/store')
jest.mock('@/hooks/useChains')

const mockUseBlockTimestamp = useBlockTimestamp as jest.MockedFunction<typeof useBlockTimestamp>
const mockUseAppSelector = useAppSelector as jest.MockedFunction<typeof useAppSelector>
const mockUseHasFeature = useHasFeature as jest.MockedFunction<typeof useHasFeature>

describe('RecoveryInProgress', () => {
it('should return null if the chain does not support recovery', () => {
mockUseHasFeature.mockReturnValue(false)
mockUseBlockTimestamp.mockReturnValue(0)
mockUseAppSelector.mockReturnValue([{ queue: [{ timestamp: 0 }] }])
beforeEach(() => {
jest.resetAllMocks()
})

const result = render(<RecoveryInProgress />)
it('should return null if the chain does not support recovery', () => {

Check failure on line 34 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return null if the chain does not support recovery

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:35:26) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
const result = render(
<_RecoveryInProgress
supportsRecovery={false}
blockTimestamp={0}
recovery={[{ queue: [{ timestamp: 0 } as RecoveryQueueItem] }] as RecoveryState}
/>,
)

expect(result.container).toBeEmptyDOMElement()
})

it('should return null if there is no block timestamp', () => {
mockUseHasFeature.mockReturnValue(true)
mockUseBlockTimestamp.mockReturnValue(undefined)
mockUseAppSelector.mockReturnValue([{ queue: [{ timestamp: 0 }] }])

const result = render(<RecoveryInProgress />)
it('should return a loader if there is no block timestamp', () => {

Check failure on line 46 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return a loader if there is no block timestamp

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:47:26) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
const result = render(
<_RecoveryInProgress
supportsRecovery={true}
blockTimestamp={undefined}
recovery={[{ queue: [{ timestamp: 0 } as RecoveryQueueItem] }] as RecoveryState}
/>,
)

expect(result.container).toBeEmptyDOMElement()
})

it('should return null if there are no delayed transactions', () => {

Check failure on line 58 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return null if there are no delayed transactions

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:59:26) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
mockUseHasFeature.mockReturnValue(true)
mockUseBlockTimestamp.mockReturnValue(undefined)
mockUseAppSelector.mockReturnValue([{ queue: [] }])

const result = render(<RecoveryInProgress />)
const result = render(
<_RecoveryInProgress
supportsRecovery={true}
blockTimestamp={69420}
recovery={[{ queue: [] as Array<RecoveryQueueItem> }] as RecoveryState}
/>,
)

expect(result.container).toBeEmptyDOMElement()
})

it('should return null if all the delayed transactions are expired and invalid', () => {

Check failure on line 70 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return null if all the delayed transactions are expired and invalid

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:71:26) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
mockUseHasFeature.mockReturnValue(true)
mockUseBlockTimestamp.mockReturnValue(69420)
mockUseAppSelector.mockReturnValue([
{
queue: [
{
timestamp: 0,
validFrom: BigNumber.from(69),
expiresAt: BigNumber.from(420),
},
],
},
])

const result = render(<RecoveryInProgress />)
const result = render(
<_RecoveryInProgress
supportsRecovery={true}
blockTimestamp={69420}
recovery={
[
{
queue: [
{
timestamp: 0,
validFrom: BigNumber.from(69),
expiresAt: BigNumber.from(420),
} as RecoveryQueueItem,
],
},
] as RecoveryState
}
/>,
)

expect(result.container).toBeEmptyDOMElement()
})

it('should return the countdown of the latest non-expired/invalid transactions if none are non-expired/valid', () => {

Check failure on line 94 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return the countdown of the latest non-expired/invalid transactions if none are non-expired/valid

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:97:35) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
const mockBlockTimestamp = 69420

mockUseHasFeature.mockReturnValue(true)
mockUseBlockTimestamp.mockReturnValue(mockBlockTimestamp)
mockUseAppSelector.mockReturnValue([
{
queue: [
{
timestamp: mockBlockTimestamp + 1,
validFrom: BigNumber.from(mockBlockTimestamp + 1), // Invalid
expiresAt: BigNumber.from(mockBlockTimestamp + 1), // Non-expired
},
{
// Older - should render this
timestamp: mockBlockTimestamp,
validFrom: BigNumber.from(mockBlockTimestamp * 4), // Invalid
expiresAt: null, // Non-expired
},
],
},
])

const { queryByText } = render(<RecoveryInProgress />)
const { queryByText } = render(
<_RecoveryInProgress
supportsRecovery={true}
blockTimestamp={mockBlockTimestamp}
recovery={
[
{
queue: [
{
timestamp: mockBlockTimestamp + 1,
validFrom: BigNumber.from(mockBlockTimestamp + 1), // Invalid
expiresAt: BigNumber.from(mockBlockTimestamp + 1), // Non-expired
} as RecoveryQueueItem,
{
// Older - should render this
timestamp: mockBlockTimestamp,
validFrom: BigNumber.from(mockBlockTimestamp * 4), // Invalid
expiresAt: null, // Non-expired
} as RecoveryQueueItem,
],
},
] as RecoveryState
}
/>,
)

expect(queryByText('Account recovery in progress')).toBeInTheDocument()
expect(
Expand All @@ -130,27 +139,31 @@ describe('RecoveryInProgress', () => {
it('should return the info of the latest non-expired/valid transactions', () => {

Check failure on line 139 in src/components/dashboard/RecoveryInProgress/index.test.tsx

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

RecoveryInProgress > should return the info of the latest non-expired/valid transactions

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> at useReduxContext (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useReduxContext.js:23:13) at useSelector (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-redux/lib/hooks/useSelector.js:63:9) at _RecoveryInProgress (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.tsx:25:39) at renderWithHooks (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:16305:18) at mountIndeterminateComponent (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:20074:13) at beginWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:21587:16) at beginWork$1 (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:27426:14) at performUnitOfWork (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26560:12) at workLoopSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26466:5) at renderRootSync (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:26434:7) at recoverFromConcurrentError (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25850:20) at performConcurrentWorkOnRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react-dom/cjs/react-dom.development.js:25750:22) at flushActQueue (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2667:24) at act (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/react/cjs/react.development.js:2582:11) at /home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/act-compat.js:63:25 at renderRoot (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:159:26) at render (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/@testing-library/react/dist/pure.js:246:10) at Object.<anonymous> (/home/runner/work/safe-wallet-web/safe-wallet-web/src/components/dashboard/RecoveryInProgress/index.test.tsx:142:35) at Promise.then.completed (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/safe-wallet-web/safe-wallet-web/node_modules/jest-runner/build/testWorker.js:106:12)
const mockBlockTimestamp = 69420

mockUseHasFeature.mockReturnValue(true)
mockUseBlockTimestamp.mockReturnValue(mockBlockTimestamp)
mockUseAppSelector.mockReturnValue([
{
queue: [
{
timestamp: mockBlockTimestamp - 1,
validFrom: BigNumber.from(mockBlockTimestamp - 1), // Invalid
expiresAt: BigNumber.from(mockBlockTimestamp - 1), // Non-expired
},
{
// Older - should render this
timestamp: mockBlockTimestamp - 2,
validFrom: BigNumber.from(mockBlockTimestamp - 1), // Invalid
expiresAt: null, // Non-expired
},
],
},
])

const { queryByText } = render(<RecoveryInProgress />)
const { queryByText } = render(
<_RecoveryInProgress
supportsRecovery={true}
blockTimestamp={mockBlockTimestamp}
recovery={
[
{
queue: [
{
timestamp: mockBlockTimestamp - 1,
validFrom: BigNumber.from(mockBlockTimestamp - 1), // Invalid
expiresAt: BigNumber.from(mockBlockTimestamp - 1), // Non-expired
} as RecoveryQueueItem,
{
// Older - should render this
timestamp: mockBlockTimestamp - 2,
validFrom: BigNumber.from(mockBlockTimestamp - 1), // Invalid
expiresAt: null, // Non-expired
} as RecoveryQueueItem,
],
},
] as RecoveryState
}
/>,
)

expect(queryByText('Account recovery possible')).toBeInTheDocument()
expect(queryByText('The recovery process is possible. This Account can be recovered.')).toBeInTheDocument()
Expand Down
77 changes: 54 additions & 23 deletions src/components/dashboard/RecoveryInProgress/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
import { Box, Card, Grid, Typography } from '@mui/material'
import { Box, Card, Grid, Skeleton, Typography } from '@mui/material'
import { useMemo } from 'react'
import type { ReactElement } from 'react'

import { useAppSelector } from '@/store'
import { selectRecovery } from '@/store/recoverySlice'
import { useBlockTimestamp } from '@/hooks/useBlockTimestamp'
import { WidgetContainer, WidgetBody } from '../styled'
import RecoveryPending from '@/public/images/common/recovery-pending.svg'
import ExternalLink from '@/components/common/ExternalLink'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'

export function RecoveryInProgress(): ReactElement | null {
const blockTimestamp = useBlockTimestamp()
const supportsRecovery = useHasFeature(FEATURES.RECOVERY)
const recovery = useAppSelector(selectRecovery)

if (!blockTimestamp || !supportsRecovery) {
import { selectRecovery, selectRecoverySlice } from '@/store/recoverySlice'
import type { RecoveryState } from '@/store/recoverySlice'
import madProps from '@/utils/mad-props'

export function _RecoveryInProgress({
blockTimestamp,
supportsRecovery,
recovery,
}: {
blockTimestamp?: number
supportsRecovery: boolean
recovery: RecoveryState
}): ReactElement | null {
const recoverySlice = useAppSelector(selectRecoverySlice)
const allRecoveryTxs = useMemo(() => {
return recoverySlice.data.flatMap(({ queue }) => queue).sort((a, b) => a.timestamp - b.timestamp)
}, [recoverySlice.data])

if (!supportsRecovery) {
return null
}

const nonExpiredTxs = recovery
.flatMap(({ queue }) => queue)
.sort((a, b) => a.timestamp - b.timestamp)
.filter((delayedTx) => {
return delayedTx.expiresAt ? delayedTx.expiresAt.gt(blockTimestamp) : true
})
if (!blockTimestamp || recoverySlice.loading) {
return (
<Grid item xs={12}>
<Skeleton variant="rounded" height="137px" width="100%" />
</Grid>
)
}

const nonExpiredTxs = allRecoveryTxs.filter((delayedTx) => {
return delayedTx.expiresAt ? delayedTx.expiresAt.gt(blockTimestamp) : true
})

if (nonExpiredTxs.length === 0) {
return null
Expand Down Expand Up @@ -54,7 +71,7 @@ export function RecoveryInProgress(): ReactElement | null {
? 'The recovery process is possible. This Account can be recovered.'
: 'The recovery process has started. This Account will be ready to recover in:'}
</Typography>
{isValid ? null : <Countdown seconds={secondsUntilValid} />}
<Countdown seconds={secondsUntilValid} />
</Grid>
<Grid item>
<ExternalLink
Expand All @@ -73,20 +90,24 @@ export function RecoveryInProgress(): ReactElement | null {
}

export function _getCountdown(seconds: number): { days: number; hours: number; minutes: number } {
const minute = 60
const hour = 60 * minute
const day = 24 * hour
const MINUTE_IN_SECONDS = 60
const HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS
const DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS

const days = Math.floor(seconds / day)
const days = Math.floor(seconds / DAY_IN_SECONDS)

const remainingSeconds = seconds % day
const hours = Math.floor(remainingSeconds / hour)
const minutes = Math.floor((remainingSeconds % hour) / minute)
const remainingSeconds = seconds % DAY_IN_SECONDS
const hours = Math.floor(remainingSeconds / HOUR_IN_SECONDS)
const minutes = Math.floor((remainingSeconds % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS)

return { days, hours, minutes }
}

function Countdown({ seconds }: { seconds: number }): ReactElement | null {
if (seconds <= 0) {
return null
}

const { days, hours, minutes } = _getCountdown(seconds)

return (
Expand Down Expand Up @@ -114,3 +135,13 @@ function TimeLeft({ value, unit }: { value: number; unit: string }): ReactElemen
</div>
)
}

// Appease React TypeScript warnings
const _useSupportsRecovery = () => useHasFeature(FEATURES.RECOVERY)
const _useRecovery = () => useAppSelector(selectRecovery)

export const RecoveryInProgress = madProps(_RecoveryInProgress, {
blockTimestamp: useBlockTimestamp,
supportsRecovery: _useSupportsRecovery,
recovery: _useRecovery,
})
2 changes: 2 additions & 0 deletions src/store/recoverySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ const { slice, selector } = makeLoadableSlice('recovery', initialState)

export const recoverySlice = slice

export const selectRecoverySlice = selector

export const selectRecovery = createSelector(selector, (recovery) => recovery.data)
4 changes: 4 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ input[type='number'] {
fill: var(--color-logo-background);
}

.illustration-background-warning-fill {
fill: var(--color-warning-background);
}

/* Note: a fallback `stroke` property must be on the svg to work */
.illustration-main-stroke {
stroke: var(--color-primary-main);
Expand Down

0 comments on commit 9d5270e

Please sign in to comment.