Skip to content

Commit

Permalink
Merge pull request #1859 from bcgov/1666-revision-type-tooltips
Browse files Browse the repository at this point in the history
1666 revision type tooltips
  • Loading branch information
Sepehr-Sobhani authored Sep 1, 2023
2 parents bb23957 + 1767ecc commit 490ffb5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { aliasOperation } from "../../../utils/graphql-test-utils";

describe("the project amendment and revisions page", () => {
beforeEach(() => {
cy.intercept("POST", "http://localhost:3004/graphql", (req) => {
aliasOperation(req, "createProjectRevisionMutation");
});
cy.useMockedTime(new Date("June 10, 2020 09:00:00"));
cy.sqlFixture("e2e/dbReset");
cy.sqlFixture("dev/001_cif_user");
Expand All @@ -23,8 +28,12 @@ describe("the project amendment and revisions page", () => {
cy.get('[type="radio"]').check("Amendment");
cy.get(".checkbox").contains("Scope").click();
cy.get("button").contains("New Revision").click();
cy.wait("@gqlcreateProjectRevisionMutation")
.its("response")
.should("have.property", "body");
cy.url().should("include", "/form/0");
});

it("displays updated forms in a project revision/amendment", () => {
cy.visit("/cif/projects");
cy.get("button").contains("View").first().as("firstViewButton");
Expand Down
19 changes: 15 additions & 4 deletions app/pages/cif/project-revision/[projectRevision]/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export function ProjectRevisionCreate({
},
});
};

const revisionEnum = allRevisionTypes.edges.map((e) => e.node.type);
createProjectRevisionSchema.properties.revisionType.enum = revisionEnum;

Expand All @@ -91,16 +92,26 @@ export function ProjectRevisionCreate({
localSchema.dependencies.revisionType.oneOf[1].properties.amendmentTypes.items.enum =
amendmentTypeEnum;

const disabledEnums = existingAmendment
? ["Amendment"]
const existingRevisionType = existingAmendment
? "Amendment"
: existingGeneralRevision
? ["General Revision"]
: [];
? "General Revision"
: null;

const disabledEnums = existingRevisionType ? [existingRevisionType] : [];

const modifiedUiSchema = {
...projectRevisionUISchema,
revisionType: {
...projectRevisionUISchema.revisionType,
"ui:enumDisabled": disabledEnums,
...(existingRevisionType && {
"ui:tooltip": {
text: `<div><ul><li>You cannot create a new ${existingRevisionType} before the in-progress ${existingRevisionType} is ${
existingRevisionType === "Amendment" ? "approved" : "applied"
}.</li></ul></div>`,
},
}),
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@testing-library/jest-dom";
import { act, screen } from "@testing-library/react";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ProjectRevisionCreate } from "pages/cif/project-revision/[projectRevision]/create";
import PageTestingHelper from "tests/helpers/pageTestingHelper";
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("The project amendments and revisions page", () => {
anchor: undefined,
});
});
it("Disables only the amendment revision type if one is already pending", () => {
it("Disables only the amendment revision type if one is already pending", async () => {
pageTestingHelper.loadQuery({
...defaultMockResolver,
Project() {
Expand All @@ -192,6 +192,53 @@ describe("The project amendments and revisions page", () => {
});
expect(amendmentRadio).toBeDisabled();
expect(generalRevisionRadio).not.toBeDisabled();
const amendmentTooltip = screen.getByRole("tooltip", {
name: "revision-type-tooltip",
});
expect(amendmentTooltip).toBeInTheDocument();
fireEvent.mouseOver(amendmentTooltip);
await waitFor(() => {
expect(
screen.getByText(
"You cannot create a new Amendment before the in-progress Amendment is approved."
)
).toBeInTheDocument();
});
});
it("Disables only the general revision type if one is already pending", async () => {
pageTestingHelper.loadQuery({
...defaultMockResolver,
Project() {
return {
id: "test-project",
rowId: 2345,
pendingGeneralRevision: {
id: 8765,
},
pendingAmendment: null,
};
},
});
pageTestingHelper.renderPage();

const amendmentRadio = screen.getByRole("radio", { name: /amendment/i });
const generalRevisionRadio = screen.getByRole("radio", {
name: /general revision/i,
});
expect(amendmentRadio).not.toBeDisabled();
expect(generalRevisionRadio).toBeDisabled();
const generalRevisionTooltip = screen.getByRole("tooltip", {
name: "revision-type-tooltip",
});
expect(generalRevisionTooltip).toBeInTheDocument();
fireEvent.mouseOver(generalRevisionTooltip);
await waitFor(() => {
expect(
screen.getByText(
"You cannot create a new General Revision before the in-progress General Revision is applied."
)
).toBeInTheDocument();
});
});
it("Does not render the create form if a general revision and amendment are both already in progress", () => {
pageTestingHelper.loadQuery({
Expand Down

0 comments on commit 490ffb5

Please sign in to comment.