Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
adonispuente committed Jun 7, 2024
1 parent e3683ca commit 8c9e231
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exports[`DataCollectorsCard should render correctly - no data 1`] = `
>
<th
class="pf-v5-c-table__th"
scope="col"
tabindex="-1"
/>
<th
Expand Down Expand Up @@ -388,6 +389,7 @@ exports[`DataCollectorsCard should render correctly with data 1`] = `
>
<th
class="pf-v5-c-table__th"
scope="col"
tabindex="-1"
/>
<th
Expand Down Expand Up @@ -722,6 +724,7 @@ exports[`DataCollectorsCard should render custom collectors 1`] = `
>
<th
class="pf-v5-c-table__th"
scope="col"
tabindex="-1"
/>
<th
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ exports[`GeneralInformation should render correctly 1`] = `
>
<th
class="pf-v5-c-table__th"
scope="col"
tabindex="-1"
/>
<th
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ describe('Table Renders', () => {

await userEvent.click(screen.getByRole('button', { name: 'Edit' }));

expect(
screen.getAllByRole('button', { name: /options menu/i })
).toHaveLength(3);
screen
.getAllByRole('button', { name: /options menu/i })
.forEach((button) => expect(button).toBeEnabled());
expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled();
expect(screen.getByRole('button', { name: 'Cancel' })).toBeEnabled();
});
Expand Down
9 changes: 2 additions & 7 deletions src/components/InventoryTable/EntityTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { selectEntity, setSort } from '../../store/actions';
import { useDispatch, useSelector } from 'react-redux';
import { TableGridBreakpoint, TableVariant } from '@patternfly/react-table';
import {
Table as PfTable,
TableBody,
Expand Down Expand Up @@ -107,11 +106,7 @@ const EntityTable = ({
sortBy,
noSystemsTable,
})}
gridBreakPoint={
columns?.length > 5
? TableGridBreakpoint.gridLg
: TableGridBreakpoint.gridMd
}
gridBreakPoint={columns?.length > 5 ? 'grid-lg' : 'gird-md'}
className="ins-c-entity-table sentry-mask data-hj-suppress"
onSort={(event, index, direction) => {
onSortChange(
Expand Down Expand Up @@ -191,7 +186,7 @@ EntityTable.defaultProps = {
hasCheckbox: true,
showActions: false,
rows: [],
variant: TableVariant.compact,
variant: 'compact',
onExpandClick: () => undefined,
tableProps: {},
};
Expand Down
54 changes: 36 additions & 18 deletions src/components/InventoryTable/EntityTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,32 @@ const expectTableBasicComponents = (
expect(screen.getAllByRole('row')).toHaveLength(rowsNumber + 1); // + 1 to count in header row

if (columnNames !== undefined) {
screen.getAllByRole('columnheader').forEach((columnHeader, index) => {
expect(columnHeader).toHaveTextContent(columnNames[index]);
const columnHeaders = screen.getAllByRole('columnheader');
let filteredIndex = 0;

columnHeaders.forEach((columnHeader) => {
const dataKey = columnHeader.getAttribute('data-key');
if (!shouldRenderSelectAllCheckbox) {
// If we do not render the select all checkbox, we should not skip '0'
if (columnNames && columnNames[filteredIndex] !== undefined) {
expect(columnHeader).toHaveTextContent(columnNames[filteredIndex]);
filteredIndex++;
}
} else {
// If we render the select all checkbox, we should skip '0'
if (dataKey !== '0') {
if (columnNames && columnNames[filteredIndex] !== undefined) {
expect(columnHeader).toHaveTextContent(columnNames[filteredIndex]);
filteredIndex++;
}
}
}
});
}

expect(
screen.queryAllByRole('cell', {
name: 'Select all rows',
screen.queryAllByRole('checkbox', {
name: /select all rows/i,
})
).toHaveLength(shouldRenderSelectAllCheckbox ? 1 : 0);

Expand Down Expand Up @@ -178,7 +196,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
6,
7,
1,
[...new Array(6)].map(() => 'One'),
true,
Expand Down Expand Up @@ -208,7 +226,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true);
expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true);
});

it('should render correctly - with actions', () => {
Expand All @@ -221,7 +239,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
2,
3,
1,
['One', 'OS'],
true,
Expand Down Expand Up @@ -249,7 +267,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(2, 1, ['One', 'OS'], true, true);
expectTableBasicComponents(3, 1, ['One', 'OS'], true, true);
expect(
screen.getByRole('columnheader', {
name: 'One',
Expand Down Expand Up @@ -309,7 +327,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true);
expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true);
expect(
screen.getByRole('columnheader', {
name: 'One',
Expand Down Expand Up @@ -339,7 +357,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true);
expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true);
expect(
screen.getByRole('columnheader', {
name: 'OS',
Expand Down Expand Up @@ -369,7 +387,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true);
expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true);
expect(
screen.getByRole('columnheader', {
name: 'OS',
Expand All @@ -391,7 +409,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(2, 1, ['One', 'OS'], true, true);
expectTableBasicComponents(3, 1, ['One', 'OS'], true, true);
expect(screen.getByRole('grid', { name: 'Host inventory' })).toHaveClass(
'pf-m-compact'
);
Expand All @@ -406,7 +424,7 @@ describe('EntityTable', () => {
</TestWrapper>
);

expectTableBasicComponents(2, 1, ['One', 'OS'], true, true);
expectTableBasicComponents(3, 1, ['One', 'OS'], true, true);
screen
.getAllByRole('columnheader')
.forEach((header) =>
Expand Down Expand Up @@ -451,7 +469,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
5,
6,
2,
['Name', 'Group', 'Tags', 'OS', 'Last seen'],
true,
Expand Down Expand Up @@ -511,7 +529,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
5,
6,
2,
['Name', 'Group', 'OS', 'Last seen', 'Secret attribute'],
true,
Expand Down Expand Up @@ -571,7 +589,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
2,
3,
1,
['Display name', 'Secret attribute'],
true,
Expand Down Expand Up @@ -660,7 +678,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
3,
4,
1,
['Group', 'OS', 'Last seen'],
true,
Expand Down Expand Up @@ -697,7 +715,7 @@ describe('EntityTable', () => {
);

expectTableBasicComponents(
4,
5,
1,
['Group', 'Tags', 'OS', 'Last seen'],
true,
Expand Down

0 comments on commit 8c9e231

Please sign in to comment.