1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Adding tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-12-01 14:46:43 +03:00
parent 5db16304a8
commit 9bca83560f
2 changed files with 46 additions and 5 deletions

View File

@ -26,7 +26,7 @@ import { HotbarStore } from "../../../common/hotbar-store";
export const ActiveHotbarName = observer(() => {
return (
<div className="flex items-center">
<div className="flex items-center" data-testid="current-hotbar-name">
<Icon material="bookmarks" smallest className="mr-2"/>{" "}
{HotbarStore.getInstance().getActive()?.name}
</div>

View File

@ -20,25 +20,49 @@
*/
import React from "react";
import mockFs from "mock-fs";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { BottomBar } from "./bottom-bar";
import { StatusBarRegistry } from "../../../extensions/registries";
import { HotbarStore } from "../../../common/hotbar-store";
import { AppPaths } from "../../../common/app-paths";
AppPaths.init();
jest.mock("electron", () => ({
app: {
getPath: () => "/foo",
getName: () => "lens",
setName: jest.fn(),
setPath: jest.fn(),
getPath: () => "tmp",
},
ipcMain: {
handle: jest.fn(),
on: jest.fn(),
removeAllListeners: jest.fn(),
off: jest.fn(),
send: jest.fn(),
},
}));
import { BottomBar } from "./bottom-bar";
import { StatusBarRegistry } from "../../../extensions/registries";
describe("<BottomBar />", () => {
beforeEach(() => {
const mockOpts = {
"tmp": {
"test-store.json": JSON.stringify({}),
},
};
mockFs(mockOpts);
StatusBarRegistry.createInstance();
HotbarStore.createInstance();
});
afterEach(() => {
StatusBarRegistry.resetInstance();
HotbarStore.resetInstance();
mockFs.restore();
});
it("renders w/o errors", () => {
@ -87,4 +111,21 @@ describe("<BottomBar />", () => {
expect(await getByTestId(testId)).toHaveTextContent(text);
});
it("show default hotbar name", () => {
const { getByTestId } = render(<BottomBar />);
expect(getByTestId("current-hotbar-name")).toHaveTextContent("default");
});
it("show active hotbar name", () => {
const { getByTestId } = render(<BottomBar />);
HotbarStore.getInstance().add({
id: "new",
name: "new",
}, { setActive: true });
expect(getByTestId("current-hotbar-name")).toHaveTextContent("new");
});
});