Skip to content

Commit

Permalink
Added test for BoardGrid component
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-bradley committed Feb 20, 2024
1 parent 534056b commit b33d560
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/app/components/ui/BoardGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { cleanup, render, screen } from "@testing-library/react";
import BoardGrid from "./BoardGrid";

vi.mock("next/navigation", () => {
const useParams = vi
.fn()
.mockReturnValue({ board: "RST-WBSB-WTDTR-TRWS-BWS" });
return { useParams };
});

describe("BoardGrid", () => {
beforeEach(async () => {
render(<BoardGrid />);

return async () => {
cleanup();
vi.clearAllMocks();
};
});
it("should render properly", () => {
const hexgrid: HTMLOrSVGElement = screen.getByTestId("hexgrid-svg");
// @ts-ignore
const g: SVGElement = hexgrid.firstElementChild;
expect(g.childElementCount).toBe(19);
});
});
2 changes: 1 addition & 1 deletion src/app/components/ui/BoardGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { HexGrid, Layout, Hexagon } from "react-hexgrid";
import { getCubeCoords } from "@/lib/utils";
import { getCubeCoords } from "../../../lib/utils";
import React, { useState } from "react";
import { useParams } from "next/navigation";

Expand Down

0 comments on commit b33d560

Please sign in to comment.