Skip to content

Commit

Permalink
test: replace renderWithProviders with setup fn
Browse files Browse the repository at this point in the history
Closes UXD-1690
  • Loading branch information
ajkl2533 committed Jan 6, 2025
1 parent db61b67 commit 24822e4
Show file tree
Hide file tree
Showing 49 changed files with 164 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/components/Accordion/Accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
import { vi } from 'vitest';

import Accordion, { filterState } from './Accordion';
import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';

describe('Accordion/filterState', () => {
it('should correctly add an item to the state if it is not already included and `isCollapsedOnOpen` is false', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/components/Breadcrumbs/Breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fireEvent, screen, waitFor } from '@testing-library/react';

import { renderWithProviders } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';
import BreadcrumbItem from './BreadcrumbItem';
import Breadcrumbs from './Breadcrumbs';

describe('Breadcrumbs', () => {
it('should not show a dropdown button when breadcrumb have less than 5 items', () => {
renderWithProviders(
setup(
<Breadcrumbs>
<BreadcrumbItem href="#">Root</BreadcrumbItem>
<BreadcrumbItem href="#">Parent</BreadcrumbItem>
Expand All @@ -19,7 +19,7 @@ describe('Breadcrumbs', () => {
});

it('should show a dropdown button when breadcrumb have more than 5 items', () => {
renderWithProviders(
setup(
<Breadcrumbs>
<BreadcrumbItem href="#">Root</BreadcrumbItem>
<BreadcrumbItem href="#">Parent1</BreadcrumbItem>
Expand All @@ -42,7 +42,7 @@ describe('Breadcrumbs', () => {
});

it('should show all items inside dropdown when dropdown is opened', async () => {
renderWithProviders(
setup(
<Breadcrumbs>
<BreadcrumbItem href="#">Root</BreadcrumbItem>
<BreadcrumbItem href="#">Parent1</BreadcrumbItem>
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Breadcrumbs', () => {
});

it('should show items within dropdown using correct order ', async () => {
renderWithProviders(
setup(
<Breadcrumbs>
<BreadcrumbItem href="#">Link1</BreadcrumbItem>
<BreadcrumbItem href="#">Link2</BreadcrumbItem>
Expand All @@ -97,7 +97,7 @@ describe('Breadcrumbs', () => {
});

it('should be the last breadcrumb item not a link', async () => {
renderWithProviders(
setup(
<Breadcrumbs>
<BreadcrumbItem href="#">Link1</BreadcrumbItem>
<BreadcrumbItem href="#">Link2</BreadcrumbItem>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Collapsible/Collapsible.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useState } from 'react';
import { screen } from '@testing-library/react';
import { type Mock, vi } from 'vitest';

import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';
import { Collapsible } from './index';

const ControllingComponent = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { vi } from 'vitest';

import { renderWithProviders } from '../../../../utils/tests/renderWithProviders';
import { setup } from '../../../../utils/tests/setup';
import { DatatableStore, datatableInitialState } from '../../Datatable.store';
import BatchActions from './BatchActions';

Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Datatable/BatchActions', () => {
});
});
it('should call onClick handler on top-level action with correct parameters', () => {
renderWithProviders(<BatchActions actions={actions} />);
setup(<BatchActions actions={actions} />);

fireEvent.click(screen.getByRole('button', { name: /Action/i }));
expect(actionFnMock).toBeCalledWith(
Expand All @@ -56,7 +56,7 @@ describe('Datatable/BatchActions', () => {
});

it('should call onClick handler in dropdown action with correct parameters', () => {
renderWithProviders(<BatchActions actions={actions} />);
setup(<BatchActions actions={actions} />);

fireEvent.click(screen.getByRole('button', { name: /Dropdown/i }));
fireEvent.click(screen.getByRole('button', { name: /Dropdown Item/i }));
Expand All @@ -78,7 +78,7 @@ describe('Datatable/BatchActions', () => {
});
});
it('should call onClick handler on top-level action with correct parameters', () => {
renderWithProviders(<BatchActions actions={actions} />);
setup(<BatchActions actions={actions} />);
act(() => {
DatatableStore.update((s) => {
s.selectedIds = selectedIds;
Expand All @@ -94,7 +94,7 @@ describe('Datatable/BatchActions', () => {
});

it('should call onClick handler in dropdown action with correct parameters', async () => {
renderWithProviders(<BatchActions actions={actions} />);
setup(<BatchActions actions={actions} />);
act(() => {
DatatableStore.update((s) => {
s.selectedIds = selectedIds;
Expand All @@ -117,7 +117,7 @@ describe('Datatable/BatchActions', () => {
});
describe('given subactions are defined', () => {
it('should create dropdown button', async () => {
renderWithProviders(<BatchActions actions={actions} />);
setup(<BatchActions actions={actions} />);

fireEvent.click(screen.getByRole('button', { name: /Dropdown/i }));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import { act, fireEvent, screen } from '@testing-library/react';

import ElementCounter, { getCounterContent } from './ElementCounter';
import { renderWithProviders } from '../../../../utils/tests/renderWithProviders';
import { setup } from '../../../../utils/tests/setup';
import { DatatableStore, datatableInitialState } from '../../Datatable.store';

describe('getCounterContent', () => {
it('should return No Data when "totalLength" is 0', () => {
render(getCounterContent(0));
setup(getCounterContent(0));
expect(screen.getByTestId('counter-content')).toHaveTextContent('No data');
});
it('should return No Data when "totalLength" is 0 and "selectedLength" is greater than 0', () => {
render(getCounterContent(0, 500));
setup(getCounterContent(0, 500));
expect(screen.getByTestId('counter-content')).toHaveTextContent('No data');
});

it('should return correct count when "totalLength" is greater than 0', () => {
render(getCounterContent(1000));
setup(getCounterContent(1000));
expect(screen.getByTestId('counter-content')).toHaveTextContent('1K');
});

it('should return correct count when "totalLength" and "selectedLength" are greater than 0', () => {
render(getCounterContent(1000, 500));
setup(getCounterContent(1000, 500));
expect(screen.getByTestId('counter-content')).toHaveTextContent(
'500 of 1K selected',
);
Expand All @@ -33,7 +33,7 @@ describe('Datatable/ElementCounter', () => {
});

it('should show Select None button when there are selected rows', () => {
renderWithProviders(
setup(
<ElementCounter dataSize={1000} hasOnlyPerPageSelection hasSelection />,
);

Expand All @@ -55,7 +55,7 @@ describe('Datatable/ElementCounter', () => {
describe('DatatableStore actions', () => {
describe('given selection dropdown is visible', () => {
it('should set "hasExclusiveSelection" to "true" on Select All click', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -69,7 +69,7 @@ describe('Datatable/ElementCounter', () => {
expect(DatatableStore.getRawState().hasExclusiveSelection).toBe(true);
});
it('should set "hasExclusiveSelection" to "false" on Select None click', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -89,7 +89,7 @@ describe('Datatable/ElementCounter', () => {
expect(DatatableStore.getRawState().hasExclusiveSelection).toBe(false);
});
it('should set "shouldResetSelectedRows" to "true" on Select All click', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -103,7 +103,7 @@ describe('Datatable/ElementCounter', () => {
expect(DatatableStore.getRawState().shouldResetSelectedRows).toBe(true);
});
it('should set "shouldResetSelectedRows" to "true" on Select None click', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -117,7 +117,7 @@ describe('Datatable/ElementCounter', () => {
expect(DatatableStore.getRawState().shouldResetSelectedRows).toBe(true);
});
it('should react on "selectedIds" change', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -136,7 +136,7 @@ describe('Datatable/ElementCounter', () => {
expect(counter).toHaveTextContent('3 of 1K selected');
});
it('should react on "hasExclusiveSelection" change', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand All @@ -158,7 +158,7 @@ describe('Datatable/ElementCounter', () => {
});
describe('given selection dropdown is hidden', () => {
it('should set "shouldResetSelectedRows" to "true" on Select None click', () => {
renderWithProviders(
setup(
<ElementCounter
dataSize={1000}
hasSelection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen, waitFor } from '@testing-library/react';
import { vi } from 'vitest';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import { InputFilter } from '../../Filters/components';
import { Operators } from '../../Filters/Filters.enums';
import { DatatableStore, datatableInitialState } from '../Datatable.store';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Datatable/Datatable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Column } from 'react-table';
import { filter } from 'ramda';
import { vi } from 'vitest';

import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';
import { fields } from '../Filters/mocks/options';
import Datatable from './Datatable';
import { DatatableStore, datatableInitialState } from './Datatable.store';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Datatable/Table/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, screen, waitFor } from '@testing-library/react';
import { Column } from 'react-table';
import { vi } from 'vitest';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import { DatatableStore, datatableInitialState } from '../Datatable.store';
import Table from './Table';
import { defaultTableConfig } from '../defaultConfigs';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Datatable/components/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen, waitFor } from '@testing-library/react';
import { vi } from 'vitest';

import Search from './Search';
import { setup } from '../../../../utils/tests/renderWithProviders';
import { setup } from '../../../../utils/tests/setup';

const onSearch = vi.fn();
const onClear = vi.fn();
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/columnPinning.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/columnResizing.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import { vi } from 'vitest';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/columnVisibility.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/pagination.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen } from '@testing-library/react';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/selection.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen, waitFor } from '@testing-library/react';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DatatableV2/tests/sorting.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from '@testing-library/react';
import { vi } from 'vitest';

import { setup } from '../../../utils/tests/renderWithProviders';
import { setup } from '../../../utils/tests/setup';
import Datatable from '../Datatable';
import { columns, data } from './mocks';

Expand Down
2 changes: 1 addition & 1 deletion src/components/DateRangePicker/DateRangePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { vi } from 'vitest';

import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';
import DateRangePicker from './DateRangePicker';

describe('DateRangePicker', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Drawer/Drawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
import { act } from 'react';
import { vi } from 'vitest';

import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';
import Drawer from './Drawer';
import Button from '../ButtonV2/Button';
import { Icon } from '../Icon';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorBoundary/ErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { vi } from 'vitest';

import ErrorBoundary, { DEFAULT_CONTENT, DEFAULT_TITLE } from './ErrorBoundary';
import { ErrorBoundaryProps } from './ErrorBoundary.types';
import { setup } from '../../utils/tests/renderWithProviders';
import { setup } from '../../utils/tests/setup';

describe('ErrorBoundary Component', () => {
it('should render component properly', () => {
Expand Down
Loading

0 comments on commit 24822e4

Please sign in to comment.