-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cloud Posture] [Quick wins] Enable edit DataView on the Misconfigurations Findings Table #173870
Changes from 8 commits
a952cb6
b04a416
97c1107
eb128b6
72ab545
d67937a
f4c0a4e
2b783e3
609f862
08e3cbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TestProvider } from '../../test/test_provider'; | ||
import { CloudSecurityDataTable, CloudSecurityDataTableProps } from './cloud_security_data_table'; | ||
|
||
const mockDataView = { | ||
fields: { | ||
getAll: () => [ | ||
{ id: 'field1', name: 'field1', customLabel: 'Label 1', visualizable: true }, | ||
{ id: 'field2', name: 'field2', customLabel: 'Label 2', visualizable: true }, | ||
], | ||
getByName: (name: string) => ({ id: name }), | ||
}, | ||
getFieldByName: (name: string) => ({ id: name }), | ||
getFormatterForField: (name: string) => ({ | ||
convert: (value: string) => value, | ||
}), | ||
} as any; | ||
|
||
const mockDefaultColumns = [{ id: 'field1' }, { id: 'field2' }]; | ||
|
||
const mockCloudPostureDataTable = { | ||
setUrlQuery: jest.fn(), | ||
columnsLocalStorageKey: 'test', | ||
filters: [], | ||
onSort: jest.fn(), | ||
sort: [], | ||
query: {}, | ||
queryError: undefined, | ||
pageIndex: 0, | ||
urlQuery: {}, | ||
setTableOptions: jest.fn(), | ||
handleUpdateQuery: jest.fn(), | ||
pageSize: 10, | ||
setPageSize: jest.fn(), | ||
onChangeItemsPerPage: jest.fn(), | ||
onChangePage: jest.fn(), | ||
onResetFilters: jest.fn(), | ||
getRowsFromPages: jest.fn(), | ||
} as any; | ||
|
||
const renderDataTable = (props: Partial<CloudSecurityDataTableProps> = {}) => { | ||
const defaultProps: CloudSecurityDataTableProps = { | ||
dataView: mockDataView, | ||
isLoading: false, | ||
defaultColumns: mockDefaultColumns, | ||
rows: [], | ||
total: 0, | ||
flyoutComponent: () => <></>, | ||
cloudPostureDataTable: mockCloudPostureDataTable, | ||
loadMore: jest.fn(), | ||
title: 'Test Table', | ||
}; | ||
|
||
return render( | ||
<TestProvider> | ||
<CloudSecurityDataTable {...defaultProps} {...props} /> | ||
</TestProvider> | ||
); | ||
}; | ||
|
||
describe('CloudSecurityDataTable', () => { | ||
it('renders loading state', () => { | ||
const { getByTestId } = renderDataTable({ isLoading: true }); | ||
expect(getByTestId('unifiedDataTableLoading')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders empty state when no rows are present', () => { | ||
const { getByTestId } = renderDataTable(); | ||
expect(getByTestId('csp:empty-state')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders data table with rows', async () => { | ||
const mockRows = [ | ||
{ | ||
id: '1', | ||
raw: { | ||
field1: 'Label 1', | ||
field2: 'Label 2', | ||
}, | ||
flattened: { | ||
field1: 'Label 1', | ||
field2: 'Label 2', | ||
}, | ||
}, | ||
] as any; | ||
const { getByTestId, getByText } = renderDataTable({ | ||
rows: mockRows, | ||
total: mockRows.length, | ||
}); | ||
|
||
expect(getByTestId('discoverDocTable')).toBeInTheDocument(); | ||
expect(getByText('Label 1')).toBeInTheDocument(); | ||
expect(getByText('Label 2')).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,11 @@ export const Configurations = () => { | |
path={findingsNavigation.findings_default.path} | ||
render={() => ( | ||
<TrackApplicationView viewId={findingsNavigation.findings_default.id}> | ||
<LatestFindingsContainer dataView={dataViewQuery.data!} /> | ||
<LatestFindingsContainer | ||
dataView={dataViewQuery.data!} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple of general questions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
IMO the downside is that we add a deep coupling with an object from the
that's a good suggestion, better than passing down a |
||
dataViewRefetch={dataViewQuery.refetch} | ||
dataViewIsRefetching={dataViewQuery.isRefetching} | ||
/> | ||
</TrackApplicationView> | ||
)} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw what
use perfected kibana data views
means (in the TODO for this hook)? not directly related to this PR, but I'd add more context to this todo, as I for instance wouldn't know what to do with it