Skip to content

Commit

Permalink
fix datagrid functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Feb 1, 2021
1 parent 5021c07 commit 687bd60
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
44 changes: 21 additions & 23 deletions test/functional/services/data_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Public License, v 1.
*/

import { chunk } from 'lodash';
import { FtrProviderContext } from '../ftr_provider_context';
import { WebElementWrapper } from './lib/web_element_wrapper';

Expand All @@ -31,14 +32,11 @@ export function DataGridProvider({ getService, getPageObjects }: FtrProviderCont
const columns = $('.euiDataGridHeaderCell__content')
.toArray()
.map((cell) => $(cell).text());
const rows = $.findTestSubjects('dataGridRow')
const cells = $.findTestSubjects('dataGridRowCell')
.toArray()
.map((row) =>
$(row)
.find('.euiDataGridRowCell__truncate')
.toArray()
.map((cell) => $(cell).text())
);
.map((cell) => $(cell).text());

const rows = chunk(cells, columns.length);

return {
columns,
Expand All @@ -56,20 +54,18 @@ export function DataGridProvider({ getService, getPageObjects }: FtrProviderCont
cellDataTestSubj: string
): Promise<string[][]> {
const $ = await element.parseDomContent();
return $('[data-test-subj="dataGridRow"]')
const columnNumber = $('.euiDataGridHeaderCell__content').length;
const cells = $.findTestSubjects('dataGridRowCell')
.toArray()
.map((row) =>
$(row)
.findTestSubjects('dataGridRowCell')
.toArray()
.map((cell) =>
$(cell)
.findTestSubject(cellDataTestSubj)
.text()
.replace(/&nbsp;/g, '')
.trim()
)
.map((cell) =>
$(cell)
.findTestSubject(cellDataTestSubj)
.text()
.replace(/&nbsp;/g, '')
.trim()
);

return chunk(cells, columnNumber);
}

/**
Expand All @@ -90,11 +86,13 @@ export function DataGridProvider({ getService, getPageObjects }: FtrProviderCont
* @param columnIndex column index starting from 1 (1 means 1st column)
*/
public async getCellElement(rowIndex: number, columnIndex: number) {
const table = await find.byCssSelector('.euiDataGrid');
const $ = await table.parseDomContent();
const columnNumber = $('.euiDataGridHeaderCell__content').length;
return await find.byCssSelector(
`[data-test-subj="dataGridWrapper"] [data-test-subj="dataGridRow"]:nth-of-type(${
rowIndex + 1
})
[data-test-subj="dataGridRowCell"]:nth-of-type(${columnIndex})`
`[data-test-subj="dataGridWrapper"] [data-test-subj="dataGridRowCell"]:nth-of-type(${
columnNumber * rowIndex + columnIndex + 2
})`
);
}
public async getFields() {
Expand Down
17 changes: 10 additions & 7 deletions x-pack/test/functional/apps/lens/smokescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['visualize', 'lens', 'common', 'header']);
const find = getService('find');
const retry = getService('retry');
const listingTable = getService('listingTable');
const testSubjects = getService('testSubjects');
const elasticChart = getService('elasticChart');
Expand Down Expand Up @@ -588,13 +589,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should able to use filters cell actions in table', async () => {
const firstCellContent = await PageObjects.lens.getDatatableCellText(0, 0);
await PageObjects.lens.clickTableCellAction(0, 0, 'lensDatatableFilterOut');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(
await find.existsByCssSelector(
`[data-test-subj*="filter-value-${firstCellContent}"][data-test-subj*="filter-negated"]`
)
).to.eql(true);
await retry.try(async () => {
await PageObjects.lens.clickTableCellAction(0, 0, 'lensDatatableFilterOut');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(
await find.existsByCssSelector(
`[data-test-subj*="filter-value-${firstCellContent}"][data-test-subj*="filter-negated"]`
)
).to.eql(true);
});
});
});
}
9 changes: 6 additions & 3 deletions x-pack/test/functional/page_objects/lens_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,13 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
},

async getDatatableCell(rowIndex = 0, colIndex = 0) {
const table = await find.byCssSelector('.euiDataGrid');
const $ = await table.parseDomContent();
const columnNumber = $('.euiDataGridHeaderCell__content').length;
return await find.byCssSelector(
`[data-test-subj="lnsDataTable"] [data-test-subj="dataGridRow"]:nth-child(${
rowIndex + 2 // this is a bit specific for EuiDataGrid: the first row is the Header
}) [data-test-subj="dataGridRowCell"]:nth-child(${colIndex + 1})`
`[data-test-subj="lnsDataTable"] [data-test-subj="dataGridRowCell"]:nth-child(${
rowIndex * columnNumber + colIndex + 2
})`
);
},

Expand Down

0 comments on commit 687bd60

Please sign in to comment.