Skip to content

Commit c4e7b05

Browse files
committed
[Unified Data Table] Improve failing test speed (elastic#243168)
## Summary Closes elastic#234829 Closes elastic#240905 Closes elastic#240904 All 3 tests were timing out so lets try to improve how fast they run - for this this PR changes from `get/queryByRole` to `get/queryByTestId` as it speeds up the tests significantly. Times measured isolating the tests using `it.only` and using the mean time of 10 runs + mean time of 10 runs of the whole file. > [!NOTE] > Both scripts to measure the test times were generated by ChatGPT Individual tests where measured with this script + `it.only`: [run-tests.sh](https://github.com/user-attachments/files/23580522/run-tests.sh) The whole test file was measured using this script: [all-tests.sh](https://github.com/user-attachments/files/23580737/all-tests.sh) | Test | Before | After | |--|--------|------| | should show the reset width button only for absolute width columns, and allow resetting to default width | 1268ms | 637ms | | should not reset the last column to auto width when there are remaining auto width columns | 894ms | 346ms | | should reset the last column to auto width if only absolute width columns remain | 893ms | 359ms | | All tests | 21.069s | 17.338s | ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit 94c5602)
1 parent a061701 commit c4e7b05

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/platform/packages/shared/kbn-unified-data-table/src/components/__snapshots__/data_table_columns.test.tsx.snap

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/platform/packages/shared/kbn-unified-data-table/src/components/data_table.test.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,18 +1307,13 @@ describe('UnifiedDataTable', () => {
13071307
describe('columns', () => {
13081308
// Default column width in EUI is hardcoded to 100px for Jest envs
13091309
const EUI_DEFAULT_COLUMN_WIDTH = '100px';
1310-
const getColumnHeader = (name: string) => screen.getByRole('columnheader', { name });
1311-
const queryColumnHeader = (name: string) => screen.queryByRole('columnheader', { name });
1310+
const getColumnHeader = (name: string) => screen.getByTestId(`dataGridHeaderCell-${name}`);
1311+
const queryColumnHeader = (name: string) => screen.queryByTestId(`dataGridHeaderCell-${name}`);
13121312
const openColumnActions = async (name: string) => {
13131313
const actionsButton = screen.getByTestId(`dataGridHeaderCellActionButton-${name}`);
13141314
await userEvent.click(actionsButton);
13151315
await waitForEuiPopoverOpen();
13161316
};
1317-
const clickColumnAction = async (name: string) => {
1318-
const action = screen.getByRole('button', { name });
1319-
await userEvent.click(action);
1320-
};
1321-
const queryButton = (name: string) => screen.queryByRole('button', { name });
13221317

13231318
it(
13241319
'should reset the last column to auto width if only absolute width columns remain',
@@ -1336,7 +1331,7 @@ describe('UnifiedDataTable', () => {
13361331
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
13371332
expect(getColumnHeader('bytes')).toHaveStyle({ width: '50px' });
13381333
await openColumnActions('message');
1339-
await clickColumnAction('Remove column');
1334+
await userEvent.click(screen.getByTestId('unifiedDataTableRemoveColumn'));
13401335
await waitFor(() => {
13411336
expect(queryColumnHeader('message')).not.toBeInTheDocument();
13421337
});
@@ -1361,7 +1356,7 @@ describe('UnifiedDataTable', () => {
13611356
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
13621357
expect(getColumnHeader('bytes')).toHaveStyle({ width: '50px' });
13631358
await openColumnActions('message');
1364-
await clickColumnAction('Remove column');
1359+
await userEvent.click(screen.getByTestId('unifiedDataTableRemoveColumn'));
13651360
await waitFor(() => {
13661361
expect(queryColumnHeader('message')).not.toBeInTheDocument();
13671362
});
@@ -1384,24 +1379,21 @@ describe('UnifiedDataTable', () => {
13841379
},
13851380
});
13861381
expect(getColumnHeader('@timestamp')).toHaveStyle({ width: '50px' });
1382+
13871383
await openColumnActions('@timestamp');
1388-
await clickColumnAction('Reset width');
1389-
await waitFor(() => {
1390-
expect(getColumnHeader('@timestamp')).toHaveStyle({
1391-
width: `${defaultTimeColumnWidth}px`,
1392-
});
1384+
await userEvent.click(screen.getByTestId('unifiedDataTableResetColumnWidth'));
1385+
expect(getColumnHeader('@timestamp')).toHaveStyle({
1386+
width: `${defaultTimeColumnWidth}px`,
13931387
});
1388+
13941389
expect(getColumnHeader('message')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
13951390
await openColumnActions('message');
1396-
expect(queryButton('Reset width')).not.toBeInTheDocument();
1397-
await waitFor(() => {
1398-
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
1399-
});
1391+
expect(screen.queryByTestId('unifiedDataTableResetColumnWidth')).not.toBeInTheDocument();
1392+
1393+
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
14001394
await openColumnActions('extension');
1401-
await clickColumnAction('Reset width');
1402-
await waitFor(() => {
1403-
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
1404-
});
1395+
await userEvent.click(screen.getByTestId('unifiedDataTableResetColumnWidth'));
1396+
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
14051397
},
14061398
EXTENDED_JEST_TIMEOUT
14071399
);

src/platform/packages/shared/kbn-unified-data-table/src/components/data_table_columns.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function buildEuiGridColumn({
244244
defaultMessage: 'Remove column',
245245
}),
246246
iconType: 'cross',
247+
'data-test-subj': 'unifiedDataTableRemoveColumn',
247248
},
248249
showMoveLeft: !defaultColumns,
249250
showMoveRight: !defaultColumns,

0 commit comments

Comments
 (0)