diff --git a/src/renderer/components/+namespaces/__tests__/namespace-select-filter.test.tsx b/src/renderer/components/+namespaces/__tests__/namespace-select-filter.test.tsx index dd8c12dc04..ca927ccb4a 100644 --- a/src/renderer/components/+namespaces/__tests__/namespace-select-filter.test.tsx +++ b/src/renderer/components/+namespaces/__tests__/namespace-select-filter.test.tsx @@ -21,6 +21,7 @@ import React from "react"; import "@testing-library/jest-dom/extend-expect"; +import { fireEvent, screen, waitFor } from "@testing-library/react"; import { NamespaceSelectFilter } from "../namespace-select-filter"; import { getDiForUnitTesting } from "../../getDiForUnitTesting"; import { DiRender, renderFor } from "../../test-utils/renderFor"; @@ -109,9 +110,9 @@ describe("NamespaceSelectFilter", () => { it ("renders selected namespaces", async () => { namespaceStore.items.replace([ - new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "one ", uid: "one", resourceVersion: "1" }}), - new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "two ", uid: "two", resourceVersion: "1" }}), - new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "three ", uid: "three", resourceVersion: "1" }}), + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "one", uid: "one", resourceVersion: "1" }}), + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "two", uid: "two", resourceVersion: "1" }}), + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "three", uid: "three", resourceVersion: "1" }}), ]); namespaceStore.selectNamespaces(["two", "three"]); @@ -121,4 +122,22 @@ describe("NamespaceSelectFilter", () => { expect(select.getElementsByClassName("Select__placeholder")[0].innerHTML).toEqual("Namespaces: two, three"); }); + + it ("allows to select namespaces", async () => { + namespaceStore.items.replace([ + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "one", uid: "one", resourceVersion: "1" }}), + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "two", uid: "two", resourceVersion: "1" }}), + new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "three", uid: "three", resourceVersion: "1" }}), + ]); + + const { container } = render(<>); + + fireEvent.click(container.querySelector(".Select__placeholder")); + + await waitFor(() => screen.getByText("one")); + fireEvent.click(screen.getByText("one")); + + expect(container.querySelector(".Select__placeholder").innerHTML).toEqual("Namespace: one"); + expect(namespaceStore.selectedNames).toEqual(new Set(["one"])); + }); }); diff --git a/src/renderer/components/+namespaces/namespace-select-filter.tsx b/src/renderer/components/+namespaces/namespace-select-filter.tsx index e23f3e6cd3..8f01cdba70 100644 --- a/src/renderer/components/+namespaces/namespace-select-filter.tsx +++ b/src/renderer/components/+namespaces/namespace-select-filter.tsx @@ -28,10 +28,10 @@ import { components, InputActionMeta, PlaceholderProps } from "react-select"; import { action, computed, makeObservable, observable, reaction } from "mobx"; import { Icon } from "../icon"; -import { NamespaceSelect } from "./namespace-select"; +import { NamespaceSelect, NamespaceSelectProps } from "./namespace-select"; import type { NamespaceStore } from "./namespace.store"; -import type { SelectOption, SelectProps } from "../select"; +import type { SelectOption } from "../select"; import { isMac } from "../../../common/vars"; import namespaceStoreInjectable from "./namespace.store.injectable"; @@ -67,7 +67,7 @@ const Placeholder = observer((props: PlaceholderProps & NamespaceS ); }); -export interface NamespaceSelectFilterProps extends SelectProps { +export interface NamespaceSelectFilterProps extends NamespaceSelectProps { maxItems?: number; } @@ -133,7 +133,7 @@ export class NonInjectedNamespaceSelectFilter extends React.Component +
{label} {isSelected && } diff --git a/src/renderer/components/+namespaces/namespace.store.injectable.ts b/src/renderer/components/+namespaces/namespace.store.injectable.ts index ee28ff53d8..0bdfb51b3f 100644 --- a/src/renderer/components/+namespaces/namespace.store.injectable.ts +++ b/src/renderer/components/+namespaces/namespace.store.injectable.ts @@ -25,7 +25,7 @@ import { namespaceStore, NamespaceStore } from "./namespace.store"; const namespaceStoreInjectable: Injectable< NamespaceStore > = { - getDependencies: di => ({}), + getDependencies: () => ({}), instantiate: () => namespaceStore, lifecycle: lifecycleEnum.singleton,