From 6897ef1c1c2a8afa35a87f7c9ec38af456a7666d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Dobr=C3=BD?= Date: Thu, 18 Apr 2024 05:04:20 +0200 Subject: [PATCH] Fix tests with Collapse animations, ignore coverage folder --- .idea/grpcflair.iml | 1 + web/__tests__/components/Endpoints.test.tsx | 61 ++++----------------- web/src/components/Endpoints.tsx | 12 ++-- web/src/components/parts/Type.tsx | 1 + web/tests/mocks/react-bootstrap.tsx | 15 +++++ 5 files changed, 35 insertions(+), 55 deletions(-) create mode 100644 web/tests/mocks/react-bootstrap.tsx diff --git a/.idea/grpcflair.iml b/.idea/grpcflair.iml index 8c20726..dde29ad 100644 --- a/.idea/grpcflair.iml +++ b/.idea/grpcflair.iml @@ -6,6 +6,7 @@ + diff --git a/web/__tests__/components/Endpoints.test.tsx b/web/__tests__/components/Endpoints.test.tsx index 27574e2..30aef64 100644 --- a/web/__tests__/components/Endpoints.test.tsx +++ b/web/__tests__/components/Endpoints.test.tsx @@ -1,11 +1,10 @@ +import "../../tests/mocks/react-bootstrap"; import { act, render, screen } from "@testing-library/react"; import Endpoints from "@/components/Endpoints"; import { SourceContext } from "@/contexts/SourceContext"; import { DEFAULT_HOSTNAME } from "@/types/constants"; import { context } from "../../tests/protobufjs-source"; -const COLLAPSE_TIMEOUT = 2000; - describe("Endpoints", () => { beforeEach(async () => { await act(async () => { @@ -43,89 +42,53 @@ describe("Endpoints", () => { it("collapse services", async () => { const services = screen.getByTestId("services"); + expect(services).toBeVisible(); - const button = services.querySelector("button"); + const button = screen.getByText("Services"); expect(button).toBeInTheDocument(); if (!button) { throw new Error("Button not found"); } - const detailsVisible = screen.queryAllByTestId("service-detail"); - detailsVisible.forEach((detail) => { - expect(detail).toBeVisible(); - }); - await act(async () => { button.click(); }); - new Promise((resolve) => { - setTimeout(() => { - const detailsHidden = screen.queryAllByTestId("service-detail"); - detailsHidden.forEach((detail) => { - expect(detail).not.toBeVisible(); - }); - resolve(undefined); - }, COLLAPSE_TIMEOUT); - }); + expect(services).not.toBeVisible(); }); it("collapse types", async () => { - const services = screen.getByTestId("types"); + const types = screen.getByTestId("types"); + expect(types).toBeVisible(); - const button = services.querySelector("button"); + const button = screen.getByText("Types"); expect(button).toBeInTheDocument(); if (!button) { throw new Error("Button not found"); } - const detailsVisible = screen.queryAllByTestId("type-detail"); - detailsVisible.forEach((detail) => { - expect(detail).toBeVisible(); - }); - await act(async () => { button.click(); }); - new Promise((resolve) => { - setTimeout(() => { - const detailsHidden = screen.queryAllByTestId("type-detail"); - detailsHidden.forEach((detail) => { - expect(detail).not.toBeVisible(); - }); - resolve(undefined); - }, COLLAPSE_TIMEOUT); - }); + expect(types).not.toBeVisible(); }); it("collapse enums", async () => { - const services = screen.getByTestId("enums"); + const enums = screen.getByTestId("enums"); + expect(enums).toBeVisible(); - const button = services.querySelector("button"); + const button = screen.getByText("Enums"); expect(button).toBeInTheDocument(); if (!button) { throw new Error("Button not found"); } - const detailsVisible = screen.queryAllByTestId("enum-detail"); - detailsVisible.forEach((detail) => { - expect(detail).toBeVisible(); - }); - await act(async () => { button.click(); }); - new Promise((resolve) => { - setTimeout(() => { - const detailsHidden = screen.queryAllByTestId("enum-detail"); - detailsHidden.forEach((detail) => { - expect(detail).not.toBeVisible(); - }); - resolve(undefined); - }, COLLAPSE_TIMEOUT); - }); + expect(enums).not.toBeVisible(); }); }); diff --git a/web/src/components/Endpoints.tsx b/web/src/components/Endpoints.tsx index 558209a..a2214f5 100644 --- a/web/src/components/Endpoints.tsx +++ b/web/src/components/Endpoints.tsx @@ -82,7 +82,7 @@ export default function Endpoints() { return (
-
+
Services -
+
{services.map((service) => ( ))} @@ -103,7 +103,7 @@ export default function Endpoints() {
-
+
Types -
+
{types.map((type) => ( @@ -126,7 +126,7 @@ export default function Endpoints() {
-
+
Enums -
+
{enums.map((enumType) => ( diff --git a/web/src/components/parts/Type.tsx b/web/src/components/parts/Type.tsx index d6d0af6..827f779 100644 --- a/web/src/components/parts/Type.tsx +++ b/web/src/components/parts/Type.tsx @@ -45,6 +45,7 @@ export default function Type({ type, dark, expanded }: TypeProps) { dark ? "bg-dark text-light" : "", ].join(" ")} data-testid="type-detail" + data-type-name={type.fullName} >