mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix catalog.test.tsx
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
387b044e69
commit
48d5aeb18c
@ -12,7 +12,7 @@ const catalogPreviousActiveTabStorageInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createStorage = di.inject(createStorageInjectable);
|
const createStorage = di.inject(createStorageInjectable);
|
||||||
|
|
||||||
return createStorage(
|
return createStorage<string | null>(
|
||||||
"catalog-previous-active-tab",
|
"catalog-previous-active-tab",
|
||||||
browseCatalogTab,
|
browseCatalogTab,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -61,28 +61,25 @@ class MockCatalogEntity extends CatalogEntity {
|
|||||||
constructor(data: CatalogEntityData, public onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
constructor(data: CatalogEntityData, public onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public onContextMenuOpen(): void | Promise<void> {}
|
function createMockCatalogEntity(onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
||||||
public onSettingsOpen(): void | Promise<void> {}
|
return new MockCatalogEntity({
|
||||||
|
metadata: {
|
||||||
|
uid: "a_catalogEntity_uid",
|
||||||
|
name: "a catalog entity",
|
||||||
|
labels: {
|
||||||
|
test: "label",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "",
|
||||||
|
},
|
||||||
|
spec: {},
|
||||||
|
}, onRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("<Catalog />", () => {
|
describe("<Catalog />", () => {
|
||||||
function createMockCatalogEntity(onRun: (context: CatalogEntityActionContext) => void | Promise<void>) {
|
|
||||||
return new MockCatalogEntity({
|
|
||||||
metadata: {
|
|
||||||
uid: "a_catalogEntity_uid",
|
|
||||||
name: "a catalog entity",
|
|
||||||
labels: {
|
|
||||||
test: "label",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
phase: "",
|
|
||||||
},
|
|
||||||
spec: {},
|
|
||||||
}, onRun);
|
|
||||||
}
|
|
||||||
|
|
||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
let catalogEntityStore: CatalogEntityStore;
|
let catalogEntityStore: CatalogEntityStore;
|
||||||
let catalogEntityRegistry: CatalogEntityRegistry;
|
let catalogEntityRegistry: CatalogEntityRegistry;
|
||||||
@ -95,14 +92,12 @@ describe("<Catalog />", () => {
|
|||||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||||
|
|
||||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||||
|
|
||||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||||
di.permitSideEffects(appVersionInjectable);
|
di.permitSideEffects(appVersionInjectable);
|
||||||
|
|
||||||
await di.runSetups();
|
await di.runSetups();
|
||||||
|
|
||||||
mockFs();
|
mockFs();
|
||||||
|
|
||||||
UserStore.createInstance();
|
UserStore.createInstance();
|
||||||
ThemeStore.createInstance();
|
ThemeStore.createInstance();
|
||||||
CatalogEntityDetailRegistry.createInstance();
|
CatalogEntityDetailRegistry.createInstance();
|
||||||
@ -133,7 +128,6 @@ describe("<Catalog />", () => {
|
|||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
ThemeStore.resetInstance();
|
ThemeStore.resetInstance();
|
||||||
CatalogEntityDetailRegistry.resetInstance();
|
CatalogEntityDetailRegistry.resetInstance();
|
||||||
|
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
mockFs.restore();
|
mockFs.restore();
|
||||||
@ -152,9 +146,7 @@ describe("<Catalog />", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
render(
|
render(<Catalog />);
|
||||||
<Catalog />,
|
|
||||||
);
|
|
||||||
|
|
||||||
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import type { CatalogCategory, CatalogCategoryRegistry, CatalogEntity } from "..
|
|||||||
import { CatalogAddButton } from "./catalog-add-button";
|
import { CatalogAddButton } from "./catalog-add-button";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { MainLayout } from "../layout/main-layout";
|
import { MainLayout } from "../layout/main-layout";
|
||||||
|
import type { StorageLayer } from "../../utils";
|
||||||
import { prevDefault } from "../../utils";
|
import { prevDefault } from "../../utils";
|
||||||
import { CatalogEntityDetails } from "./catalog-entity-details";
|
import { CatalogEntityDetails } from "./catalog-entity-details";
|
||||||
import { CatalogMenu } from "./catalog-menu";
|
import { CatalogMenu } from "./catalog-menu";
|
||||||
@ -47,7 +48,7 @@ import catalogCategoryRegistryInjectable from "../../../common/catalog/category-
|
|||||||
import onContextMenuOpenInjectable from "../../../common/catalog/on-context-menu-open.injectable";
|
import onContextMenuOpenInjectable from "../../../common/catalog/on-context-menu-open.injectable";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
catalogPreviousActiveTabStorage: { set: (value: string ) => void; get: () => string };
|
catalogPreviousActiveTabStorage: StorageLayer<string | null>;
|
||||||
catalogEntityStore: CatalogEntityStore;
|
catalogEntityStore: CatalogEntityStore;
|
||||||
getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns;
|
getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns;
|
||||||
customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>;
|
customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>;
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export interface AvatarProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
onClick?: MouseEventHandler<HTMLDivElement>;
|
onClick?: MouseEventHandler<HTMLDivElement>;
|
||||||
|
"data-testid"?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNameParts(name: string): string[] {
|
function getNameParts(name: string): string[] {
|
||||||
@ -61,40 +62,48 @@ function getLabelFromTitle(title: string) {
|
|||||||
].filter(isDefined).join("");
|
].filter(isDefined).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Avatar(props: AvatarProps) {
|
export const Avatar = ({
|
||||||
const { title, variant = "rounded", size = 32, colorHash, children, background, imgProps, src, className, disabled, id, onClick } = props;
|
title,
|
||||||
const colorFromHash = randomColor({ seed: colorHash, luminosity: "dark" });
|
variant = "rounded",
|
||||||
|
size = 32,
|
||||||
const renderContents = () => {
|
colorHash,
|
||||||
if (src) {
|
children,
|
||||||
return (
|
background,
|
||||||
|
imgProps,
|
||||||
|
src,
|
||||||
|
className,
|
||||||
|
disabled,
|
||||||
|
id,
|
||||||
|
onClick,
|
||||||
|
"data-testid": dataTestId,
|
||||||
|
}: AvatarProps) => (
|
||||||
|
<div
|
||||||
|
className={cssNames(styles.Avatar, {
|
||||||
|
[styles.circle]: variant == "circle",
|
||||||
|
[styles.rounded]: variant == "rounded",
|
||||||
|
[styles.disabled]: disabled,
|
||||||
|
}, className)}
|
||||||
|
style={{
|
||||||
|
width: `${size}px`,
|
||||||
|
height: `${size}px`,
|
||||||
|
background: background || (
|
||||||
|
src
|
||||||
|
? "transparent"
|
||||||
|
: randomColor({ seed: colorHash, luminosity: "dark" })
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
id={id}
|
||||||
|
onClick={onClick}
|
||||||
|
data-testid={dataTestId}
|
||||||
|
>
|
||||||
|
{src
|
||||||
|
? (
|
||||||
<img
|
<img
|
||||||
src={src}
|
src={src}
|
||||||
{...imgProps}
|
{...imgProps}
|
||||||
alt={title}
|
alt={title}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
: children || getLabelFromTitle(title)}
|
||||||
|
</div>
|
||||||
return children || getLabelFromTitle(title);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cssNames(styles.Avatar, {
|
|
||||||
[styles.circle]: variant == "circle",
|
|
||||||
[styles.rounded]: variant == "rounded",
|
|
||||||
[styles.disabled]: disabled,
|
|
||||||
}, className)}
|
|
||||||
style={{
|
|
||||||
width: `${size}px`,
|
|
||||||
height: `${size}px`,
|
|
||||||
background: background || (src ? "transparent" : colorFromHash),
|
|
||||||
}}
|
|
||||||
id={id}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
{renderContents()}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user