Skip to content
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

Fix Checks results filters #1073

Merged
merged 5 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/js/components/ClusterDetails/ClusterDetailsNew.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export function ClusterDetailsNew() {
<ChecksResultOverviewNew
{...lastExecution}
onCheckClick={(health) =>
navigate(`/clusters/${clusterID}/checks/results?health=${health}`)
navigate(
`/clusters_new/${clusterID}/executions/last?health=${health}`
)
}
/>
</div>
Expand Down
79 changes: 51 additions & 28 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
getCheckResults,
getCheckDescription,
} from '@components/ChecksResults';
import ChecksResultFilters, {
filterChecks,
} from '@components/ChecksResults/ChecksResultFilters';
import ChecksResultFilters from '@components/ChecksResults/ChecksResultFilters';
import { UNKNOWN_PROVIDER } from '@components/ClusterDetails/ClusterSettings';
import { ClusterInfoBox } from '@components/ClusterDetails';
import NotificationBox from '@components/NotificationBox';
Expand Down Expand Up @@ -138,32 +136,57 @@ function ExecutionResults({
key={hostID}
hostname={hostnames.find(({ id }) => hostID === id)?.hostname}
>
{filterChecks(checks, predicates).map((checkID) => {
const { health, error, expectations, failedExpectations } =
getCheckHealthByAgent(checkResults, checkID, hostID);
{checks
.map((checkID) => {
const { health, error, expectations, failedExpectations } =
getCheckHealthByAgent(checkResults, checkID, hostID);

const label = getLabel(
executionData?.status,
health,
error,
expectations,
failedExpectations
);
return (
<CheckResult
key={checkID}
checkId={checkID}
description={getCheckDescription(catalog, checkID)}
executionState={executionData?.status}
health={health}
label={label}
onClick={() => {
setModalOpen(true);
setSelectedCheck(checkID);
}}
/>
);
})}
return {
checkID,
error,
expectations,
failedExpectations,
result: health,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change from health to result?
We use health all around the frontend code.
Is it because the predicate function expects that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's correct, predicate() relies on result being present.

};
})
.filter((check) => {
if (predicates.length === 0) {
return true;
}

return predicates.some((predicate) => predicate(check));
})
.map(
({
checkID,
result,
error,
expectations,
failedExpectations,
}) => {
const label = getLabel(
executionData?.status,
result,
error,
expectations,
failedExpectations
);
return (
<CheckResult
key={checkID}
checkId={checkID}
description={getCheckDescription(catalog, checkID)}
executionState={executionData?.status}
health={result}
label={label}
onClick={() => {
setModalOpen(true);
setSelectedCheck(checkID);
}}
/>
);
}
)}
</HostResultsWrapper>
))}
</ResultsContainer>
Expand Down
84 changes: 84 additions & 0 deletions assets/js/components/ExecutionResults/ExecutionResults.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,88 @@ 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,
} = prepareStateData('passing');

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

expect(screen.getByText('test-cluster')).toBeTruthy();
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(2);
expect(screen.queryByText(checkID2)).toBeNull();
expect(screen.getAllByText('2/2 expectations passed')).toBeTruthy();
});

it("should render ExecutionResults with successfully filtered 'passing' and 'ciritcal' results", async () => {
const {
clusterID,
hostnames,
checks: [checkID1, checkID2],
loading,
catalog,
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}
catalogError={error}
executionLoading={executionLoading}
executionData={executionData}
executionError={executionError}
/>,
{
route: `/clusters_new/${clusterID}/executions/last?health=passing&health=critical
`,
}
);

expect(screen.getByText('test-cluster')).toBeTruthy();
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(2);
expect(screen.getAllByText(checkID2)).toHaveLength(2);
expect(screen.getAllByText('2/2 expectations passed')).toBeTruthy();
expect(screen.getAllByText('1/2 expectations failed')).toBeTruthy();
});
});