-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Taylor Smock <[email protected]>
- Loading branch information
Showing
2 changed files
with
6 additions
and
22 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
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,23 +1,15 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { APIKeyCard } from '../content'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { IntlProviders } from '../../../utils/testWithIntl'; | ||
|
||
test('should copy API key to the clipboard', async () => { | ||
const originalClipboard = { ...global.navigator.clipboard }; | ||
const mockClipboard = { | ||
writeText: jest.fn().mockImplementation(() => Promise.resolve()), | ||
}; | ||
global.navigator.clipboard = mockClipboard; | ||
const user = userEvent.setup(); | ||
const user = userEvent.setup({ writeToClipboard: true }); | ||
render( | ||
<IntlProviders> | ||
<APIKeyCard token="validToken" /> | ||
</IntlProviders>, | ||
); | ||
await user.click(screen.getByRole('img')); | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1); | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('Token validToken'); | ||
jest.resetAllMocks(); | ||
global.navigator.clipboard = originalClipboard; | ||
await waitFor(async () => expect(await navigator.clipboard.readText()).toBe('Token validToken')); | ||
}); |