Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions src/ui/widgets/GroupBox/groupBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,73 @@ import React from "react";
import { GroupBoxComponent } from "./groupBox";
import { ColorUtils } from "../../../types/color";
import { render } from "@testing-library/react";
import { configureStore } from "@reduxjs/toolkit";
import { Provider } from "react-redux";

const testStore = configureStore({
reducer: {
style: (state = { classes: {}, currentClass: "DEFAULT" }) => state
}
});

describe("<GroupBoxComponent /> snapshots", (): void => {
test("it matches the snapshot for Group Box style", (): void => {
const { asFragment } = render(
<GroupBoxComponent
name={"Test"}
backgroundColor={ColorUtils.WHITE}
styleOpt={0}
/>
<Provider store={testStore}>
<GroupBoxComponent
name={"Test"}
backgroundColor={ColorUtils.WHITE}
styleOpt={0}
/>
</Provider>
);
expect(asFragment()).toMatchSnapshot();
});
test("it matches the snapshot for Title Bar style", (): void => {
const { asFragment } = render(
<GroupBoxComponent name={"Title"} styleOpt={1} />
<Provider store={testStore}>
<GroupBoxComponent name={"Title"} styleOpt={1} />
</Provider>
);
expect(asFragment()).toMatchSnapshot();
});
test("it matches the snapshot for Line style", (): void => {
const { asFragment } = render(
<GroupBoxComponent name={"No Title"} styleOpt={2} />
<Provider store={testStore}>
<GroupBoxComponent name={"No Title"} styleOpt={2} />
</Provider>
);
expect(asFragment()).toMatchSnapshot();
});
test("it matches the snapshot for no style", (): void => {
const { asFragment } = render(
<GroupBoxComponent name={"None"} styleOpt={3} />
<Provider store={testStore}>
<GroupBoxComponent name={"None"} styleOpt={3} />
</Provider>
);
expect(asFragment()).toMatchSnapshot();
});
});

describe("<GroupBoxComponent />", (): void => {
test("it renders the title", (): void => {
const grouping = <GroupBoxComponent name={"Test"} styleOpt={1} />;
const grouping = (
<Provider store={testStore}>
<GroupBoxComponent name={"Test"} styleOpt={1} />
</Provider>
);
const { getByText } = render(grouping);
expect(getByText("Test")).toBeInTheDocument();
});

test("it renders child div with text", (): void => {
const childText = "Testing Child Component";
const groupingWithChild = (
<GroupBoxComponent name={"Test"}>
<div>{childText}</div>
</GroupBoxComponent>
<Provider store={testStore}>
<GroupBoxComponent name={"Test"}>
<div>{childText}</div>
</GroupBoxComponent>
</Provider>
);
const { getByText } = render(groupingWithChild);
expect(getByText("Test")).toBeInTheDocument();
Expand Down
18 changes: 15 additions & 3 deletions src/ui/widgets/GroupBox/groupBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { fontToCss, newFont } from "../../../types/font";
import { ColorUtils } from "../../../types/color";
import Box from "@mui/material/Box";
import { MacroContext, MacroContextType } from "../../../types/macros";
import { selectCurrentClass } from "../../../redux/slices/styleSlice";
import { useSelector } from "react-redux";

const INNER_DIV_STYLE: CSSProperties = {
position: "relative",
Expand Down Expand Up @@ -44,14 +46,24 @@ export const GroupBoxComponent = (
props: InferWidgetProps<typeof GroupBoxProps>
): JSX.Element => {
const {
backgroundColor = ColorUtils.fromRgba(240, 240, 240),
foregroundColor = ColorUtils.fromRgba(0, 0, 0),
lineColor = ColorUtils.fromRgba(0, 0, 0),
font = newFont(14),
styleOpt = 0,
transparent = false,
visible = true
} = props;
const currentClass = useSelector(selectCurrentClass);

let {
backgroundColor = ColorUtils.fromRgba(240, 240, 240),
foregroundColor = ColorUtils.fromRgba(0, 0, 0),
lineColor = ColorUtils.fromRgba(0, 0, 0)
} = props;

if (currentClass === "DARKMODE") {
backgroundColor = ColorUtils.fromRgba(26, 29, 38);
foregroundColor = ColorUtils.fromRgba(233, 233, 233);
lineColor = ColorUtils.fromRgba(233, 233, 233);
}

const outerDivStyle: CSSProperties = {
width: "100%",
Expand Down
Loading