From e528c729bdc7c16ffe5ad02d210895c426797e94 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 25 May 2023 11:25:45 -0400 Subject: [PATCH] chore: Add tests for large number of namespaces Signed-off-by: Sebastian Malton --- .../namespace-select-filter.test.tsx.snap | 853 ++++++++++++++++++ .../namespace-select-filter.test.tsx | 55 +- 2 files changed, 907 insertions(+), 1 deletion(-) diff --git a/packages/core/src/renderer/components/namespace-select-filter/__snapshots__/namespace-select-filter.test.tsx.snap b/packages/core/src/renderer/components/namespace-select-filter/__snapshots__/namespace-select-filter.test.tsx.snap index b06a45557f..83f846442e 100644 --- a/packages/core/src/renderer/components/namespace-select-filter/__snapshots__/namespace-select-filter.test.tsx.snap +++ b/packages/core/src/renderer/components/namespace-select-filter/__snapshots__/namespace-select-filter.test.tsx.snap @@ -6144,3 +6144,856 @@ exports[` once the subscribe resolves when menu expand `; + +exports[` once the subscribe resolves with thousands of namespaces renders 1`] = ` + +
+
+ + +`; + +exports[` once the subscribe resolves with thousands of namespaces when menu expand icon is clicked renders 1`] = ` + +
+
+ + +`; + +exports[` once the subscribe resolves with thousands of namespaces when menu expand icon is clicked when menu expand icon is clicked again renders 1`] = ` + +
+
+ + +`; diff --git a/packages/core/src/renderer/components/namespace-select-filter/namespace-select-filter.test.tsx b/packages/core/src/renderer/components/namespace-select-filter/namespace-select-filter.test.tsx index 8772ece9f1..4eb2ec4b53 100644 --- a/packages/core/src/renderer/components/namespace-select-filter/namespace-select-filter.test.tsx +++ b/packages/core/src/renderer/components/namespace-select-filter/namespace-select-filter.test.tsx @@ -21,7 +21,7 @@ import { getDiForUnitTesting } from "../../getDiForUnitTesting"; import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable"; import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable"; import type { Disposer } from "@k8slens/utilities"; -import { disposer } from "@k8slens/utilities"; +import { array, disposer } from "@k8slens/utilities"; import { renderFor } from "../test-utils/renderFor"; import { NamespaceSelectFilter } from "./component"; import type { NamespaceStore } from "../namespaces/store"; @@ -479,4 +479,57 @@ describe("", () => { }); }); }); + + describe("once the subscribe resolves with thousands of namespaces", () => { + beforeEach(async () => { + await fetchMock.resolveSpecific([ + "https://127.0.0.1:12345/api-kube/api/v1/namespaces", + ], createMockResponseFromString("https://127.0.0.1:12345/api-kube/api/v1/namespaces", JSON.stringify({ + apiVersion: "v1", + kind: "NamespaceList", + metadata: {}, + items: array.filled(20000, undefined).map((_, i) => createNamespace(`test-${i}`)), + }))); + }); + + it("renders", () => { + expect(result.baseElement).toMatchSnapshot(); + }); + + describe("when menu expand icon is clicked", () => { + beforeEach(() => { + result.getByTestId("namespace-select-filter-expand-icon").click(); + }); + + it("renders", () => { + expect(result.baseElement).toMatchSnapshot(); + }); + + it("menu is open", () => { + expect(result.getByTestId("namespace-select-filter-list-container")).toBeInTheDocument(); + }); + + it("does not show all items in the DOM", () => { + expect(result.queryByTestId("namespace-select-filter-option-test-1500")).not.toBeInTheDocument(); + }); + + it("does show some items in the DOM", () => { + expect(result.getByTestId("namespace-select-filter-option-test-10")).toBeInTheDocument(); + }); + + describe("when menu expand icon is clicked again", () => { + beforeEach(() => { + result.getByTestId("namespace-select-filter-expand-icon").click(); + }); + + it("renders", () => { + expect(result.baseElement).toMatchSnapshot(); + }); + + it("menu is closed", () => { + expect(result.queryByTestId("namespace-select-filter-list-container")).not.toBeInTheDocument(); + }); + }); + }); + }); });