Skip to content

Commit

Permalink
fix(coral): Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Anderson <mathieu.anderson@aiven.io>
  • Loading branch information
Mathieu Anderson committed Feb 16, 2024
1 parent a62917b commit 2d81c7b
Showing 1 changed file with 72 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,93 @@ describe("<AddNewClusterForm />", () => {
const originalConsoleError = console.error;

beforeEach(() => {
console.error = jest.fn();

customRender(<AddNewClusterForm />, {
queryClient: true,
aquariumContext: true,
});
});
afterEach(() => {
console.error = originalConsoleError;

afterEach(() => {
cleanup();
jest.clearAllMocks();
});

it("renders all necessary elements by default", async () => {
const clusterTypeSelect = screen.getByRole("group", {
name: "Cluster type *",
describe("renders all necessary elements by default", () => {
it("renders Cluster type field", () => {
const clusterTypeSelect = screen.getByRole("group", {
name: "Cluster type *",
});
const clusterTypeOptions =
within(clusterTypeSelect).getAllByRole("radio");

expect(clusterTypeSelect).toBeEnabled();
expect(clusterTypeOptions).toHaveLength(3);
});
const clusterTypeOptions = within(clusterTypeSelect).getAllByRole("radio");
const clusterNameInput = screen.getByRole("textbox", {
name: "Cluster name *",

it("renders Cluster name field", () => {
const clusterNameInput = screen.getByRole("textbox", {
name: "Cluster name *",
});

expect(clusterNameInput).toBeEnabled();
});
const protocolSelect = screen.getByRole("combobox", {
name: "Protocol *",

it("renders Protocol field", () => {
const protocolSelect = screen.getByRole("combobox", {
name: "Protocol *",
});
const protocolSelectOptions =
within(protocolSelect).getAllByRole("option");

expect(protocolSelect).toBeEnabled();
expect(protocolSelectOptions).toHaveLength(7);
});
const protocolSelectOptions = within(protocolSelect).getAllByRole("option");
const kafkaFlavorSelect = screen.getByRole("combobox", {
name: "Kafka flavor *",

it("renders cluster type field", () => {
const clusterTypeSelect = screen.getByRole("group", {
name: "Cluster type *",
});
const clusterTypeOptions =
within(clusterTypeSelect).getAllByRole("radio");

expect(clusterTypeSelect).toBeEnabled();
expect(clusterTypeOptions).toHaveLength(3);
});
const kafkaFlavorSelectOptions =
within(kafkaFlavorSelect).getAllByRole("option");
const bootstrapServersInput = screen.getByRole("textbox", {
name: "Bootstrap servers *",

it("renders Kafka flavor field", () => {
const kafkaFlavorSelect = screen.getByRole("combobox", {
name: "Kafka flavor *",
});
const kafkaFlavorSelectOptions =
within(kafkaFlavorSelect).getAllByRole("option");

expect(kafkaFlavorSelect).toBeEnabled();
expect(kafkaFlavorSelectOptions).toHaveLength(6);
});
const restServersInput = screen.getByRole("textbox", {
name: "REST API servers (optional)",

it("renders Bootstrap servers field", () => {
const bootstrapServersInput = screen.getByRole("textbox", {
name: "Bootstrap servers *",
});

expect(bootstrapServersInput).toBeEnabled();
});

const submitButton = screen.getByRole("button", {
name: "Add new cluster",
it("renders REST API servers field", () => {
const restServersInput = screen.getByRole("textbox", {
name: "REST API servers (optional)",
});

expect(restServersInput).toBeEnabled();
});

expect(clusterTypeSelect).toBeEnabled();
expect(clusterTypeOptions).toHaveLength(3);
expect(clusterNameInput).toBeEnabled();
expect(protocolSelect).toBeEnabled();
expect(protocolSelectOptions).toHaveLength(7);
expect(kafkaFlavorSelect).toBeEnabled();
expect(kafkaFlavorSelectOptions).toHaveLength(6);
expect(bootstrapServersInput).toBeEnabled();
expect(restServersInput).toBeEnabled();
expect(submitButton).toBeEnabled();
it("renders Add new server button", () => {
const submitButton = screen.getByRole("button", {
name: "Add new cluster",
});

expect(submitButton).toBeEnabled();
});
});

it("shows an error message when the cluster name is empty", async () => {
Expand Down Expand Up @@ -250,6 +285,8 @@ describe("<AddNewClusterForm />", () => {
});

it("renders error message when submitting fails", async () => {
console.error = jest.fn();

mockAddNewClusterRequest.mockRejectedValue(new Error("Request failed"));

const clusterNameInput = screen.getByRole("textbox", {
Expand Down Expand Up @@ -287,5 +324,7 @@ describe("<AddNewClusterForm />", () => {
position: "bottom-left",
});
expect(mockedUsedNavigate).not.toHaveBeenCalled();

console.error = originalConsoleError;
});
});

0 comments on commit 2d81c7b

Please sign in to comment.