import React from "react"; import { render } from "@testing-library/react"; import { CSSProperties } from "react"; import { withHocs } from "../hocs/withHocs"; import { componentDisplayName } from "../utils/componentDisplayName"; import { withStyleObjectStrategy } from "./withStyleObjectStrategy"; function Example(props: { style: CSSProperties }): JSX.Element { return
{JSON.stringify(props)};
}
it("withStyleObjectStrategy name", () => {
const Component = withStyleObjectStrategy({
borderColor: "red",
})(Example);
expect(componentDisplayName.get(Component)).toBe(
"withStyleObjectStrategy(Example)",
);
});
it("withStyleObjectStrategy name with dependency array", () => {
const Component = withStyleObjectStrategy({
borderColor: "red",
})(Example);
expect(componentDisplayName.get(Component)).toBe(
"withStyleObjectStrategy(Example)",
);
});
it("withStyleObjectStrategy with value", () => {
const Component = withStyleObjectStrategy<{ background?: string }>(
({ background }) => ({
background,
}),
["background"],
)(Example);
render({"style":{"background":"blue"}}',
);
});
it("withStyleObjectStrategy a new property in dependencyNames", () => {
const Component = withStyleObjectStrategy<{ background: string }>(
({ background }) => ({ background }),
["background"],
)(Example);
render({"background":"yellow","style":{"background":"yellow"}}',
);
});
it("withStyleObjectStrategy overridden", () => {
const Component = withStyleObjectStrategy({ background: "red" })(Example);
render({"style":{"background":"red","border":"none"}}',
);
});
it("withStyleObjectStrategy rewritten", () => {
const Component = withStyleObjectStrategy<{ style: CSSProperties }>(
(_props) => ({ width: "100%" }),
["style"],
)(Example);
render({"style":{"width":"100%"}}',
);
});
it("withStyleObjectStrategy with style twice", () => {
const Component = withHocs([
withStyleObjectStrategy({
background: "black",
borderColor: "white",
}),
withStyleObjectStrategy({
borderColor: "red",
display: "block",
}),
])(Example);
render({"style":{"borderColor":"white","display":"block","background":"black"}}',
);
});