Skip to content

Commit

Permalink
finish rebase, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman committed Jan 13, 2023
1 parent 6bb2289 commit a1a4b83
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 61 deletions.
3 changes: 1 addition & 2 deletions app/tray/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import SignatureRequest from './Requests/SignatureRequest'
import ChainRequest from './Requests/ChainRequest'
import AddTokenRequest from './Requests/AddTokenRequest'
import SignTypedDataRequest from './Requests/SignTypedDataRequest'
import { isHardwareSigner } from '../../../resources/domain/signer'
import PermitSignatureRequest from './Requests/PermitSignatureRequest'
import SignPermitRequest from './Requests/SignPermitRequest'
import { isHardwareSigner } from '../../../resources/domain/signer'

class _AccountModule extends React.Component {
// constructor (props, context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useState, useEffect } from 'react'
import BigNumber from 'bignumber.js'

import { formatDisplayInteger, isUnlimited } from '../../../../../../resources/utils/numbers'
import svg from '../../../../../../resources/svg'
import link from '../../../../../../resources/link'
import { ClusterBox, Cluster, ClusterRow, ClusterValue } from '../../../../../../resources/Components/Cluster'
import Countdown from '../../../../../../resources/Components/Countdown'
import RequestHeader from '../../../../../../resources/Components/RequestHeader'
import RequestItem from '../../../../../../resources/Components/RequestItem'
import CustomAmountInput from '../../../../../../resources/Components/CustomAmountInput'
import TypedSignatureOverview from '../../../../../../resources/Components/SimpleTypedData'
import useCopiedMessage from '../../../../../../resources/Hooks/useCopiedMessage'
import { formatDisplayInteger, isUnlimited } from '../../../../../resources/utils/numbers'
import svg from '../../../../../resources/svg'
import link from '../../../../../resources/link'
import { ClusterBox, Cluster, ClusterRow, ClusterValue } from '../../../../../resources/Components/Cluster'
import Countdown from '../../../../../resources/Components/Countdown'
import RequestHeader from '../../../../../resources/Components/RequestHeader'
import RequestItem from '../../../../../resources/Components/RequestItem'
import CustomAmountInput from '../../../../../resources/Components/CustomAmountInput'
import TypedSignatureOverview from '../../../../../resources/Components/SimpleTypedData'
import { getSignatureRequestClass } from '../../../../../resources/domain/request'
import useCopiedMessage from '../../../../../resources/Hooks/useCopiedMessage'

import { getSignatureRequestClass } from '../../../../../../resources/domain/request'
const getPermit = (req) => {
const {
typedMessage: {
Expand Down
4 changes: 2 additions & 2 deletions app/tray/Account/Requests/SignTypedDataRequest/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Restore from 'react-restore'
import TypedSignatureOverview from '../../../../../../resources/Components/SimpleTypedData'
import { getSignatureRequestClass } from '../../../../../../resources/domain/request'
import TypedSignatureOverview from '../../../../../resources/Components/SimpleTypedData'
import { getSignatureRequestClass } from '../../../../../resources/domain/request'
class TransactionRequest extends React.Component {
constructor(...args) {
super(...args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import svg from '../../../../../../resources/svg'

import { Cluster, ClusterRow, ClusterValue } from '../../../../../../resources/Components/Cluster'
import { DisplayValue } from '../../../../../../resources/Components/DisplayValue'
import RequestHeader from '../../../../../../../resources/Components/RequestHeader'
import RequestHeader from '../../../../../../resources/Components/RequestHeader'

const isNonZeroHex = (hex) => !!hex && !['0x', '0x0'].includes(hex)

Expand Down
1 change: 0 additions & 1 deletion app/tray/Account/Requests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Restore from 'react-restore'
import TxOverview from './TransactionRequest/TxMainNew/overview'

import RequestItem from '../../../../resources/Components/RequestItem'
import RingIcon from '../../../../resources/Components/RingIcon'

import { ClusterBox, Cluster } from '../../../../resources/Components/Cluster'

Expand Down
90 changes: 46 additions & 44 deletions test/resources/Hooks/useCopied/index.test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
/** @jest-environment jsdom */
import { renderHook, act } from '@testing-library/react'
import React from 'react'

import { render, screen } from '../../../componentSetup'
import useCopiedMessage from '../../../../resources/Hooks/useCopiedMessage'
import link from '../../../../resources/link'

const TestComponent = () => {
const [showCopiedMessage, copyText] = useCopiedMessage('use frame!')

return (
<>
<button onClick={copyText}>Copy</button>
<div data-testid='iscopied'>{showCopiedMessage ? 'message copied!' : 'waiting for click'}</div>
</>
)
}

jest.mock('../../../../resources/link', () => ({
send: jest.fn()
}))

describe('#useCopied', () => {
jest.useFakeTimers()

let result

const getBool = () => result.current[0]
const copyFn = () => result.current[1]()

beforeEach(() => {
;({ result } = renderHook(() => useCopiedMessage('VALUE')))
jest.clearAllMocks()
})

it('should correctly initialise a boolean to check if the copiedMessage should be shown', () => {
expect(result.current[0]).toBe(false)
})

it('should expose a function to copy to clipboard', () => {
expect(typeof result.current[1]).toBe('function')
})

it('should set the boolean value as true when the copy function is called', () => {
act(() => {
copyFn()
})
expect(getBool()).toBe(true)
})

it('should reset the boolean value after 1 second', () => {
act(() => {
copyFn()
jest.advanceTimersByTime(1000)
})
expect(getBool()).toBe(false)
})

it('should call the clipboardData function inside link when the copy function is called', () => {
act(() => {
copyFn()
})
expect(link.send).toHaveBeenCalledWith('tray:clipboardData', 'VALUE')
expect(link.send).toHaveBeenCalledTimes(1)
})
it('should not display the copied text by default', () => {
render(<TestComponent />)

expect(screen.getByTestId('iscopied').textContent).toBe('waiting for click')
})

it('should let the component know to display the copied text after the copy function is invoked', async () => {
const { user } = render(<TestComponent />)

const clickToCopyButton = screen.getByRole('button')
await user.click(clickToCopyButton)

expect(screen.getByTestId('iscopied').textContent).toBe('message copied!')
})

it('should reset the copied text after one second', async () => {
const { user } = render(<TestComponent />, { advanceTimersAfterInput: true })

const clickToCopyButton = screen.getByRole('button')
await user.click(clickToCopyButton)

expect(screen.getByTestId('iscopied').textContent).toBe('waiting for click')
})

it('send the copied data to the clipboard', async () => {
const { user } = render(<TestComponent />)

const clickToCopyButton = screen.getByRole('button')
await user.click(clickToCopyButton)

expect(link.send).toHaveBeenCalledTimes(1)
expect(link.send).toHaveBeenCalledWith('tray:clipboardData', 'use frame!')
})

0 comments on commit a1a4b83

Please sign in to comment.