From 8c9e231da163bb1ecb5a7b23bcd9b087c61e863f Mon Sep 17 00:00:00 2001 From: Adonis Puente Date: Fri, 7 Jun 2024 10:33:35 +0200 Subject: [PATCH] update test --- .../DataCollectorsCard.test.js.snap | 3 ++ .../GeneralInformation.test.js.snap | 1 + .../__test__/InventoryHostStaleness.test.js | 6 --- src/components/InventoryTable/EntityTable.js | 9 +--- .../InventoryTable/EntityTable.test.js | 54 ++++++++++++------- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/components/GeneralInfo/DataCollectorsCard/__snapshots__/DataCollectorsCard.test.js.snap b/src/components/GeneralInfo/DataCollectorsCard/__snapshots__/DataCollectorsCard.test.js.snap index a4179e5da..69b4937f3 100644 --- a/src/components/GeneralInfo/DataCollectorsCard/__snapshots__/DataCollectorsCard.test.js.snap +++ b/src/components/GeneralInfo/DataCollectorsCard/__snapshots__/DataCollectorsCard.test.js.snap @@ -54,6 +54,7 @@ exports[`DataCollectorsCard should render correctly - no data 1`] = ` > { 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(); }); diff --git a/src/components/InventoryTable/EntityTable.js b/src/components/InventoryTable/EntityTable.js index a3666e3e3..1fc529f60 100644 --- a/src/components/InventoryTable/EntityTable.js +++ b/src/components/InventoryTable/EntityTable.js @@ -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, @@ -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( @@ -191,7 +186,7 @@ EntityTable.defaultProps = { hasCheckbox: true, showActions: false, rows: [], - variant: TableVariant.compact, + variant: 'compact', onExpandClick: () => undefined, tableProps: {}, }; diff --git a/src/components/InventoryTable/EntityTable.test.js b/src/components/InventoryTable/EntityTable.test.js index d27521307..d7b2e30bf 100644 --- a/src/components/InventoryTable/EntityTable.test.js +++ b/src/components/InventoryTable/EntityTable.test.js @@ -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); @@ -178,7 +196,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 6, + 7, 1, [...new Array(6)].map(() => 'One'), true, @@ -208,7 +226,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true); + expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true); }); it('should render correctly - with actions', () => { @@ -221,7 +239,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 2, + 3, 1, ['One', 'OS'], true, @@ -249,7 +267,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(2, 1, ['One', 'OS'], true, true); + expectTableBasicComponents(3, 1, ['One', 'OS'], true, true); expect( screen.getByRole('columnheader', { name: 'One', @@ -309,7 +327,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true); + expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true); expect( screen.getByRole('columnheader', { name: 'One', @@ -339,7 +357,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true); + expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true); expect( screen.getByRole('columnheader', { name: 'OS', @@ -369,7 +387,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(3, 1, ['', 'One', 'OS'], true, true); + expectTableBasicComponents(4, 1, ['', 'One', 'OS'], true, true); expect( screen.getByRole('columnheader', { name: 'OS', @@ -391,7 +409,7 @@ describe('EntityTable', () => { ); - 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' ); @@ -406,7 +424,7 @@ describe('EntityTable', () => { ); - expectTableBasicComponents(2, 1, ['One', 'OS'], true, true); + expectTableBasicComponents(3, 1, ['One', 'OS'], true, true); screen .getAllByRole('columnheader') .forEach((header) => @@ -451,7 +469,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 5, + 6, 2, ['Name', 'Group', 'Tags', 'OS', 'Last seen'], true, @@ -511,7 +529,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 5, + 6, 2, ['Name', 'Group', 'OS', 'Last seen', 'Secret attribute'], true, @@ -571,7 +589,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 2, + 3, 1, ['Display name', 'Secret attribute'], true, @@ -660,7 +678,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 3, + 4, 1, ['Group', 'OS', 'Last seen'], true, @@ -697,7 +715,7 @@ describe('EntityTable', () => { ); expectTableBasicComponents( - 4, + 5, 1, ['Group', 'Tags', 'OS', 'Last seen'], true,