Skip to content

Commit

Permalink
chore: merge main into redesign (#5385)
Browse files Browse the repository at this point in the history
* feat: introduce built-in next.js exports and updated scripts and configs (#5384)

* chore: updated gitignore and rmeoved robots.txt

* chore: updated next-sitemap config

* chore: next-config refactored options and export support

* chore: updated imports to node: prefix

* chore: updated contributing guidelines

* chore: updated scripts

* chore: updated next-sitemap

* chore: added missing props

* fix: github-pages

* chore: remove unused package

* fix(storybook): update packages (#5386)

---------

Co-authored-by: Harkunwar Kochar <10580591+Harkunwar@users.noreply.github.com>
  • Loading branch information
ovflowd and Harkunwar committed May 24, 2023
1 parent 862d056 commit 4a1ac84
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 63 deletions.
52 changes: 34 additions & 18 deletions hooks/__tests__/useCopyToClipboard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { render, fireEvent, screen } from '@testing-library/react';
import { render, fireEvent, screen, act } from '@testing-library/react';
import { FormattedMessage } from 'react-intl';
import { IntlProvider } from 'react-intl';
import { useCopyToClipboard } from '../useCopyToClipboard';

const mockWriteText = jest.fn();
const originalNavigator = { ...window.navigator };

const testMessages = {
'components.common.shellBox.copy':
'{copied, select, true {copied}other {copy}}',
};

describe('useCopyToClipboard', () => {
beforeEach(() => {
jest.useFakeTimers();

Object.defineProperty(window, 'navigator', {
value: {
clipboard: {
Expand All @@ -23,22 +30,7 @@ describe('useCopyToClipboard', () => {
});
});

const TestComponent = ({ textToCopy }: { textToCopy: string }) => {
const [copied, copyText] = useCopyToClipboard();

return (
<IntlProvider locale="en" onError={() => {}}>
<button onClick={() => copyText(textToCopy)} type="button">
<FormattedMessage
id="components.common.shellBox.copy"
values={{ copied }}
/>
</button>
</IntlProvider>
);
};

it('should call clipboard API with `test` once', () => {
it('should call clipboard API with `test` once', async () => {
const navigatorClipboardWriteTextSpy = jest
.fn()
.mockImplementation(() => Promise.resolve());
Expand All @@ -50,9 +42,33 @@ describe('useCopyToClipboard', () => {
},
});

const TestComponent = ({ textToCopy }: { textToCopy: string }) => {
const [copied, copyText] = useCopyToClipboard();

return (
<IntlProvider locale="en" messages={testMessages} onError={() => {}}>
<button onClick={() => copyText(textToCopy)} type="button">
<FormattedMessage
id="components.common.shellBox.copy"
values={{ copied }}
/>
</button>
</IntlProvider>
);
};

render(<TestComponent textToCopy="test" />);

const button = screen.getByRole('button');
fireEvent.click(button);

await fireEvent.click(button);

expect(await screen.findByText(/copied/i)).toBeInTheDocument();

act(() => jest.advanceTimersByTime(3000));

expect(await screen.findByText(/copy/i)).toBeInTheDocument();

expect(navigatorClipboardWriteTextSpy).toHaveBeenCalledTimes(1);
expect(navigatorClipboardWriteTextSpy).toHaveBeenCalledWith('test');
});
Expand Down
72 changes: 31 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"node": "v18"
},
"scripts": {
"scripts:release-post": "cross-env NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
"scripts:sitemap": "cross-env NODE_NO_WARNINGS=1 next-sitemap --config next-sitemap.config.mjs",
"serve": "cross-env NODE_NO_WARNINGS=1 next dev",
"build": "cross-env NODE_NO_WARNINGS=1 next build",
"start": "cross-env NODE_NO_WARNINGS=1 next start",
Expand All @@ -23,15 +25,14 @@
"prettier": "prettier . --check --cache --cache-strategy metadata",
"prettier:fix": "npm run prettier -- --write",
"format": "npm run prettier:fix && npm run lint:fix",
"scripts:release-post": "NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
"test": "npm run test:unit && npm run test:storybook",
"storybook": "cross-env NODE_NO_WARNINGS=1 storybook dev -p 6006",
"storybook:build": "cross-env NODE_NO_WARNINGS=1 storybook build",
"test:unit": "cross-env NODE_NO_WARNINGS=1 jest --passWithNoTests",
"test:unit:watch": "npm run test:unit -- --watch",
"test:storybook": "npx concurrently -P -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"npm run storybook -- --ci\" \"npx wait-on http://localhost:6006 && npx test-storybook {@}\"",
"test:storybook:snapshot": "npm run test:storybook -- -- --updateSnapshot",
"test:storybook:watch": "npm run test:storybook -- -- --watch",
"storybook": "cross-env NODE_ENV=development NODE_NO_WARNINGS=1 storybook dev -p 6006",
"storybook:build": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 storybook build"
"test": "npm run test:unit && npm run test:storybook"
},
"dependencies": {
"@emotion/react": "^11.11.0",
Expand Down

0 comments on commit 4a1ac84

Please sign in to comment.