-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
catalog-add-button.test.tsx
89 lines (75 loc) · 2.36 KB
/
catalog-add-button.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import React from "react";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { CatalogCategorySpec } from "../../../../common/catalog";
import { CatalogCategory } from "../../../../common/catalog";
import { CatalogAddButton } from "../catalog-add-button";
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
import { type DiRender, renderFor } from "../../test-utils/renderFor";
class TestCatalogCategory extends CatalogCategory {
public readonly apiVersion = "catalog.k8slens.dev/v1alpha1";
public readonly kind = "CatalogCategory";
public metadata = {
name: "Test Category",
icon: "",
};
public spec: CatalogCategorySpec = {
group: "entity.k8slens.dev",
versions: [],
names: {
kind: "Test",
},
};
}
describe("CatalogAddButton", () => {
let render: DiRender;
beforeEach(() => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
render = renderFor(di);
});
it("opens Add menu", async () => {
const category = new TestCatalogCategory();
category.on("catalogAddMenu", ctx => {
ctx.menuItems.push(
{
icon: "text_snippet",
title: "Add from kubeconfig",
onClick: () => {},
},
);
});
render(<CatalogAddButton category={category}/>);
userEvent.hover(screen.getByLabelText("SpeedDial CatalogAddButton"));
await screen.findByTitle("Add from kubeconfig");
});
it("filters menu items", async () => {
const category = new TestCatalogCategory();
category.on("catalogAddMenu", ctx => {
ctx.menuItems.push(
{
icon: "text_snippet",
title: "foobar",
onClick: () => {},
},
);
ctx.menuItems.push(
{
icon: "text_snippet",
title: "Add from kubeconfig",
onClick: () => {},
},
);
});
category.addMenuFilter(item => item.title === "foobar");
render(<CatalogAddButton category={category}/>);
userEvent.hover(screen.getByLabelText("SpeedDial CatalogAddButton"));
await expect(screen.findByTitle("Add from kubeconfig"))
.rejects
.toThrow();
await screen.findByTitle("foobar");
});
});