Address PR comments from merge (#150089)

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.
Merged [PR](https://github.com/elastic/kibana/pull/149716) before seeing
Or's comments. I created a follow-up chore PR to clean and address his
comments.

*  Rename `getResourceFindingsTableFixture` to `getFindingsFixture`
*  Update other `getFindingsFixture`
*  Update unit test description
*  Revert typing to `ResourceFindingsResponseAggs` with an undefined 
*  Clean up translation
This commit is contained in:
Lola 2023-02-01 15:40:15 -05:00 committed by GitHub
parent e45f91897c
commit 33f7509c78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 86 deletions

View file

@ -11,65 +11,11 @@ import * as TEST_SUBJECTS from '../test_subjects';
import { FindingsTable } from './latest_findings_table';
import type { PropsOf } from '@elastic/eui';
import Chance from 'chance';
import type { EcsEvent } from '@kbn/ecs';
import { TestProvider } from '../../../test/test_provider';
import { CspFinding } from '../../../../common/schemas/csp_finding';
import { getFindingsFixture } from '../../../test/fixtures/findings_fixture';
const chance = new Chance();
const getFakeFindings = (name: string): CspFinding & { id: string } => ({
cluster_id: chance.guid(),
id: chance.word(),
result: {
expected: {
source: {},
},
evaluation: chance.weighted(['passed', 'failed'], [0.5, 0.5]),
evidence: {
filemode: chance.word(),
},
},
rule: {
audit: chance.paragraph(),
benchmark: {
rule_number: '1.1.1',
name: 'CIS Kubernetes',
version: '1.6.0',
id: 'cis_k8s',
},
default_value: chance.sentence(),
description: chance.paragraph(),
id: chance.guid(),
impact: chance.word(),
name,
profile_applicability: chance.sentence(),
rationale: chance.paragraph(),
references: chance.paragraph(),
rego_rule_id: 'cis_X_X_X',
remediation: chance.word(),
section: chance.sentence(),
tags: [],
version: '1.0',
},
agent: {
id: chance.string(),
name: chance.string(),
type: chance.string(),
version: chance.string(),
},
resource: {
name: chance.string(),
type: chance.string(),
raw: {} as any,
sub_type: chance.string(),
id: chance.string(),
},
host: {} as any,
ecs: {} as any,
event: {} as EcsEvent,
'@timestamp': new Date().toISOString(),
});
type TableProps = PropsOf<typeof FindingsTable>;
describe('<FindingsTable />', () => {
@ -96,7 +42,7 @@ describe('<FindingsTable />', () => {
it('renders the table with provided items', () => {
const names = chance.unique(chance.sentence, 10);
const data = names.map(getFakeFindings);
const data = names.map(getFindingsFixture);
const props: TableProps = {
loading: false,
@ -120,7 +66,7 @@ describe('<FindingsTable />', () => {
it('adds filter with a cell button click', () => {
const names = chance.unique(chance.sentence, 10);
const data = names.map(getFakeFindings);
const data = names.map(getFindingsFixture);
const filterProps = { onAddFilter: jest.fn() };
const props: TableProps = {

View file

@ -135,16 +135,6 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
}),
});
};
function resourceFindingsPageTitleTranslation(resourceName: string | undefined) {
return i18n.translate('xpack.csp.findings.resourceFindings.resourceFindingsPageTitle', {
defaultMessage: '{resourceName} {hyphen} Findings',
values: {
resourceName,
hyphen: resourceFindings.data?.resourceName ? '-' : '',
},
});
}
return (
<div data-test-subj={TEST_SUBJECTS.FINDINGS_CONTAINER}>
<FindingsSearchBar
@ -159,7 +149,16 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
<PageTitleText
title={
<CloudPosturePageTitle
title={resourceFindingsPageTitleTranslation(resourceFindings.data?.resourceName)}
title={i18n.translate(
'xpack.csp.findings.resourceFindings.resourceFindingsPageTitle',
{
defaultMessage: '{resourceName} {hyphen} Findings',
values: {
resourceName: resourceFindings.data?.resourceName,
hyphen: resourceFindings.data?.resourceName ? '-' : '',
},
}
)}
/>
}
/>
@ -170,9 +169,9 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
<CspInlineDescriptionList
listItems={getResourceFindingSharedValues({
resourceId: params.resourceId,
resourceName: resourceFindings.data.resourceName,
resourceSubType: resourceFindings.data.resourceSubType,
clusterId: resourceFindings.data.clusterId,
resourceName: resourceFindings.data?.resourceName || '',
resourceSubType: resourceFindings.data?.resourceSubType || '',
clusterId: resourceFindings.data?.clusterId || '',
})}
/>
)

View file

@ -12,7 +12,7 @@ import { TestProvider } from '../../../../test/test_provider';
import { capitalize } from 'lodash';
import moment from 'moment';
import { getResourceFindingsTableFixture } from '../../../../test/fixtures/resource_findings_fixture';
import { getFindingsFixture } from '../../../../test/fixtures/findings_fixture';
describe('<ResourceFindingsTable />', () => {
it('should render no findings empty state when status success and data has a length of zero ', async () => {
@ -38,8 +38,8 @@ describe('<ResourceFindingsTable />', () => {
).toBeInTheDocument();
});
it('should render resource finding table content when data items exists', () => {
const data = Array.from({ length: 10 }, getResourceFindingsTableFixture);
it('should render resource finding table content when data has a non zero length', () => {
const data = Array.from({ length: 10 }, getFindingsFixture);
const props: ResourceFindingsTableProps = {
loading: false,

View file

@ -34,12 +34,12 @@ type ResourceFindingsResponse = IKibanaSearchResponse<
estypes.SearchResponse<CspFinding, ResourceFindingsResponseAggs>
>;
export interface ResourceFindingsResponseAggs {
count?: estypes.AggregationsMultiBucketAggregateBase<estypes.AggregationsStringRareTermsBucketKeys>;
clusterId?: estypes.AggregationsMultiBucketAggregateBase<estypes.AggregationsStringRareTermsBucketKeys>;
resourceSubType?: estypes.AggregationsMultiBucketAggregateBase<estypes.AggregationsStringRareTermsBucketKeys>;
resourceName?: estypes.AggregationsMultiBucketAggregateBase<estypes.AggregationsStringRareTermsBucketKeys>;
}
export type ResourceFindingsResponseAggs = Record<
'count' | 'clusterId' | 'resourceSubType' | 'resourceName',
estypes.AggregationsMultiBucketAggregateBase<
estypes.AggregationsStringRareTermsBucketKeys | undefined
>
>;
const getResourceFindingsQuery = ({
query,
@ -119,5 +119,6 @@ function assertNonBucketsArray<T>(arr: unknown): asserts arr is T[] {
}
}
const getFirstBucketKey = (buckets: estypes.AggregationsStringRareTermsBucketKeys[]): string =>
buckets[0]?.key;
const getFirstBucketKey = (
buckets: Array<estypes.AggregationsStringRareTermsBucketKeys | undefined>
): string | undefined => buckets[0]?.key;

View file

@ -120,9 +120,11 @@ export const getFindingsCountAggQuery = () => ({
count: { terms: { field: 'result.evaluation' } },
});
export const getAggregationCount = (buckets: estypes.AggregationsStringRareTermsBucketKeys[]) => {
const passed = buckets.find((bucket) => bucket.key === 'passed');
const failed = buckets.find((bucket) => bucket.key === 'failed');
export const getAggregationCount = (
buckets: Array<estypes.AggregationsStringRareTermsBucketKeys | undefined>
) => {
const passed = buckets.find((bucket) => bucket?.key === 'passed');
const failed = buckets.find((bucket) => bucket?.key === 'failed');
return {
passed: passed?.doc_count || 0,

View file

@ -11,7 +11,7 @@ import { CspFinding } from '../../../common/schemas/csp_finding';
const chance = new Chance();
export const getResourceFindingsTableFixture = (): CspFinding & { id: string } => ({
export const getFindingsFixture = (): CspFinding & { id: string } => ({
cluster_id: chance.guid(),
id: chance.word(),
result: {