Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test(web-react): Mock usage of the useIcon hook #1803

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/web-react/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const config = {
// A list of paths to modules that run some code to configure or set up the testing framework before each test file in the suite is executed.
// https://jestjs.io/docs/configuration#setupfilesafterenv-array
setupFilesAfterEnv: ['<rootDir>/config/jest/setupTestingLibrary.ts'],

// Automatically clear mock calls, instances, contexts and results before every test.
// https://jestjs.io/docs/configuration#clearmocks-boolean
clearMocks: true,
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

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

describe('AccordionHeader', () => {
classNamePrefixProviderTest(AccordionHeader, 'Accordion__itemHeader');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
Expand All @@ -9,6 +10,8 @@ import AccordionContent from '../AccordionContent';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

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

describe('AccordionItem', () => {
classNamePrefixProviderTest(AccordionItem, 'Accordion__item');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
Expand All @@ -9,6 +10,8 @@ import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';
import UncontrolledAccordion from '../UncontrolledAccordion';

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

describe('UncontrolledAccordion', () => {
classNamePrefixProviderTest(UncontrolledAccordion, 'Accordion');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { emotionColorPropsTest } from '../../../../tests/providerTests/dictionaryPropsTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import Alert from '../Alert';

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

describe('Alert', () => {
classNamePrefixProviderTest(Alert, 'Alert');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import Breadcrumbs from '../Breadcrumbs';

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

describe('Breadcrumbs', () => {
classNamePrefixProviderTest(Breadcrumbs, 'Breadcrumbs');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import BreadcrumbsItem from '../BreadcrumbsItem';

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

describe('BreadcrumbsItem', () => {
classNamePrefixProviderTest(BreadcrumbsItem, 'd-none');
classNamePrefixProviderTest(BreadcrumbsItem, 'd-tablet-flex');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import {
actionButtonColorPropsTest,
Expand All @@ -12,6 +13,8 @@ import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import Button from '../Button';

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

describe('Button', () => {
classNamePrefixProviderTest(Button, 'Button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import {
actionButtonColorPropsTest,
Expand All @@ -12,6 +13,8 @@ import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import ButtonLink from '../ButtonLink';

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

describe('ButtonLink', () => {
classNamePrefixProviderTest(ButtonLink, 'Button');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Collapse', () => {

it('should render text children', () => {
render(
<Collapse id="collapse" isOpen data-testId="test">
<Collapse id="collapse" isOpen data-testid="test">
Hello World
</Collapse>,
);
Expand All @@ -34,10 +34,10 @@ describe('Collapse', () => {

return (
<>
<Button type="button" data-testId="test-button" onClick={() => setIsOpen(!isOpen)}>
<Button type="button" data-testid="test-button" onClick={() => setIsOpen(!isOpen)}>
Toggle Collapse
</Button>
<Collapse id="collapse" isOpen={isOpen} data-testId="test">
<Collapse id="collapse" isOpen={isOpen} data-testid="test">
Hello World
</Collapse>
</>
Expand All @@ -58,7 +58,7 @@ describe('Collapse', () => {

it('should have correct html element', () => {
render(
<Collapse id="collapse" elementType="section" isOpen data-testId="test">
<Collapse id="collapse" elementType="section" isOpen data-testid="test">
Hello World
</Collapse>,
);
Expand All @@ -76,10 +76,10 @@ describe('Collapse', () => {

return (
<>
<Button type="button" data-testId="test-button" onClick={() => setIsOpen(!isOpen)}>
<Button type="button" data-testid="test-button" onClick={() => setIsOpen(!isOpen)}>
Toggle Collapse
</Button>
<Collapse id="collapse" isOpen={isOpen} transitionDuration={duration} data-testId="test">
<Collapse id="collapse" isOpen={isOpen} transitionDuration={duration} data-testid="test">
Hello World
</Collapse>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import { Button } from '../../Button';
import DropdownTrigger from '../DropdownTrigger';

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

describe('DropdownTrigger', () => {
stylePropsTest((props) => <DropdownTrigger elementType={Button} {...props} />);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import '@testing-library/jest-dom';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import FileUploader from '../FileUploader';

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

describe('FileUploader', () => {
classNamePrefixProviderTest(FileUploader, 'FileUploader');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { validationTextPropsTest } from '../../../../tests/providerTests/validationTextPropsTest';
import FileUploaderInput from '../FileUploaderInput';
import '@testing-library/jest-dom';

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

describe('FileUploaderInput', () => {
classNamePrefixProviderTest(FileUploaderInput, 'FileUploaderInput');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { SpiritFileUploaderAttachmentProps } from '../../../types';
import FileUploader from '../FileUploader';
import FileUploaderList from '../FileUploaderList';

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

describe('FileUploaderList', () => {
const props = {
label: 'File uploader',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import HeaderDialogCloseButton from '../HeaderDialogCloseButton';

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

describe('HeaderDialogCloseButton', () => {
classNamePrefixProviderTest(HeaderDialogCloseButton, 'HeaderDialogCloseButton');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import { HEADER_MENU_TOGGLE_LABEL_DEFAULT } from '../constants';
import HeaderMobileActions from '../HeaderMobileActions';

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

describe('HeaderMobileActions', () => {
classNamePrefixProviderTest(HeaderMobileActions, 'HeaderMobileActions');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import Icon from '../Icon';

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

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,14 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import { SpiritItemProps } from '../../../types';
import Item from '../Item';

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

describe('Item', () => {
stylePropsTest(Item);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import ModalCloseButton from '../ModalCloseButton';

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

describe('ModalCloseButton', () => {
classNamePrefixProviderTest(ModalCloseButton, 'Button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import ModalHeader from '../ModalHeader';

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

describe('ModalHeader', () => {
classNamePrefixProviderTest(ModalHeader, 'ModalHeader');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import '@testing-library/jest-dom';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import PaginationButtonLink from '../PaginationButtonLink';

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

describe('PaginationButtonLink', () => {
classNamePrefixProviderTest(PaginationButtonLink, 'Button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import '@testing-library/jest-dom';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import PaginationLinkNext from '../PaginationLinkNext';

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

describe('PaginationLinkNext', () => {
classNamePrefixProviderTest(PaginationLinkNext, 'Button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import '@testing-library/jest-dom';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import PaginationLinkPrevious from '../PaginationLinkPrevious';

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

describe('PaginationLinkPrevious', () => {
classNamePrefixProviderTest(PaginationLinkPrevious, 'Button');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import UncontrolledPagination from '../UncontrolledPagination';

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

describe('UncontrolledPagination', () => {
const onPageChange = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock } from '../../../../tests/mocks/hooksMock';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { validationStatePropsTest } from '../../../../tests/providerTests/dictionaryPropsTest';
import { requiredPropsTest } from '../../../../tests/providerTests/requiredPropsTest';
Expand All @@ -9,6 +10,8 @@ import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest';
import { validationTextPropsTest } from '../../../../tests/providerTests/validationTextPropsTest';
import Select from '../Select';

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

describe('Select', () => {
classNamePrefixProviderTest(Select, 'Select');

Expand Down
Loading
Loading