Skip to content

Commit

Permalink
Update copy and tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Mirjam Aulbach <[email protected]>
  • Loading branch information
programmiri committed Oct 16, 2023
1 parent 0c5fa5e commit 53d4f5b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ describe("TopicDetailsSchema", () => {
});

const checkBoxBefore = screen.queryByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

expect(checkBoxBefore).not.toBeInTheDocument();
Expand All @@ -996,7 +996,7 @@ describe("TopicDetailsSchema", () => {
});

const checkboxToForceRegister = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

expect(checkboxToForceRegister).toBeVisible();
Expand Down Expand Up @@ -1032,7 +1032,7 @@ describe("TopicDetailsSchema", () => {
await user.click(buttonRequest);

const checkboxToForceRegister = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

await user.click(checkboxToForceRegister);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ describe("TopicDetailsSchema", () => {
await user.click(buttonRequest);

const checkboxToForceRegister = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

await user.click(checkboxToForceRegister);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function TopicDetailsSchema() {
topicOverview,
} = useTopicDetails();
const [showSchemaPromotionModal, setShowSchemaPromotionModal] =
useState(false);
useState(true);
const [errorMessage, setErrorMessage] = useState("");
const [isValidationError, setIsValidationError] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ describe("SchemaPromotionModal", () => {
expect(dialog).toBeVisible();
});

it("shows no warning or option to force register", () => {
const warning = screen.queryByRole("alert");
const checkbox = screen.queryByRole("checkbox");

expect(warning).not.toBeInTheDocument();
expect(checkbox).not.toBeInTheDocument();
});

it("shows more information to delete the topic", () => {
const dialog = screen.getByRole("dialog");
const headline = within(dialog).getByRole("heading", {
Expand All @@ -50,7 +58,7 @@ describe("SchemaPromotionModal", () => {

it("does not show a switch to force register", () => {
const forceRegisterSwitch = screen.queryByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});
expect(forceRegisterSwitch).not.toBeInTheDocument();
});
Expand Down Expand Up @@ -102,13 +110,6 @@ describe("SchemaPromotionModal", () => {
jest.clearAllMocks();
});

it("disables Force register switch", () => {
const forceRegisterSwitch = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
});
expect(forceRegisterSwitch).toBeDisabled();
});

it("disables textarea where user can add a comment why they promote the schema", () => {
const dialog = screen.getByRole("dialog");
const textarea = within(dialog).getByRole("textbox", {
Expand Down Expand Up @@ -191,6 +192,15 @@ describe("SchemaPromotionModal", () => {
jest.clearAllMocks();
});

it("shows a warning about force register", async () => {
const warning = screen.getByRole("alert");

expect(warning).toBeVisible();
expect(warning).toHaveTextContent(
"Uploaded schema appears invalid. Are you sure you want to force register it?"
);
});

it("triggers a given submit function with correct payload when user does not switch Force register or adds a reason", async () => {
const dialog = screen.getByRole("dialog");

Expand All @@ -211,7 +221,7 @@ describe("SchemaPromotionModal", () => {
const dialog = screen.getByRole("dialog");

const forceRegisterSwitch = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

const confirmationButton = within(dialog).getByRole("button", {
Expand All @@ -232,7 +242,7 @@ describe("SchemaPromotionModal", () => {
const dialog = screen.getByRole("dialog");

const forceRegisterSwitch = screen.getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

const textarea = within(dialog).getByRole("textbox", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Checkbox, Textarea } from "@aivenio/aquarium";
import { Alert, Box, Checkbox, Textarea } from "@aivenio/aquarium";
import { useState } from "react";
import { Modal } from "src/app/components/Modal";

Expand Down Expand Up @@ -52,16 +52,12 @@ const SchemaPromotionModal = ({
{`Promote the Version ${version} of the schema to ${targetEnvironment}?`}
</p>
{showForceRegister && (
<Checkbox
disabled={isLoading}
checked={forceRegister}
caption={
"Overrides some validation that the schema registry would normally do."
}
onChange={(e) => setForceRegister(e.target.checked)}
>
Force register
</Checkbox>
<Box marginBottom={"l1"}>
<Alert type={"warning"}>
Uploaded schema appears invalid. Are you sure you want to force
register it?
</Alert>
</Box>
)}
<Textarea
labelText="You can add the reason to promote the schema (optional)"
Expand All @@ -73,6 +69,18 @@ const SchemaPromotionModal = ({
helperText={"Required"}
disabled={isLoading}
/>
{showForceRegister && (
<Checkbox
disabled={isLoading}
checked={forceRegister}
caption={
"Overrides standard validation processes of the schema registry."
}
onChange={(e) => setForceRegister(e.target.checked)}
>
Force register
</Checkbox>
)}
</Box>
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,12 @@ describe("TopicSchemaRequest", () => {
const form = getForm();

const checkBoxBefore = within(form).queryByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

const warningBefore = screen.queryByText("alertdialog");
expect(checkBoxBefore).not.toBeInTheDocument();
expect(warningBefore).not.toBeInTheDocument();

const select = within(form).getByRole("combobox", {
name: /Environment/i,
Expand All @@ -999,9 +1002,15 @@ describe("TopicSchemaRequest", () => {
await userEvent.upload(fileInput, testFile);
await userEvent.click(button);

const warningForceRegister = screen.getByRole("alert");
const checkboxForceRegister = within(form).getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});
expect(warningForceRegister).toBeVisible();
expect(warningForceRegister).toHaveTextContent(
"Uploaded schema appears invalid. Are you sure you want to" +
" force register it?"
);

expect(checkboxForceRegister).toBeVisible();
expect(console.error).toHaveBeenCalledWith({
Expand Down Expand Up @@ -1031,7 +1040,7 @@ describe("TopicSchemaRequest", () => {
await userEvent.click(submitButton);

const checkboxForceRegister = within(form).getByRole("checkbox", {
name: "Force register Overrides some validation that the schema registry would normally do.",
name: "Force register Overrides standard validation processes of the schema registry.",
});

await userEvent.click(checkboxForceRegister);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) {
{isValidationError && (
<Box marginBottom={"l1"}>
<Alert type={"warning"}>
The uploaded schema does not appear to be valid. You can force
register the schema.
Uploaded schema appears invalid. Are you sure you want to force
register it?
</Alert>
</Box>
)}
Expand Down Expand Up @@ -247,7 +247,7 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) {
<Checkbox<TopicRequestFormSchema>
name={"forceRegister"}
caption={
"Overrides some validation that the schema registry would normally do."
"Overrides standard validation processes of the schema registry."
}
>
Force register
Expand Down

0 comments on commit 53d4f5b

Please sign in to comment.