forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Posture] [Dashboard] Add sorting by Compliance Score in the cl…
…usters section (elastic#149566) Issue elastic#144013 ## Summary This PR adds the capability to sort Clusters by Compliance Score in the Cloud Posture Dashboard. It saves the sorting on the Local Storage and defaults to **Descending** on the initial load. The following changes were also introduced: - Added unit tests for sorting - Also added missing tests for the clusters section columns and added some tests to do in future PRs - Isolated `mockDashboardData` into own mock file and added a `clusterMockData` - Styling optimizations - Wrapped existent callbacks into `useCallback` ## Screenshots ### Initial load ![image](https://user-images.githubusercontent.com/19270322/215618280-65415866-e8fb-4df5-85bc-4ea7af0ce375.png) ### Sort Toggle ![image](https://user-images.githubusercontent.com/19270322/215618358-520fe047-0624-4c87-8e99-998ae18610fa.png) ### Tests ![image](https://user-images.githubusercontent.com/19270322/215618537-ce064460-71b4-48ef-9594-ce1093a94157.png)
- Loading branch information
1 parent
75fc86f
commit 1b2d40c
Showing
7 changed files
with
362 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
..._posture/public/pages/compliance_dashboard/dashboard_sections/benchmarks_section.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { BenchmarksSection } from './benchmarks_section'; | ||
import { getMockDashboardData, getClusterMockData } from '../mock'; | ||
import { TestProvider } from '../../../test/test_provider'; | ||
import { KSPM_POLICY_TEMPLATE } from '../../../../common/constants'; | ||
import { | ||
DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID, | ||
DASHBOARD_TABLE_HEADER_SCORE_TEST_ID, | ||
} from '../../findings/test_subjects'; | ||
|
||
describe('<BenchmarksSection />', () => { | ||
const renderBenchmarks = (alterMockData = {}) => | ||
render( | ||
<TestProvider> | ||
<BenchmarksSection | ||
complianceData={{ ...getMockDashboardData(), ...alterMockData }} | ||
dashboardType={KSPM_POLICY_TEMPLATE} | ||
/> | ||
</TestProvider> | ||
); | ||
|
||
describe('Sorting', () => { | ||
const mockDashboardDataCopy = getMockDashboardData(); | ||
const clusterMockDataCopy = getClusterMockData(); | ||
clusterMockDataCopy.stats.postureScore = 50; | ||
clusterMockDataCopy.meta.clusterId = '1'; | ||
|
||
const clusterMockDataCopy1 = getClusterMockData(); | ||
clusterMockDataCopy1.stats.postureScore = 95; | ||
clusterMockDataCopy1.meta.clusterId = '2'; | ||
|
||
const clusterMockDataCopy2 = getClusterMockData(); | ||
clusterMockDataCopy2.stats.postureScore = 45; | ||
clusterMockDataCopy2.meta.clusterId = '3'; | ||
|
||
mockDashboardDataCopy.clusters = [ | ||
clusterMockDataCopy, | ||
clusterMockDataCopy1, | ||
clusterMockDataCopy2, | ||
]; | ||
|
||
it('sorts by ascending order of compliance scores', () => { | ||
const { getAllByTestId } = renderBenchmarks(mockDashboardDataCopy); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[0]).toHaveTextContent('45'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[1]).toHaveTextContent('50'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[2]).toHaveTextContent('95'); | ||
}); | ||
|
||
it('toggles sort order when clicking Compliance Score', () => { | ||
const { getAllByTestId, getByTestId } = renderBenchmarks(mockDashboardDataCopy); | ||
|
||
userEvent.click(getByTestId(DASHBOARD_TABLE_HEADER_SCORE_TEST_ID)); | ||
|
||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[0]).toHaveTextContent('95'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[1]).toHaveTextContent('50'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[2]).toHaveTextContent('45'); | ||
|
||
userEvent.click(getByTestId(DASHBOARD_TABLE_HEADER_SCORE_TEST_ID)); | ||
|
||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[0]).toHaveTextContent('45'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[1]).toHaveTextContent('50'); | ||
expect(getAllByTestId(DASHBOARD_TABLE_COLUMN_SCORE_TEST_ID)[2]).toHaveTextContent('95'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.