chore: Fixup tests snapshots to match new testid behaviour

- Move order-of-sidebar-items to the new package
- Fix the extension sidebar item registrator

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-05-31 14:23:53 -04:00
1 parent 7924ab5504
commit 27aaa3623d
38 files changed
+1482 -16995

No files matched your search

@@ -8,7 +8,7 @@ import { extensionRegistratorInjectionToken } from "../../../extensions/extensio
import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar";
import { computed } from "mobx";
import routesInjectable from "../../routes/routes.injectable";
import { matches, noop } from "lodash/fp";
import { matches } from "lodash/fp";
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
import { getExtensionRoutePath } from "../../routes/for-extension";
@@ -23,66 +23,55 @@ const extensionSidebarItemRegistratorInjectable = getInjectable({
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const routes = di.inject(routesInjectable);
const extensionShouldBeEnabledForClusterFrame = di.inject(extensionShouldBeEnabledForClusterFrameInjectable, extension);
const extensionRoutes = computed(() => routes.get().filter(matches({ extension })));
return computed(() => {
const extensionRoutes = routes.get().filter(matches({ extension }));
return computed(() => extension.clusterPageMenus.map((registration) => {
const {
components,
title,
orderNumber = 9999,
parentId: rawParentId,
visible,
id: rawId,
target,
} = registration;
const id = rawId
? `sidebar-item-${extension.sanitizedExtensionId}-${rawId}`
: `sidebar-item-${extension.sanitizedExtensionId}`;
const parentId = rawParentId
? `sidebar-item-${extension.sanitizedExtensionId}-${rawParentId}`
: null;
const targetRoutePath = getExtensionRoutePath(extension, target?.pageId);
const targetRoute = computed(() => extensionRoutes.get().find(matches({ path: targetRoutePath })));
return extension.clusterPageMenus.map((registration) => {
const targetRoutePath = getExtensionRoutePath(
extension,
registration.target?.pageId,
);
return getInjectable({
id,
instantiate: () => ({
orderNumber,
parentId,
isVisible: computed(() => extensionShouldBeEnabledForClusterFrame.value.get() && (visible?.get() ?? true)),
title,
getIcon: () => (components.Icon && <components.Icon />),
onClick: () => {
const route = targetRoute.get();
const targetRoute = extensionRoutes.find(
matches({ path: targetRoutePath }),
);
if (route) {
navigateToRoute(route);
}
},
isActive: computed(() => {
const route = targetRoute.get();
const isVisible = computed(() => {
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
return false;
}
if (!route) {
return false;
}
if (!registration.visible) {
return true;
}
return registration.visible.get();
});
const id = registration.id ?
`${extension.sanitizedExtensionId}-${registration.id}`
: extension.sanitizedExtensionId;
return getInjectable({
id: `sidebar-item-${id}`,
instantiate: () => ({
orderNumber: registration.orderNumber ?? 9999,
parentId: registration.parentId
? `${extension.sanitizedExtensionId}-${registration.parentId}`
: null,
isVisible,
title: registration.title,
getIcon: registration.components.Icon
? () => <registration.components.Icon />
: undefined,
...(targetRoute
? {
onClick: () => navigateToRoute(targetRoute),
isActive: di.inject(
routeIsActiveInjectable,
targetRoute,
),
}
: { onClick: noop }),
return di.inject(routeIsActiveInjectable, route).get();
}),
injectionToken: sidebarItemInjectionToken,
});
}),
injectionToken: sidebarItemInjectionToken,
});
});
}));
},
injectionToken: extensionRegistratorInjectionToken,
@@ -82,7 +82,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
<a
aria-current="page"
class="navItem active"
data-testid="sidebar-item-link-for-cluster-overview"
data-testid="link-for-sidebar-item-cluster-overview"
href="/"
>
<i
@@ -114,7 +114,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-nodes"
data-testid="link-for-sidebar-item-nodes"
href="/"
>
<i
@@ -152,7 +152,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-workloads"
data-testid="link-for-sidebar-item-workloads"
href="/"
>
<i
@@ -204,6 +204,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-workloads"
>
<span
class="icon"
@@ -214,31 +215,6 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-config"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-config"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="list"
>
list
</span>
</i>
<span>
Config
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -246,7 +222,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-network"
data-testid="link-for-sidebar-item-network"
href="/"
>
<i
@@ -264,6 +240,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-network"
>
<span
class="icon"
@@ -274,31 +251,6 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-storage"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-storage"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="storage"
>
storage
</span>
</i>
<span>
Storage
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -306,7 +258,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-namespaces"
data-testid="link-for-sidebar-item-namespaces"
href="/"
>
<i
@@ -331,7 +283,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-helm"
data-testid="link-for-sidebar-item-helm"
href="/"
>
<i
@@ -383,66 +335,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
>
<span
class="icon"
data-icon-name="keyboard_arrow_down"
>
keyboard_arrow_down
</span>
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-user-management"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-user-management"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="security"
>
security
</span>
</i>
<span>
Access Control
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-custom-resources"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-custom-resources"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="extension"
>
extension
</span>
</i>
<span>
Custom Resources
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-helm"
>
<span
class="icon"
@@ -686,7 +579,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
<a
aria-current="page"
class="navItem active"
data-testid="sidebar-item-link-for-cluster-overview"
data-testid="link-for-sidebar-item-cluster-overview"
href="/"
>
<i
@@ -718,7 +611,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-nodes"
data-testid="link-for-sidebar-item-nodes"
href="/"
>
<i
@@ -756,7 +649,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-workloads"
data-testid="link-for-sidebar-item-workloads"
href="/"
>
<i
@@ -808,6 +701,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-workloads"
>
<span
class="icon"
@@ -818,31 +712,6 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-config"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-config"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="list"
>
list
</span>
</i>
<span>
Config
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -850,7 +719,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-network"
data-testid="link-for-sidebar-item-network"
href="/"
>
<i
@@ -868,6 +737,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-network"
>
<span
class="icon"
@@ -878,31 +748,6 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-storage"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-storage"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="storage"
>
storage
</span>
</i>
<span>
Storage
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -910,7 +755,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-namespaces"
data-testid="link-for-sidebar-item-namespaces"
href="/"
>
<i
@@ -935,7 +780,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
>
<a
class="navItem"
data-testid="sidebar-item-link-for-helm"
data-testid="link-for-sidebar-item-helm"
href="/"
>
<i
@@ -987,66 +832,7 @@ exports[`<ClusterFrame /> given cluster with list nodes and namespaces permissio
</span>
<i
class="Icon expandIcon material focusable"
>
<span
class="icon"
data-icon-name="keyboard_arrow_down"
>
keyboard_arrow_down
</span>
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-user-management"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-user-management"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="security"
>
security
</span>
</i>
<span>
Access Control
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-custom-resources"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-custom-resources"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="extension"
>
extension
</span>
</i>
<span>
Custom Resources
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-helm"
>
<span
class="icon"
@@ -1297,7 +1083,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
<a
aria-current="page"
class="navItem active"
data-testid="sidebar-item-link-for-workloads"
data-testid="link-for-sidebar-item-workloads"
href="/"
>
<i
@@ -1349,6 +1135,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-workloads"
>
<span
class="icon"
@@ -1359,31 +1146,6 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-config"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-config"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="list"
>
list
</span>
</i>
<span>
Config
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -1391,7 +1153,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
>
<a
class="navItem"
data-testid="sidebar-item-link-for-network"
data-testid="link-for-sidebar-item-network"
href="/"
>
<i
@@ -1409,6 +1171,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-network"
>
<span
class="icon"
@@ -1419,31 +1182,6 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-storage"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-storage"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="storage"
>
storage
</span>
</i>
<span>
Storage
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
@@ -1451,7 +1189,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
>
<a
class="navItem"
data-testid="sidebar-item-link-for-namespaces"
data-testid="link-for-sidebar-item-namespaces"
href="/"
>
<i
@@ -1476,7 +1214,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
>
<a
class="navItem"
data-testid="sidebar-item-link-for-helm"
data-testid="link-for-sidebar-item-helm"
href="/"
>
<i
@@ -1528,66 +1266,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
</span>
<i
class="Icon expandIcon material focusable"
>
<span
class="icon"
data-icon-name="keyboard_arrow_down"
>
keyboard_arrow_down
</span>
</i>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-user-management"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-user-management"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="security"
>
security
</span>
</i>
<span>
Access Control
</span>
</a>
</div>
<div
class="SidebarItem"
data-is-active-test="false"
data-testid="sidebar-item-custom-resources"
>
<a
class="navItem"
data-testid="sidebar-item-link-for-custom-resources"
href="/"
>
<i
class="Icon material focusable"
>
<span
class="icon"
data-icon-name="extension"
>
extension
</span>
</i>
<span>
Custom Resources
</span>
<i
class="Icon expandIcon material focusable"
data-testid="expand-icon-for-sidebar-item-helm"
>
<span
class="icon"
@@ -1617,7 +1296,7 @@ exports[`<ClusterFrame /> given cluster without list nodes, but with namespaces
<div
class="Tab flex gaps align-center active"
data-is-active-test="true"
data-testid="tab-link-for-overview"
data-testid="tab-link-for-sidebar-item-workloads-overview"
role="tab"
tabindex="0"
>
@@ -14,13 +14,10 @@ const routeIsActiveInjectable = getInjectable({
instantiate: (di, route: Route<unknown>) => {
const currentPath = di.inject(currentPathInjectable);
return computed(
() =>
!!matchPath(currentPath.get(), {
path: route.path,
exact: true,
}),
);
return computed(() => !!matchPath(currentPath.get(), {
path: route.path,
exact: true,
}));
},
lifecycle: lifecycleEnum.keyedSingleton({