Rename old directory for behaviours as "features" to better communicate new intent with new directory structure to organize code and tests around features instead of technicalities (#6033)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Iku-tursoandJanne Savolainen authored and GitHub committed 2022-08-16 15:09:08 +03:00
1 parent 36077a9fea
commit 299922c8a7
107 files changed

No files matched your search

@@ -0,0 +1,120 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { RenderResult } from "@testing-library/react";
import type { SidebarItemRegistration } from "../../renderer/components/layout/sidebar-items.injectable";
import { sidebarItemsInjectionToken } from "../../renderer/components/layout/sidebar-items.injectable";
import { computed } from "mobx";
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import React from "react";
import isAllowedResourceInjectable from "../../common/utils/is-allowed-resource.injectable";
import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token";
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token";
describe("cluster - visibility of sidebar items", () => {
let applicationBuilder: ApplicationBuilder;
let rendered: RenderResult;
beforeEach(() => {
applicationBuilder = getApplicationBuilder();
applicationBuilder.setEnvironmentToClusterFrame();
applicationBuilder.beforeApplicationStart(({ rendererDi }) => {
rendererDi.register(testRouteInjectable);
rendererDi.register(testRouteComponentInjectable);
rendererDi.register(testSidebarItemsInjectable);
});
});
describe("given kube resource for route is not allowed", () => {
beforeEach(async () => {
rendered = await applicationBuilder.render();
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});
it("related sidebar item does not exist", () => {
const item = rendered.queryByTestId("sidebar-item-some-item-id");
expect(item).toBeNull();
});
describe("when kube resource becomes allowed", () => {
beforeEach(() => {
applicationBuilder.allowKubeResource("namespaces");
});
it("renders", () => {
expect(rendered.container).toMatchSnapshot();
});
it("related sidebar item exists", () => {
const item = rendered.queryByTestId("sidebar-item-some-item-id");
expect(item).not.toBeNull();
});
});
});
});
const testRouteInjectable = getInjectable({
id: "some-route-injectable-id",
instantiate: (di) => {
const someKubeResourceName = "namespaces";
const kubeResourceIsAllowed = di.inject(
isAllowedResourceInjectable,
someKubeResourceName,
);
return {
path: "/some-child-page",
isEnabled: kubeResourceIsAllowed,
clusterFrame: true,
};
},
injectionToken: frontEndRouteInjectionToken,
});
const testRouteComponentInjectable = getInjectable({
id: "some-child-page-route-component-injectable",
instantiate: (di) => ({
route: di.inject(testRouteInjectable),
Component: () => <div data-testid="some-child-page" />,
}),
injectionToken: routeSpecificComponentInjectionToken,
});
const testSidebarItemsInjectable = getInjectable({
id: "some-sidebar-item-injectable",
instantiate: (di) => {
const testRoute = di.inject(testRouteInjectable);
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
return computed((): SidebarItemRegistration[] => [
{
id: "some-item-id",
parentId: null,
title: "Some item",
onClick: () => navigateToRoute(testRoute),
isVisible: testRoute.isEnabled,
orderNumber: 42,
},
]);
},
injectionToken: sidebarItemsInjectionToken,
});