Skip to content

Commit

Permalink
Test(web-react): Use Jest's automock functionality to share useIcon m…
Browse files Browse the repository at this point in the history
…ock between tests
  • Loading branch information
literat committed Dec 19, 2024
1 parent 1c62074 commit dccbc43
Show file tree
Hide file tree
Showing 32 changed files with 50 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('AccordionHeader', () => {
classNamePrefixProviderTest(AccordionHeader, 'Accordion__itemHeader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import Accordion from '../Accordion';
import AccordionContent from '../AccordionContent';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('AccordionItem', () => {
classNamePrefixProviderTest(AccordionItem, 'Accordion__item');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import AccordionContent from '../AccordionContent';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';
import UncontrolledAccordion from '../UncontrolledAccordion';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('UncontrolledAccordion', () => {
classNamePrefixProviderTest(UncontrolledAccordion, 'Accordion');
Expand Down
10 changes: 2 additions & 8 deletions packages/web-react/src/components/Alert/__tests__/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
emotionColorPropsTest,
restPropsTest,
stylePropsTest,
} from '@local/tests';
import { classNamePrefixProviderTest, emotionColorPropsTest, restPropsTest, stylePropsTest } from '@local/tests';
import Alert from '../Alert';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Alert', () => {
classNamePrefixProviderTest(Alert, 'Alert');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import Breadcrumbs from '../Breadcrumbs';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Breadcrumbs', () => {
classNamePrefixProviderTest(Breadcrumbs, 'Breadcrumbs');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import BreadcrumbsItem from '../BreadcrumbsItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('BreadcrumbsItem', () => {
classNamePrefixProviderTest(BreadcrumbsItem, 'd-none');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
actionButtonColorPropsTest,
emotionColorPropsTest,
Expand All @@ -13,7 +12,7 @@ import {
} from '@local/tests';
import Button from '../Button';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Button', () => {
classNamePrefixProviderTest(Button, 'Button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
actionButtonColorPropsTest,
emotionColorPropsTest,
Expand All @@ -13,7 +12,7 @@ import {
} from '@local/tests';
import ButtonLink from '../ButtonLink';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ButtonLink', () => {
classNamePrefixProviderTest(ButtonLink, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import { Button } from '../../Button';
import DropdownTrigger from '../DropdownTrigger';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('DropdownTrigger', () => {
stylePropsTest((props) => <DropdownTrigger elementType={Button} {...props} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import '@testing-library/jest-dom';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import FileUploader from '../FileUploader';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploader', () => {
classNamePrefixProviderTest(FileUploader, 'FileUploader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, validationTextPropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, validationTextPropsTest } from '@local/tests';
import FileUploaderInput from '../FileUploaderInput';
import '@testing-library/jest-dom';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploaderInput', () => {
classNamePrefixProviderTest(FileUploaderInput, 'FileUploaderInput');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '@local/tests';
import { SpiritFileUploaderAttachmentProps } from '../../../types';
import FileUploader from '../FileUploader';
import FileUploaderList from '../FileUploaderList';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploaderList', () => {
const props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import HeaderDialogCloseButton from '../HeaderDialogCloseButton';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('HeaderDialogCloseButton', () => {
classNamePrefixProviderTest(HeaderDialogCloseButton, 'HeaderDialogCloseButton');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { HEADER_MENU_TOGGLE_LABEL_DEFAULT } from '../constants';
import HeaderMobileActions from '../HeaderMobileActions';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('HeaderMobileActions', () => {
classNamePrefixProviderTest(HeaderMobileActions, 'HeaderMobileActions');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import Icon from '../Icon';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Icon', () => {
const AddIcon = (props: Record<string, unknown>) => <Icon {...props} name="add" data-testid="test-icon" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import { SpiritItemProps } from '../../../types';
import Item from '../Item';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Item', () => {
stylePropsTest(Item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ModalCloseButton from '../ModalCloseButton';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ModalCloseButton', () => {
classNamePrefixProviderTest(ModalCloseButton, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ModalHeader from '../ModalHeader';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ModalHeader', () => {
classNamePrefixProviderTest(ModalHeader, 'ModalHeader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationButtonLink from '../PaginationButtonLink';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationButtonLink', () => {
classNamePrefixProviderTest(PaginationButtonLink, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationLinkNext from '../PaginationLinkNext';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationLinkNext', () => {
classNamePrefixProviderTest(PaginationLinkNext, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationLinkPrevious from '../PaginationLinkPrevious';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationLinkPrevious', () => {
classNamePrefixProviderTest(PaginationLinkPrevious, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '@local/tests';
import UncontrolledPagination from '../UncontrolledPagination';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('UncontrolledPagination', () => {
const onPageChange = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
validationStatePropsTest,
requiredPropsTest,
Expand All @@ -12,7 +11,7 @@ import {
} from '@local/tests';
import Select from '../Select';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Select', () => {
classNamePrefixProviderTest(Select, 'Select');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
textColorPropsTest,
restPropsTest,
stylePropsTest,
} from '@local/tests';
import { classNamePrefixProviderTest, textColorPropsTest, restPropsTest, stylePropsTest } from '@local/tests';
import Spinner from '../Spinner';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Spinner', () => {
classNamePrefixProviderTest(Spinner, 'animation-spin-clockwise');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
validationStatePropsTest,
restPropsTest,
Expand All @@ -12,7 +11,7 @@ import {
import { TextFieldType } from '../../../types';
import TextField from '../TextField';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('TextField', () => {
describe.each(['text', 'password', 'email'])('input type %s', (type) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ToastBar from '../ToastBar';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ToastBar', () => {
classNamePrefixProviderTest((props) => <ToastBar {...props} id="test" />, 'ToastBar');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '@local/tests';
import { ToastLinkProps } from '../../../types';
import { ToastContext } from '../ToastContext';
import UncontrolledToast from '../UncontrolledToast';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

const defaultToast = {
id: 'test-id',
Expand Down
Loading

0 comments on commit dccbc43

Please sign in to comment.