Skip to content

Commit

Permalink
Re-add checks filtering (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster authored Mar 6, 2023
1 parent beef248 commit b39bc24
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 16 deletions.
43 changes: 27 additions & 16 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import Table from '@components/Table';

import ReactMarkdown from 'react-markdown';
Expand Down Expand Up @@ -89,6 +89,8 @@ function ExecutionResults({
onLastExecutionUpdate = () => {},
onStartExecution = () => {},
}) {
const [predicates, setPredicates] = useState([]);

const hosts = hostnames.map((item) => item.id);

if (catalogLoading) {
Expand Down Expand Up @@ -121,22 +123,30 @@ function ExecutionResults({
);
}

const tableData = getCheckResults(executionData).map(
({
check_id: checkID,
result,
expectation_results: expectationResults,
agents_check_results: agentsCheckResults,
}) => ({
checkID,
result,
clusterName,
executionState: executionData?.status,
description: getCheckDescription(catalog, checkID),
expectationResults,
agentsCheckResults: addHostnameToTargets(agentsCheckResults, hostnames),
const tableData = getCheckResults(executionData)
.filter((check) => {
if (predicates.length === 0) {
return true;
}

return predicates.some((predicate) => predicate(check));
})
);
.map(
({
check_id: checkID,
result,
expectation_results: expectationResults,
agents_check_results: agentsCheckResults,
}) => ({
checkID,
result,
clusterName,
executionState: executionData?.status,
description: getCheckDescription(catalog, checkID),
expectationResults,
agentsCheckResults: addHostnameToTargets(agentsCheckResults, hostnames),
})
);

return (
<>
Expand All @@ -145,6 +155,7 @@ function ExecutionResults({
clusterName={clusterName}
cloudProvider={cloudProvider}
clusterScenario={clusterScenario}
onFilterChange={(newPredicates) => setPredicates(newPredicates)}
/>
<ResultsContainer
catalogError={false}
Expand Down
85 changes: 85 additions & 0 deletions assets/js/components/ExecutionResults/ExecutionResults.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,89 @@ describe('ExecutionResults', () => {
const svgText = screen.getByText('Select Checks now');
expect(svgText).toBeInTheDocument();
});

it("should render ExecutionResults with successfully filtered 'passing' results", async () => {
const {
clusterID,
hostnames,
checks: [checkID1, checkID2],
loading,
catalog,
error,
executionLoading,
executionData,
executionError,
executionStarted,
} = prepareStateData('passing');

renderWithRouter(
<ExecutionResults
clusterID={clusterID}
clusterName="test-cluster"
clusterScenario="hana_scale_up"
cloudProvider="azure"
hostnames={hostnames}
catalogLoading={loading}
catalog={catalog}
executionStarted={executionStarted}
catalogError={error}
executionLoading={executionLoading}
executionData={executionData}
executionError={executionError}
/>,
{ route: `/clusters/${clusterID}/executions/last?health=passing` }
);

expect(screen.getAllByText('test-cluster')).toHaveLength(2);
expect(screen.getByText('HANA scale-up')).toBeTruthy();
expect(screen.getByText('Azure')).toBeTruthy();
expect(screen.getByText(hostnames[0].hostname)).toBeTruthy();
expect(screen.getByText(hostnames[1].hostname)).toBeTruthy();
expect(screen.getAllByText(checkID1)).toHaveLength(1);
expect(screen.queryByText(checkID2)).toBeNull();
});

it("should render ExecutionResults with successfully filtered 'passing' and 'critical' results", async () => {
const {
clusterID,
hostnames,
checks: [checkID1, checkID2],
loading,
catalog,
executionStarted,
error,
executionLoading,
executionData,
executionError,
} = prepareStateData('passing');

renderWithRouter(
<ExecutionResults
clusterID={clusterID}
clusterName="test-cluster"
clusterScenario="hana_scale_up"
cloudProvider="azure"
hostnames={hostnames}
catalogLoading={loading}
catalog={catalog}
executionStarted={executionStarted}
catalogError={error}
executionLoading={executionLoading}
executionData={executionData}
executionError={executionError}
/>,
{
route: `/clusters/${clusterID}/executions/last?health=passing&health=critical
`,
}
);

expect(screen.getAllByText('test-cluster')).toHaveLength(2);
expect(screen.getByText('HANA scale-up')).toBeTruthy();
expect(screen.getByText('Azure')).toBeTruthy();
expect(screen.getAllByText(hostnames[0].hostname)).toHaveLength(2);
expect(screen.getAllByText(hostnames[1].hostname)).toHaveLength(2);
expect(screen.getAllByText(checkID1)).toHaveLength(1);
expect(screen.getAllByText(checkID2)).toHaveLength(1);
});
});

0 comments on commit b39bc24

Please sign in to comment.