mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
more tests
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
80d1a28d28
commit
a1c4c9e830
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
|
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
||||||
import { NamespaceSelectFilter } from "../namespace-select-filter";
|
import { NamespaceSelectFilter } from "../namespace-select-filter";
|
||||||
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||||
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
import { DiRender, renderFor } from "../../test-utils/renderFor";
|
||||||
@ -109,9 +110,9 @@ describe("NamespaceSelectFilter", () => {
|
|||||||
|
|
||||||
it ("renders selected namespaces", async () => {
|
it ("renders selected namespaces", async () => {
|
||||||
namespaceStore.items.replace([
|
namespaceStore.items.replace([
|
||||||
new Namespace({ kind: "Namespace", apiVersion: "v1", metadata: { name: "one ", uid: "one", 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: "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: "three", uid: "three", resourceVersion: "1" }}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
namespaceStore.selectNamespaces(["two", "three"]);
|
namespaceStore.selectNamespaces(["two", "three"]);
|
||||||
@ -121,4 +122,22 @@ describe("NamespaceSelectFilter", () => {
|
|||||||
|
|
||||||
expect(select.getElementsByClassName("Select__placeholder")[0].innerHTML).toEqual("Namespaces: two, three");
|
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(<><NamespaceSelectFilter showIcons={false} /></>);
|
||||||
|
|
||||||
|
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"]));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,10 +28,10 @@ import { components, InputActionMeta, PlaceholderProps } from "react-select";
|
|||||||
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
||||||
|
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { NamespaceSelect } from "./namespace-select";
|
import { NamespaceSelect, NamespaceSelectProps } from "./namespace-select";
|
||||||
import type { NamespaceStore } from "./namespace.store";
|
import type { NamespaceStore } from "./namespace.store";
|
||||||
|
|
||||||
import type { SelectOption, SelectProps } from "../select";
|
import type { SelectOption } from "../select";
|
||||||
import { isMac } from "../../../common/vars";
|
import { isMac } from "../../../common/vars";
|
||||||
import namespaceStoreInjectable from "./namespace.store.injectable";
|
import namespaceStoreInjectable from "./namespace.store.injectable";
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ const Placeholder = observer((props: PlaceholderProps<any, boolean> & NamespaceS
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface NamespaceSelectFilterProps extends SelectProps {
|
export interface NamespaceSelectFilterProps extends NamespaceSelectProps {
|
||||||
maxItems?: number;
|
maxItems?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ export class NonInjectedNamespaceSelectFilter extends React.Component<NamespaceS
|
|||||||
: this.namespaceStore.areAllSelectedImplicitly;
|
: this.namespaceStore.areAllSelectedImplicitly;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center select-option-label">
|
||||||
<Icon small material={ namespace ? "layers" : "panorama_wide_angle" } />
|
<Icon small material={ namespace ? "layers" : "panorama_wide_angle" } />
|
||||||
<span>{label}</span>
|
<span>{label}</span>
|
||||||
{isSelected && <Icon small material="check" className="box right" />}
|
{isSelected && <Icon small material="check" className="box right" />}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import { namespaceStore, NamespaceStore } from "./namespace.store";
|
|||||||
const namespaceStoreInjectable: Injectable<
|
const namespaceStoreInjectable: Injectable<
|
||||||
NamespaceStore
|
NamespaceStore
|
||||||
> = {
|
> = {
|
||||||
getDependencies: di => ({}),
|
getDependencies: () => ({}),
|
||||||
|
|
||||||
instantiate: () => namespaceStore,
|
instantiate: () => namespaceStore,
|
||||||
lifecycle: lifecycleEnum.singleton,
|
lifecycle: lifecycleEnum.singleton,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user