Skip to content

Commit

Permalink
Merge branch 'main' into assessment-wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Apr 16, 2024
2 parents d9bb0fb + d8d1ede commit 488d071
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 221 deletions.
51 changes: 25 additions & 26 deletions client/src/app/components/AppTableActionButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Button, Flex, FlexItem } from "@patternfly/react-core";
import { Button } from "@patternfly/react-core";
import { applicationsWriteScopes, RBAC, RBAC_TYPE } from "@app/rbac";
import { ConditionalTooltip } from "./ConditionalTooltip";
import { Td } from "@patternfly/react-table";

export interface AppTableActionButtonsProps {
isDeleteEnabled?: boolean;
Expand All @@ -24,34 +25,32 @@ export const AppTableActionButtons: React.FC<AppTableActionButtonsProps> = ({
allowedPermissions={applicationsWriteScopes}
rbacType={RBAC_TYPE.Scope}
>
<Flex>
<FlexItem align={{ default: "alignRight" }}>
<Td isActionCell>
<Button
id="edit-button"
aria-label="edit"
variant="secondary"
onClick={onEdit}
>
{t("actions.edit")}
</Button>
</Td>
<Td isActionCell>
<ConditionalTooltip
isTooltipEnabled={isDeleteEnabled}
content={tooltipMessage}
>
<Button
id="edit-button"
aria-label="edit"
variant="secondary"
onClick={onEdit}
id="delete-button"
aria-label="delete"
variant="link"
onClick={onDelete}
isAriaDisabled={isDeleteEnabled}
>
{t("actions.edit")}
{t("actions.delete")}
</Button>
</FlexItem>
<FlexItem>
<ConditionalTooltip
isTooltipEnabled={isDeleteEnabled}
content={tooltipMessage}
>
<Button
id="delete-button"
aria-label="delete"
variant="link"
onClick={onDelete}
isAriaDisabled={isDeleteEnabled}
>
{t("actions.delete")}
</Button>
</ConditionalTooltip>
</FlexItem>
</Flex>
</ConditionalTooltip>
</Td>
</RBAC>
);
};
9 changes: 5 additions & 4 deletions client/src/app/hooks/useAssessmentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ export const useAssessmentStatus = (application: Application) => {

const hasApplicationAssessmentInProgress = applicationAssessments?.some(
(assessment: Assessment) =>
assessment.status === "started" ||
assessment.status === "empty" ||
(assessment.status === "complete" &&
application.assessments?.length !== 0)
assessment.required &&
(assessment.status === "started" ||
assessment.status === "empty" ||
(assessment.status === "complete" &&
application.assessments?.length !== 0))
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { TASKGROUPS } from "@app/api/rest";
import mock from "@app/test-config/mockInstance";
import userEvent from "@testing-library/user-event";

mock.onAny().reply(200, []);

const applicationData1 = {
id: 1,
name: "App1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ export const ApplicationsTable: React.FC = () => {
<Tr>
<TableHeaderContentWithControls {...tableControls}>
{getColumnVisibility("name") && (
<Th {...getThProps({ columnKey: "name" })} width={15} />
<Th {...getThProps({ columnKey: "name" })} width={10} />
)}
{getColumnVisibility("businessService") && (
<Th
Expand All @@ -836,18 +836,18 @@ export const ApplicationsTable: React.FC = () => {
<Th {...getThProps({ columnKey: "assessment" })} width={15} />
)}
{getColumnVisibility("review") && (
<Th {...getThProps({ columnKey: "review" })} width={10} />
<Th {...getThProps({ columnKey: "review" })} width={15} />
)}
{getColumnVisibility("analysis") && (
<Th {...getThProps({ columnKey: "analysis" })} width={10} />
<Th {...getThProps({ columnKey: "analysis" })} width={15} />
)}
{getColumnVisibility("tags") && (
<Th {...getThProps({ columnKey: "tags" })} width={10} />
)}
{getColumnVisibility("effort") && (
<Th {...getThProps({ columnKey: "effort" })} width={10} />
)}
<Th />
<Th width={10} />
</TableHeaderContentWithControls>
</Tr>
</Thead>
Expand Down Expand Up @@ -885,7 +885,7 @@ export const ApplicationsTable: React.FC = () => {
>
{getColumnVisibility("name") && (
<Td
width={15}
width={10}
{...getTdProps({ columnKey: "name" })}
modifier="truncate"
>
Expand Down Expand Up @@ -936,7 +936,7 @@ export const ApplicationsTable: React.FC = () => {
)}
{getColumnVisibility("analysis") && (
<Td
width={10}
width={15}
modifier="truncate"
{...getTdProps({ columnKey: "analysis" })}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,110 @@ describe("useAssessmentStatus", () => {
server.resetHandlers();
});

it("Updates hasApplicationAssessmentInProgress to false when assessment is marked as not required", async () => {
server.use(
rest.get("/hub/archetypes", (req, res, ctx) => {
return res(
ctx.json([
createMockArchetype({
id: 1,
name: "archetype1",
applications: [],
assessed: false,
assessments: [],
}),
])
);
}),
rest.get("/hub/assessments", (req, res, ctx) => {
return res(
ctx.json([
createMockAssessment({
id: 1,
application: { id: 1, name: "app1" },
questionnaire: { id: 1, name: "questionnaire1" },
status: "started",
required: true,
sections: [],
}),
createMockAssessment({
id: 2,
application: { id: 1, name: "app1" },
questionnaire: { id: 2, name: "questionnaire2" },
status: "complete",
required: true,
sections: [],
}),
])
);
})
);

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
cacheTime: 1000,
},
},
});

const { result, rerender } = renderHook(
() => useAssessmentStatus(createMockApplication({ id: 1, name: "app1" })),
{ queryClient }
);

await waitFor(() => {
expect(result.current.hasApplicationAssessmentInProgress).toBe(true);
});

server.use(
rest.get("/hub/archetypes", (req, res, ctx) => {
return res(
ctx.json([
createMockArchetype({
id: 1,
name: "archetype1",
applications: [],
assessed: false,
assessments: [],
}),
])
);
}),
rest.get("/hub/assessments", (req, res, ctx) => {
return res(
ctx.json([
createMockAssessment({
id: 1,
application: { id: 1, name: "app1" },
questionnaire: { id: 1, name: "questionnaire1" },
status: "started",
required: false,
sections: [],
}),
createMockAssessment({
id: 2,
application: { id: 1, name: "app1" },
questionnaire: { id: 2, name: "questionnaire2" },
status: "complete",
required: false,
sections: [],
}),
])
);
})
);

queryClient.invalidateQueries([assessmentsQueryKey]);

rerender(createMockApplication({ id: 1, name: "app1" }));

await waitFor(() => {
expect(result.current.hasApplicationAssessmentInProgress).toBe(false);
});
});

it("Updates hasApplicationAssessmentInProgress to false once associated assessments are deleted", async () => {
server.use(
rest.get("/hub/assessments", (req, res, ctx) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import {
fireEvent,
} from "@app/test-config/test-utils";

import {
APPLICATIONS,
BUSINESS_SERVICES,
REVIEWS,
TAG_CATEGORIES,
} from "@app/api/rest";
import { BUSINESS_SERVICES } from "@app/api/rest";
import mock from "@app/test-config/mockInstance";
import userEvent from "@testing-library/user-event";

Expand All @@ -20,19 +15,17 @@ import "@testing-library/jest-dom";
import { BusinessService } from "@app/api/models";
import { ApplicationFormModal } from "../application-form-modal";

const data: any[] = [];
mock.onGet(`${BUSINESS_SERVICES}`).reply(200, data);
mock.onGet(`${TAG_CATEGORIES}`).reply(200, data);
mock.onGet(`${APPLICATIONS}`).reply(200, data);
mock.onGet(`${REVIEWS}`).reply(200, data);

describe("Component: application-form", () => {
const mockChangeValue = jest.fn();

it("Validation tests", async () => {
const businessServices: BusinessService[] = [{ id: 1, name: "service" }];

mock.onGet(`${BUSINESS_SERVICES}`).reply(200, businessServices);
mock
.onGet(`${BUSINESS_SERVICES}`)
.reply(200, businessServices)
.onAny()
.reply(200, []);

render(
<ApplicationFormModal application={null} onClose={mockChangeValue} />
Expand Down Expand Up @@ -121,5 +114,5 @@ describe("Component: application-form", () => {
);

expect(createButton).toBeEnabled();
});
}, 10000);
});
Loading

0 comments on commit 488d071

Please sign in to comment.