Adding tests

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

No files matched your search

@@ -26,7 +26,7 @@ import { HotbarStore } from "../../../common/hotbar-store";
export const ActiveHotbarName = observer(() => { export const ActiveHotbarName = observer(() => {
return ( return (
<div className="flex items-center"> <div className="flex items-center" data-testid="current-hotbar-name">
<Icon material="bookmarks" smallest className="mr-2"/>{" "} <Icon material="bookmarks" smallest className="mr-2"/>{" "}
{HotbarStore.getInstance().getActive()?.name} {HotbarStore.getInstance().getActive()?.name}
</div> </div>
@@ -20,25 +20,49 @@
*/ */
import React from "react"; import React from "react";
import mockFs from "mock-fs";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect"; 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", () => ({ jest.mock("electron", () => ({
app: { 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 />", () => { describe("<BottomBar />", () => {
beforeEach(() => { beforeEach(() => {
const mockOpts = {
"tmp": {
"test-store.json": JSON.stringify({}),
},
};
mockFs(mockOpts);
StatusBarRegistry.createInstance(); StatusBarRegistry.createInstance();
HotbarStore.createInstance();
}); });
afterEach(() => { afterEach(() => {
StatusBarRegistry.resetInstance(); StatusBarRegistry.resetInstance();
HotbarStore.resetInstance();
mockFs.restore();
}); });
it("renders w/o errors", () => { it("renders w/o errors", () => {
@@ -87,4 +111,21 @@ describe("<BottomBar />", () => {
expect(await getByTestId(testId)).toHaveTextContent(text); 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");
});
}); });