mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
41bcfd1278
commit
c131766361
79
src/renderer/components/icon/icon.test.tsx
Normal file
79
src/renderer/components/icon/icon.test.tsx
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import type { Logger } from "../../../common/logger";
|
||||||
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
|
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
|
||||||
|
import type { DiRender } from "../test-utils/renderFor";
|
||||||
|
import { renderFor } from "../test-utils/renderFor";
|
||||||
|
import { Icon } from "./icon";
|
||||||
|
|
||||||
|
describe("<Icon> href technical tests", () => {
|
||||||
|
let render: DiRender;
|
||||||
|
let logger: jest.MockedObject<Logger>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const di = getDiForUnitTesting();
|
||||||
|
|
||||||
|
logger = {
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
silly: jest.fn(),
|
||||||
|
warn: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
di.override(loggerInjectable, () => logger);
|
||||||
|
|
||||||
|
render = renderFor(di);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render an <Icon> with http href", () => {
|
||||||
|
const result = render((
|
||||||
|
<Icon
|
||||||
|
data-testid="my-icon"
|
||||||
|
href="http://localhost"
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(result.queryByTestId("my-icon")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render an <Icon> with https href", () => {
|
||||||
|
const result = render((
|
||||||
|
<Icon
|
||||||
|
data-testid="my-icon"
|
||||||
|
href="https://localhost"
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(result.queryByTestId("my-icon")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should warn about ws hrefs", () => {
|
||||||
|
const result = render((
|
||||||
|
<Icon
|
||||||
|
data-testid="my-icon"
|
||||||
|
href="ws://localhost"
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(result.queryByTestId("my-icon")).not.toBeInTheDocument();
|
||||||
|
expect(logger.warn).toBeCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should warn about javascript: hrefs", () => {
|
||||||
|
const result = render((
|
||||||
|
<Icon
|
||||||
|
data-testid="my-icon"
|
||||||
|
href="javascript:void 0"
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(result.queryByTestId("my-icon")).not.toBeInTheDocument();
|
||||||
|
expect(logger.warn).toBeCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user