Skip to content

Commit

Permalink
Adding functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ofiriro3 committed Jan 12, 2023
1 parent 52ac325 commit 75aac4a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
},

getColumnValues: async (columnName: string) => {
const elementsWithNoFilterCell = ['CIS Section'];
const tableElement = await table.getElement();
const columnIndex = await table.getColumnIndex(columnName);
const columnCells = await tableElement.findAllByCssSelector(
`tbody tr td:nth-child(${columnIndex}) div[data-test-subj="filter_cell_value"]`
);
const selector = elementsWithNoFilterCell.includes(columnName)
? `tbody tr td:nth-child(${columnIndex})`
: `tbody tr td:nth-child(${columnIndex}) div[data-test-subj="filter_cell_value"]`;
const columnCells = await tableElement.findAllByCssSelector(selector);

return await Promise.all(columnCells.map((cell) => cell.getVisibleText()));
},
Expand All @@ -125,16 +127,7 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
return values.includes(value);
},

assertColumnSort: async (columnName: string, direction: 'asc' | 'desc') => {
const values = (await table.getColumnValues(columnName)).filter(Boolean);
expect(values).to.not.be.empty();
const sorted = values
.slice()
.sort((a, b) => (direction === 'asc' ? a.localeCompare(b) : b.localeCompare(a)));
values.forEach((value, i) => expect(value).to.be(sorted[i]));
},

toggleColumnSortOrFail: async (columnName: string, direction: 'asc' | 'desc') => {
toggleColumnSort: async (columnName: string, direction: 'asc' | 'desc') => {
const element = await table.getColumnHeaderCell(columnName);
const currentSort = await element.getAttribute('aria-sort');
if (currentSort === 'none') {
Expand All @@ -155,7 +148,6 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
const nonStaleElement = await table.getColumnHeaderCell(columnName);
await nonStaleElement.click();
}
await table.assertColumnSort(columnName, direction);
},
};

Expand Down
39 changes: 30 additions & 9 deletions x-pack/test/cloud_security_posture_functional/pages/findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import Chance from 'chance';
import type { FtrProviderContext } from '../ftr_provider_context';

// eslint-disable-next-line import/no-default-export
Expand All @@ -14,14 +15,16 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const filterBar = getService('filterBar');
const retry = getService('retry');
const pageObjects = getPageObjects(['common', 'findings']);
const numberOfFindings = 10;
const chance = new Chance();

const data = Array.from({ length: 2 }, (_, id) => {
const data = Array.from({ length: numberOfFindings }, (_, id) => {
return {
resource: { id, name: `Resource ${id}` },
result: { evaluation: id === 0 ? 'passed' : 'failed' },
rule: {
name: `Rule ${id}`,
section: 'Kubelet',
section: chance.string({ pool: 'abcdefghABCDEFGH', length: 10 }),
tags: ['Kubernetes'],
type: 'process',
},
Expand All @@ -32,7 +35,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const ruleName2 = data[1].rule.name;

// Failing: See https://github.com/elastic/kibana/issues/147998
describe.skip('Findings Page', () => {
describe('Findings Page', () => {
let findings: typeof pageObjects.findings;
let table: typeof pageObjects.findings.table;
let distributionBar: typeof pageObjects.findings.distributionBar;
Expand Down Expand Up @@ -103,12 +106,30 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

describe('Table Sort', () => {
it('sorts by rule name', async () => {
await table.toggleColumnSortOrFail('Rule', 'asc');
});

it('sorts by resource name', async () => {
await table.toggleColumnSortOrFail('Resource Name', 'desc');
it('sorts by a column, should be case sensitive/insensitive depending on the column', async () => {
type SortDirection = 'asc' | 'desc';
type TestCase = [string, string, SortDirection, Intl.CollatorOptions];
const testCases: TestCase[] = [
['Rule', 'en', 'asc', {}],
['Rule', 'en', 'desc', {}],
['Resource Name', 'en', 'asc', {}],
['Resource Name', 'en', 'desc', {}],
['CIS Section', 'en', 'desc', { sensitivity: 'base' }],
['CIS Section', 'en', 'desc', { sensitivity: 'base' }],
];
for (const [columnName, locale, dir, sortingOptions] of testCases) {
await table.toggleColumnSort(columnName, dir);
const values = (await table.getColumnValues(columnName)).filter(Boolean);
expect(values).to.not.be.empty();
const sorted = values
.slice()
.sort((a, b) =>
dir === 'asc'
? a.localeCompare(b, locale, sortingOptions)
: b.localeCompare(a, locale, sortingOptions)
);
values.forEach((value, i) => expect(value).to.be(sorted[i]));
}
});
});

Expand Down

0 comments on commit 75aac4a

Please sign in to comment.