-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
61 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
...count/Requests/SignPermitRequest/index.js → ...count/Requests/SignPermitRequest/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') | ||
}) |