Skip to content

Commit

Permalink
add chart and icons tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed Feb 27, 2024
1 parent ee5a1e3 commit 1a74a4d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"eslint-plugin-storybook": "^0.6.15",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^29.7.0",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jsdom-testing-mocks": "^1.11.0",
"pre-commit": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion src/components/accordion/overrides.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AccordionOverrides } from "baseui/accordion";
import { expandProperty } from "inline-style-expand-shorthand";

export const getAccordionOverrides = (): AccordionOverrides => {
return {
PanelContainer: {
style: () => ({
borderBottom: "none",
...expandProperty("borderBottom", "none"),
marginTop: "4px",
}),
},
Expand Down
48 changes: 48 additions & 0 deletions src/components/chart/Chart.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { render } from "@testing-library/react";
import Chart from "./ChartWrapper";
import { LineSeries } from "./series";
import { MockViewport, mockViewport } from "jsdom-testing-mocks";
import { setupJestCanvasMock } from "jest-canvas-mock";

let viewport: MockViewport;

beforeEach(() => {
viewport = mockViewport({ width: "1320px", height: "568px" });
setupJestCanvasMock();
});

afterEach(() => {
viewport.cleanup();
});

const lineData = [
{ time: "2018-12-22", value: 23 },
{ time: "2018-12-23", value: 54 },
{ time: "2018-12-24", value: 36 },
{ time: "2018-12-25", value: 48 },
{ time: "2018-12-26", value: 24 },
{ time: "2018-12-27", value: 73 },
{ time: "2018-12-28", value: 287 },
{ time: "2018-12-29", value: 96 },
{ time: "2018-12-30", value: 37 },
{ time: "2018-12-31", value: 54 },
{ time: "2019-01-01", value: 62 },
{ time: "2019-01-02", value: 71 },
{ time: "2019-01-03", value: 88 },
{ time: "2019-01-04", value: 99 },
{ time: "2019-01-05", value: 13 },
{ time: "2019-01-06", value: 28 },
{ time: "2019-01-07", value: 92 },
];

describe("Chart", () => {
it("renders without crashing", () => {
render(
<Chart height={400}>
<LineSeries data={lineData} />
</Chart>
);
});

// Add more tests as needed
});
17 changes: 17 additions & 0 deletions src/components/icons/Icons.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isValidElement } from "react";
import * as Icons from ".";
import { render } from "../../test-utils/render";

describe("Icons", () => {
it("all icons render", () => {
const keys = Object.keys(Icons);
keys.forEach((key) => {
const Icon = Icons[key as keyof typeof Icons];

if (isValidElement(<Icon />)) {
const { container } = render(<Icon />);
expect(container.firstChild).toBeInTheDocument();
}
});
});
});
6 changes: 3 additions & 3 deletions src/components/menu/ui/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef } from "react";
import { cloneElement, forwardRef } from "react";
import { MenuItemProps, MenuItemTypographyProps } from "../types";
import { ParagraphSmall, ParagraphMedium, ParagraphLarge } from "baseui/typography";
import { useStyletron, styled } from "baseui";
Expand Down Expand Up @@ -38,7 +38,7 @@ const MenuItem = forwardRef<HTMLLIElement, MenuItemProps>(
<LinkComponent className={css(getLinkComponentStyles())}>
{item?.selected != null && <Checkbox checked={item.selected} />}
{item?.startEnhancer &&
React.cloneElement(item.startEnhancer, {
cloneElement(item.startEnhancer, {
size: 16,
className: css(isAreaSelected ? svgActiveStyles : {}),
})}
Expand All @@ -48,7 +48,7 @@ const MenuItem = forwardRef<HTMLLIElement, MenuItemProps>(
<EndWrapper>
{item?.suffixText && <TypographyComponent color={paragraphColor}>{item.suffixText}</TypographyComponent>}
{item?.endEnhancer &&
React.cloneElement(item.endEnhancer, {
cloneElement(item.endEnhancer, {
size: 16,
className: css(isAreaSelected ? svgActiveStyles : {}),
})}
Expand Down

0 comments on commit 1a74a4d

Please sign in to comment.