Skip to content

Commit 85002f8

Browse files
AlexGPlayeokoneyo
authored andcommitted
[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
1 parent c2f0090 commit 85002f8

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
@@ -1310,18 +1310,13 @@ describe('UnifiedDataTable', () => {
13101310
describe('columns', () => {
13111311
// Default column width in EUI is hardcoded to 100px for Jest envs
13121312
const EUI_DEFAULT_COLUMN_WIDTH = '100px';
1313-
const getColumnHeader = (name: string) => screen.getByRole('columnheader', { name });
1314-
const queryColumnHeader = (name: string) => screen.queryByRole('columnheader', { name });
1313+
const getColumnHeader = (name: string) => screen.getByTestId(`dataGridHeaderCell-${name}`);
1314+
const queryColumnHeader = (name: string) => screen.queryByTestId(`dataGridHeaderCell-${name}`);
13151315
const openColumnActions = async (name: string) => {
13161316
const actionsButton = screen.getByTestId(`dataGridHeaderCellActionButton-${name}`);
13171317
await userEvent.click(actionsButton);
13181318
await waitForEuiPopoverOpen();
13191319
};
1320-
const clickColumnAction = async (name: string) => {
1321-
const action = screen.getByRole('button', { name });
1322-
await userEvent.click(action);
1323-
};
1324-
const queryButton = (name: string) => screen.queryByRole('button', { name });
13251320

13261321
it(
13271322
'should reset the last column to auto width if only absolute width columns remain',
@@ -1339,7 +1334,7 @@ describe('UnifiedDataTable', () => {
13391334
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
13401335
expect(getColumnHeader('bytes')).toHaveStyle({ width: '50px' });
13411336
await openColumnActions('message');
1342-
await clickColumnAction('Remove column');
1337+
await userEvent.click(screen.getByTestId('unifiedDataTableRemoveColumn'));
13431338
await waitFor(() => {
13441339
expect(queryColumnHeader('message')).not.toBeInTheDocument();
13451340
});
@@ -1364,7 +1359,7 @@ describe('UnifiedDataTable', () => {
13641359
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
13651360
expect(getColumnHeader('bytes')).toHaveStyle({ width: '50px' });
13661361
await openColumnActions('message');
1367-
await clickColumnAction('Remove column');
1362+
await userEvent.click(screen.getByTestId('unifiedDataTableRemoveColumn'));
13681363
await waitFor(() => {
13691364
expect(queryColumnHeader('message')).not.toBeInTheDocument();
13701365
});
@@ -1387,24 +1382,21 @@ describe('UnifiedDataTable', () => {
13871382
},
13881383
});
13891384
expect(getColumnHeader('@timestamp')).toHaveStyle({ width: '50px' });
1385+
13901386
await openColumnActions('@timestamp');
1391-
await clickColumnAction('Reset width');
1392-
await waitFor(() => {
1393-
expect(getColumnHeader('@timestamp')).toHaveStyle({
1394-
width: `${defaultTimeColumnWidth}px`,
1395-
});
1387+
await userEvent.click(screen.getByTestId('unifiedDataTableResetColumnWidth'));
1388+
expect(getColumnHeader('@timestamp')).toHaveStyle({
1389+
width: `${defaultTimeColumnWidth}px`,
13961390
});
1391+
13971392
expect(getColumnHeader('message')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
13981393
await openColumnActions('message');
1399-
expect(queryButton('Reset width')).not.toBeInTheDocument();
1400-
await waitFor(() => {
1401-
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
1402-
});
1394+
expect(screen.queryByTestId('unifiedDataTableResetColumnWidth')).not.toBeInTheDocument();
1395+
1396+
expect(getColumnHeader('extension')).toHaveStyle({ width: '50px' });
14031397
await openColumnActions('extension');
1404-
await clickColumnAction('Reset width');
1405-
await waitFor(() => {
1406-
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
1407-
});
1398+
await userEvent.click(screen.getByTestId('unifiedDataTableResetColumnWidth'));
1399+
expect(getColumnHeader('extension')).toHaveStyle({ width: EUI_DEFAULT_COLUMN_WIDTH });
14081400
},
14091401
EXTENDED_JEST_TIMEOUT
14101402
);

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)