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

Add remediation content #1114

Merged
merged 4 commits into from
Jan 17, 2023
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
8 changes: 8 additions & 0 deletions assets/js/components/ChecksResults/checksUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ export const getCheckDescription = (catalog, checkID) => {
}
return null;
};

export const getCheckRemediation = (catalog, checkID) => {
const check = findCheck(catalog, checkID);
if (check) {
return check.remediation;
}
return null;
};
9 changes: 9 additions & 0 deletions assets/js/components/ChecksResults/checksUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

import {
getCheckDescription,
getCheckRemediation,
getCheckResults,
getChecks,
getCheckHealthByAgent,
Expand Down Expand Up @@ -71,6 +72,14 @@ describe('checksUtils', () => {
expect(getCheckDescription(catalog, id)).toBe(description);
});

it('getCheckRemediation should return a check remediation', () => {
const catalog = catalogCheckFactory.buildList(2);
const [{ id, remediation }] = catalog;

expect(getCheckRemediation(catalog, id)).toBe(remediation);
expect(getCheckRemediation(catalog, 'wont-be-found')).toBe(null);
});

describe('getCheckHealthByAgent', () => {
it('should return an empty map when check results are empty', () => {
expect(
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/ChecksResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getCheckHealthByAgent,
getCheckResults,
getCheckDescription,
getCheckRemediation,
} from './checksUtils';

export {
Expand All @@ -19,6 +20,7 @@ export {
getCheckHealthByAgent,
getCheckResults,
getCheckDescription,
getCheckRemediation,
};

export default ChecksResults;
15 changes: 11 additions & 4 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getCheckHealthByAgent,
getCheckResults,
getCheckDescription,
getCheckRemediation,
} from '@components/ChecksResults';
import ChecksResultFilters from '@components/ChecksResults/ChecksResultFilters';
import { UNKNOWN_PROVIDER } from '@components/ClusterDetails/ClusterSettings';
Expand All @@ -41,6 +42,14 @@ const getLabel = (status, health, error, expectations, failedExpectations) => {
return `${failedExpectations}/${expectations} expectations failed`;
};

function asMarkdownContent(content) {
return (
<ReactMarkdown className="markdown" remarkPlugins={[remarkGfm]}>
{content}
</ReactMarkdown>
);
}

function ExecutionResults({
clusterID,
clusterName,
Expand Down Expand Up @@ -90,13 +99,11 @@ function ExecutionResults({
return (
<div>
<Modal
title={getCheckDescription(catalog, selectedCheck)}
title={asMarkdownContent(getCheckDescription(catalog, selectedCheck))}
open={modalOpen}
onClose={() => setModalOpen(false)}
>
<ReactMarkdown className="markdown" remarkPlugins={[remarkGfm]}>
{getCheckDescription(catalog, selectedCheck)}
</ReactMarkdown>
{asMarkdownContent(getCheckRemediation(catalog, selectedCheck))}
</Modal>
<BackButton url={`/clusters_new/${clusterID}`}>
Back to Cluster Details
Expand Down
19 changes: 17 additions & 2 deletions assets/js/components/ExecutionResults/ExecutionResults.test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { screen } from '@testing-library/react';

import userEvent from '@testing-library/user-event';

import { faker } from '@faker-js/faker';
import { renderWithRouter } from '@lib/test-utils';

import {
catalogFactory,
catalogCheckFactory,
hostnameFactory,
addCriticalExpectation,
addPassingExpectation,
Expand Down Expand Up @@ -69,8 +72,8 @@ const prepareStateData = (checkExecutionStatus) => {
const { loading, catalog, error } = catalogFactory.build({
loading: false,
catalog: [
catalogFactory.build({ id: checkID1 }),
catalogFactory.build({ id: checkID2 }),
catalogCheckFactory.build({ id: checkID1 }),
nelsonkopliku marked this conversation as resolved.
Show resolved Hide resolved
catalogCheckFactory.build({ id: checkID2 }),
],
error: null,
});
Expand Down Expand Up @@ -108,6 +111,13 @@ const prepareStateData = (checkExecutionStatus) => {

describe('ExecutionResults', () => {
it('should render ExecutionResults with successfully fetched results', async () => {
window.IntersectionObserver = jest.fn().mockImplementation(() => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this IntersectionObserver for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Headlessui dialog related need. Without it we get an error (which I don't remember now) and google helped me 😄

observe: () => null,
disconnect: () => null,
}));

const user = userEvent.setup();

const {
clusterID,
hostnames,
Expand Down Expand Up @@ -145,6 +155,11 @@ describe('ExecutionResults', () => {
expect(screen.getAllByText(checkID2)).toHaveLength(2);
expect(screen.getAllByText('2/2 expectations passed')).toBeTruthy();
expect(screen.getAllByText('1/2 expectations failed')).toBeTruthy();

const [{ remediation }] = catalog;
expect(screen.queryByText(remediation)).not.toBeInTheDocument();
await user.click(screen.getAllByText(checkID1)[0]);
expect(screen.getByText(remediation)).toBeVisible();
});

it('should render ExecutionResults with running state', async () => {
Expand Down
7 changes: 5 additions & 2 deletions assets/js/components/Modal/Modal.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { Fragment } from 'react';
import React, { Fragment, useRef } from 'react';
import { Dialog, Transition } from '@headlessui/react';

function Modal({ children, open, onClose, title }) {
const refContent = useRef(null);

return (
<Transition appear show={open} as={Fragment}>
<Dialog
initialFocus={refContent}
as="div"
className="fixed inset-0 z-50 overflow-y-auto"
onClose={onClose}
>
<div className="min-h-screen px-4 text-center">
<div ref={refContent} className="min-h-screen px-4 text-center">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
Expand Down