Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`[COMPONENTS]: TableEmptyRows component testing > to match snapshot 1`] = `
<div>
<tr
class="MuiTableRow-root css-1ra9nw1-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-sizeMedium css-bsph2u-MuiTableCell-root"
colspan="9"
/>
</tr>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`[COMPONENTS]: TableHeadCustom component testing > matches snapshot 1`] = `
<div>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
>
<tr
class="MuiTableRow-root MuiTableRow-head css-1q1u3t4-MuiTableRow-root"
>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignLeft MuiTableCell-sizeMedium css-1ygcj2i-MuiTableCell-root"
scope="col"
>
Name
</th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter MuiTableCell-sizeMedium css-elqmqc-MuiTableCell-root"
scope="col"
>
Email
</th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignRight MuiTableCell-sizeMedium css-10wjn0w-MuiTableCell-root"
scope="col"
>
Role
</th>
</tr>
</thead>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`[COMPONENTS]: TableNoData component testing > matches snapshot 1`] = `
<div>
<tr
class="MuiTableRow-root css-1q1u3t4-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-sizeMedium css-fp2qxz-MuiTableCell-root"
colspan="12"
>
<div
class="MuiStack-root css-fwjcfw-MuiStack-root"
>
<span
class="MuiTypography-root MuiTypography-h6 css-nfq7sy-MuiTypography-root"
>
No data found
</span>
</div>
</td>
</tr>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`[COMPONENTS]: TablePaginationCustom component testing > matches snapshot 1`] = `
<div>
<div
class="MuiBox-root css-1kxonj9"
>
<div
class="MuiTablePagination-root css-312mw9-MuiTablePagination-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular MuiTablePagination-toolbar css-78c6dr-MuiToolbar-root-MuiTablePagination-toolbar"
>
<div
class="MuiTablePagination-spacer css-1psng7p-MuiTablePagination-spacer"
/>
<p
class="MuiTablePagination-selectLabel css-pdct74-MuiTablePagination-selectLabel"
id=":r1:"
>
Rows per page:
</p>
<div
class="MuiInputBase-root MuiInputBase-colorPrimary MuiTablePagination-input css-16c50h-MuiInputBase-root-MuiTablePagination-select"
>
<div
aria-controls=":r2:"
aria-expanded="false"
aria-haspopup="listbox"
aria-labelledby=":r1: :r0:"
class="MuiSelect-select MuiTablePagination-select MuiSelect-standard MuiInputBase-input css-194a1fa-MuiSelect-select-MuiInputBase-input"
id=":r0:"
role="combobox"
tabindex="0"
>
10
</div>
<input
aria-hidden="true"
aria-invalid="false"
class="MuiSelect-nativeInput css-yf8vq0-MuiSelect-nativeInput"
tabindex="-1"
value="10"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiSelect-icon MuiTablePagination-selectIcon MuiSelect-iconStandard css-pqjvzy-MuiSvgIcon-root-MuiSelect-icon"
data-testid="ArrowDropDownIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M7 10l5 5 5-5z"
/>
</svg>
</div>
<p
class="MuiTablePagination-displayedRows css-levciy-MuiTablePagination-displayedRows"
>
1–10 of 100
</p>
<div
class="MuiTablePagination-actions"
>
<button
aria-label="Go to previous page"
class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-colorInherit MuiIconButton-sizeMedium css-zylse7-MuiButtonBase-root-MuiIconButton-root"
disabled=""
tabindex="-1"
title="Go to previous page"
type="button"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="KeyboardArrowLeftIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"
/>
</svg>
</button>
<button
aria-label="Go to next page"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit MuiIconButton-sizeMedium css-zylse7-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
title="Go to next page"
type="button"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="KeyboardArrowRightIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"
/>
</svg>
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`[COMPONENTS]: TableSelectedAction component testing > matches snapshot 1`] = `
<div>
<div
class="MuiStack-root css-kp6p8-MuiStack-root"
>
<span
class="MuiButtonBase-root MuiCheckbox-root MuiCheckbox-indeterminate MuiCheckbox-colorPrimary MuiCheckbox-sizeMedium PrivateSwitchBase-root MuiCheckbox-root MuiCheckbox-indeterminate MuiCheckbox-colorPrimary MuiCheckbox-sizeMedium MuiCheckbox-root MuiCheckbox-indeterminate MuiCheckbox-colorPrimary MuiCheckbox-sizeMedium css-12wnr2w-MuiButtonBase-root-MuiCheckbox-root"
>
<input
class="PrivateSwitchBase-input css-1m9pwf3"
data-indeterminate="true"
type="checkbox"
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="IndeterminateCheckBoxIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z"
/>
</svg>
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</span>
<h6
class="MuiTypography-root MuiTypography-subtitle2 css-1kwcz3m-MuiTypography-root"
>
5
selected
</h6>
</div>
</div>
`;
47 changes: 47 additions & 0 deletions src/components/table/__test__/table-empty-rows.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { render } from '@testing-library/react';
import TableEmptyRows from '../table-empty-rows';

describe('[COMPONENTS]: TableEmptyRows component testing', () => {
it('to match snapshot', () => {
const { container } = render(
<TableEmptyRows emptyRows={3} height={50} />
);
expect(container).toMatchSnapshot();
});

it('renders a TableRow when emptyRows is positive', () => {
const { container } = render(<TableEmptyRows emptyRows={2} />);
const tableRow = container.querySelector('tr');
expect(tableRow).toBeInTheDocument();
});

it('applies height style when height prop is provided', () => {
const { container } = render(<TableEmptyRows emptyRows={2} height={40} />);
const tableRow = container.querySelector('tr');
expect(tableRow).toHaveStyle('height: 80px');
});

it('returns null when emptyRows is 0', () => {
const { container } = render(<TableEmptyRows emptyRows={0} />);
expect(container.firstChild).toBeNull();
});

it('creates TableCell with colspan of 9', () => {
const { container } = render(<TableEmptyRows emptyRows={1} />);
const tableCell = container.querySelector('td');
expect(tableCell).toHaveAttribute('colspan', '9');
});


it('handles negative emptyRows by rendering a row', () => {
const { container } = render(<TableEmptyRows emptyRows={-1} />);
const tableRow = container.querySelector('tr');
expect(tableRow).toBeInTheDocument();
});

it('does not apply calculated height style when height prop is not provided', () => {
const { container } = render(<TableEmptyRows emptyRows={3} />);
const tableRow = container.querySelector('tr');
expect(tableRow).not.toHaveAttribute('style', expect.stringContaining('height'));
});
});
Loading
Loading