mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Add behavioural tests for deleting sub namespaces
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
89cf491bc0
commit
bb5876b39c
4 files changed
+2848
-16
No files matched your search
@@ -162,7 +162,7 @@ class NonInjectedKubeObjectMenu<Kube extends KubeObject> extends React.Component
|
||||
<MenuItem
|
||||
key={`context-menu-item-${index}`}
|
||||
onClick={() => item.onClick(object)}
|
||||
data-testid={`menu-action-${item.title.toLowerCase().replace(/\s+/, "-")}`}
|
||||
data-testid={`menu-action-${item.title.toLowerCase().replace(/\s+/, "-")}-for-${object.selfLink}`}
|
||||
>
|
||||
<Icon
|
||||
{...item.icon}
|
||||
@@ -191,6 +191,7 @@ class NonInjectedKubeObjectMenu<Kube extends KubeObject> extends React.Component
|
||||
return (
|
||||
<MenuActions
|
||||
id={`menu-actions-for-kube-object-menu-for-${object?.getId()}`}
|
||||
data-testid={`menu-actions-for-kube-object-menu-for-${object?.getId()}`}
|
||||
className={cssNames("KubeObjectMenu", className)}
|
||||
onOpen={object ? () => this.emitOnContextMenuOpen(object) : undefined}
|
||||
{...menuProps}
|
||||
|
||||
@@ -77,18 +77,33 @@ type WindowDiCallback = (container: { windowDi: DiContainer }) => void | Promise
|
||||
|
||||
type LensWindowWithHelpers = LensWindow & { rendered: RenderResult; di: DiContainer };
|
||||
|
||||
const createNamespacesFor = (namespaces: Set<string>): Namespace[] => (
|
||||
Array.from(namespaces, (namespace) => new Namespace({
|
||||
apiVersion: "v1",
|
||||
kind: "Namespace",
|
||||
metadata: {
|
||||
name: namespace,
|
||||
resourceVersion: "1",
|
||||
selfLink: `/api/v1/namespaces/${namespace}`,
|
||||
uid: `namespace-${namespace}`,
|
||||
const createNamespace = (namespace: string) => new Namespace({
|
||||
apiVersion: "v1",
|
||||
kind: "Namespace",
|
||||
metadata: {
|
||||
name: namespace,
|
||||
resourceVersion: "1",
|
||||
selfLink: `/api/v1/namespaces/${namespace}`,
|
||||
uid: `namespace-${namespace}`,
|
||||
},
|
||||
});
|
||||
|
||||
const createSubNamespace = (namespace: string, parent: Namespace) => new Namespace({
|
||||
apiVersion: "v1",
|
||||
kind: "Namespace",
|
||||
metadata: {
|
||||
name: namespace,
|
||||
resourceVersion: "1",
|
||||
selfLink: `/api/v1/namespaces/${namespace}`,
|
||||
uid: `namespace-${namespace}`,
|
||||
annotations: {
|
||||
"hnc.x-k8s.io/subnamespace-of": parent.getName(),
|
||||
},
|
||||
}))
|
||||
);
|
||||
labels: {
|
||||
[`${parent.getName()}.tree.hnc.x-k8s.io/depth`]: "1",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export interface ApplicationBuilder {
|
||||
mainDi: DiContainer;
|
||||
@@ -144,6 +159,7 @@ export interface ApplicationBuilder {
|
||||
};
|
||||
namespaces: {
|
||||
add: (namespace: string) => void;
|
||||
addSubNamespace: (namespace: string, parent: string) => void;
|
||||
select: (namespace: string) => void;
|
||||
};
|
||||
helmCharts: {
|
||||
@@ -303,7 +319,6 @@ export const getApplicationBuilder = () => {
|
||||
|
||||
let applicationHasStarted = false;
|
||||
|
||||
const namespaces = observable.set<string>();
|
||||
const namespaceItems = observable.array<Namespace>();
|
||||
const selectedNamespaces = observable.set<string>();
|
||||
const startApplication = mainDi.inject(startApplicationInjectionToken);
|
||||
@@ -385,8 +400,14 @@ export const getApplicationBuilder = () => {
|
||||
},
|
||||
namespaces: {
|
||||
add: action((namespace) => {
|
||||
namespaces.add(namespace);
|
||||
namespaceItems.replace(createNamespacesFor(namespaces));
|
||||
namespaceItems.push(createNamespace(namespace));
|
||||
}),
|
||||
addSubNamespace: action((namespace, parent) => {
|
||||
const parentNamespace = namespaceItems.find((n) => n.getName() === parent);
|
||||
|
||||
assert(parentNamespace, `Cannot find namespace with name="${parent}"`);
|
||||
|
||||
namespaceItems.push(createSubNamespace(namespace, parentNamespace));
|
||||
}),
|
||||
select: action((namespace) => {
|
||||
const selectedNamespacesStorage = builder.applicationWindow.only.di.inject(selectedNamespacesStorageInjectable);
|
||||
@@ -545,7 +566,7 @@ export const getApplicationBuilder = () => {
|
||||
return Array.from(selectedNamespaces);
|
||||
},
|
||||
get allowedNamespaces() {
|
||||
return Array.from(namespaces);
|
||||
return Array.from(namespaceItems, n => n.getName());
|
||||
},
|
||||
contextItems: namespaceItems,
|
||||
api: windowDi.inject(namespaceApiInjectable),
|
||||
@@ -556,6 +577,7 @@ export const getApplicationBuilder = () => {
|
||||
pickOnlySelected: () => [],
|
||||
isSelectedAll: () => false,
|
||||
getTotalCount: () => namespaceItems.length,
|
||||
isSelected: () => false,
|
||||
} as Partial<NamespaceStore> as NamespaceStore));
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user