[Cloud Posture] Add test for filtering findings by evaluation (#146452)

This commit is contained in:
Or Ouziel 2022-12-01 14:56:04 +02:00 committed by GitHub
parent f3d12b33e6
commit 7e035f4189
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 2 deletions

View file

@ -24,7 +24,11 @@ const getColor = (type: Props['type']): EuiBadgeProps['color'] => {
};
export const CspEvaluationBadge = ({ type }: Props) => (
<EuiBadge color={getColor(type)} style={{ width: BADGE_WIDTH, textAlign: 'center' }}>
<EuiBadge
color={getColor(type)}
style={{ width: BADGE_WIDTH, textAlign: 'center' }}
data-test-subj={`${type}_finding`}
>
{type === 'failed' ? (
<FormattedMessage id="xpack.csp.cspEvaluationBadge.failLabel" defaultMessage="Fail" />
) : (

View file

@ -126,6 +126,7 @@ const DistributionBar: React.FC<Omit<Props, 'pageEnd' | 'pageStart'>> = ({
distributionOnClick={() => {
distributionOnClick(RULE_PASSED);
}}
data-test-subj="distribution_bar_passed"
/>
<DistributionBarPart
value={failed}
@ -133,6 +134,7 @@ const DistributionBar: React.FC<Omit<Props, 'pageEnd' | 'pageStart'>> = ({
distributionOnClick={() => {
distributionOnClick(RULE_FAILED);
}}
data-test-subj="distribution_bar_failed"
/>
</EuiFlexGroup>
);
@ -142,12 +144,15 @@ const DistributionBarPart = ({
value,
color,
distributionOnClick,
...rest
}: {
value: number;
color: string;
distributionOnClick: () => void;
['data-test-subj']: string;
}) => (
<button
data-test-subj={rest['data-test-subj']}
onClick={distributionOnClick}
css={css`
flex: ${value};

View file

@ -47,6 +47,11 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
},
};
const distributionBar = {
filterBy: async (type: 'passed' | 'failed') =>
testSubjects.click(type === 'failed' ? 'distribution_bar_failed' : 'distribution_bar_passed'),
};
const table = {
getElement: () => testSubjects.find('findings_table'),
@ -76,6 +81,12 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
return rows.length;
},
getFindingsCount: async (type: 'passed' | 'failed') => {
const element = await table.getElement();
const items = await element.findAllByCssSelector(`span[data-test-subj="${type}_finding"]`);
return items.length;
},
getRowIndexForValue: async (columnName: string, value: string) => {
const values = await table.getColumnValues(columnName);
const rowIndex = values.indexOf(value);
@ -160,5 +171,6 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
navigateToFindingsPage,
table,
index,
distributionBar,
};
}

View file

@ -18,7 +18,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const data = Array.from({ length: 2 }, (_, id) => {
return {
resource: { id, name: `Resource ${id}` },
result: { evaluation: 'passed' },
result: { evaluation: id === 0 ? 'passed' : 'failed' },
rule: {
name: `Rule ${id}`,
section: 'Kubelet',
@ -34,10 +34,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
describe('Findings Page', () => {
let findings: typeof pageObjects.findings;
let table: typeof pageObjects.findings.table;
let distributionBar: typeof pageObjects.findings.distributionBar;
before(async () => {
findings = pageObjects.findings;
table = pageObjects.findings.table;
distributionBar = pageObjects.findings.distributionBar;
await findings.index.add(data);
await findings.navigateToFindingsPage();
@ -108,5 +110,18 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await table.toggleColumnSortOrFail('Resource Name', 'desc');
});
});
describe('DistributionBar', () => {
(['passed', 'failed'] as const).forEach((type) => {
it(`filters by ${type} findings`, async () => {
await distributionBar.filterBy(type);
const items = data.filter(({ result }) => result.evaluation === type);
expect(await table.getFindingsCount(type)).to.eql(items.length);
await filterBar.removeFilter('result.evaluation');
});
});
});
});
}