Skip to content

Commit 900b156

Browse files
-Remove unnecesary tests and unnecesary async assertions.
-Improve coverage
1 parent 9f2f70d commit 900b156

4 files changed

Lines changed: 97 additions & 294 deletions

File tree

apps/website/test/theme-generator/BrandingDetails.test.tsx

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,25 @@ jest.mock("react-color", () => ({
2222
}));
2323

2424
describe("BrandingDetails", () => {
25+
beforeAll(() => {
26+
global.URL.createObjectURL = jest.fn(() => "blob:mock-url");
27+
});
28+
29+
const colors: Colors = {
30+
primary: "#5F249F" as CssColor,
31+
secondary: "#0067B3" as CssColor,
32+
tertiary: "#F7CF2B" as CssColor,
33+
neutral: "#999999" as CssColor,
34+
info: "#0067B3" as CssColor,
35+
success: "#59D97D" as CssColor,
36+
error: "#FE344F" as CssColor,
37+
warning: "#F59F3D" as CssColor,
38+
};
39+
2540
it("renders color sections with ColorCard components", () => {
2641
const onColorsChange = jest.fn();
2742
const onLogosChange = jest.fn();
2843

29-
const colors: Colors = {
30-
primary: "#5F249F" as CssColor,
31-
secondary: "#0067B3" as CssColor,
32-
tertiary: "#F7CF2B" as CssColor,
33-
neutral: "#999999" as CssColor,
34-
info: "#0067B3" as CssColor,
35-
success: "#59D97D" as CssColor,
36-
error: "#FE344F" as CssColor,
37-
warning: "#F59F3D" as CssColor,
38-
};
39-
4044
const logos: Logos = { mainLogo: [], footerLogo: [], footerReducedLogo: [], favicon: [] };
4145

4246
render(
@@ -47,21 +51,10 @@ describe("BrandingDetails", () => {
4751
expect(screen.getByText("Primary")).toBeInTheDocument();
4852
});
4953

50-
it("updates colors when input value changes", async () => {
54+
it("updates colors when input value changes", () => {
5155
const onColorsChange = jest.fn();
5256
const onLogosChange = jest.fn();
5357

54-
const colors: Colors = {
55-
primary: "#5F249F" as CssColor,
56-
secondary: "#0067B3" as CssColor,
57-
tertiary: "#F7CF2B" as CssColor,
58-
neutral: "#999999" as CssColor,
59-
info: "#0067B3" as CssColor,
60-
success: "#59D97D" as CssColor,
61-
error: "#FE344F" as CssColor,
62-
warning: "#F59F3D" as CssColor,
63-
};
64-
6558
const logos: Logos = { mainLogo: [], footerLogo: [], footerReducedLogo: [], favicon: [] };
6659

6760
render(
@@ -72,31 +65,17 @@ describe("BrandingDetails", () => {
7265
fireEvent.change(primaryInput, { target: { value: "#111111" } });
7366
fireEvent.blur(primaryInput);
7467

75-
await waitFor(() => {
76-
expect(onColorsChange).toHaveBeenCalledWith(
77-
expect.objectContaining({
78-
primary: "#111111",
79-
secondary: "#0067B3",
80-
})
81-
);
82-
});
68+
expect(onColorsChange).toHaveBeenCalledWith(
69+
expect.objectContaining({
70+
primary: "#111111",
71+
})
72+
);
8373
});
8474

8575
it("renders logo sections with FileInput components", () => {
8676
const onColorsChange = jest.fn();
8777
const onLogosChange = jest.fn();
8878

89-
const colors: Colors = {
90-
primary: "#5F249F" as CssColor,
91-
secondary: "#0067B3" as CssColor,
92-
tertiary: "#F7CF2B" as CssColor,
93-
neutral: "#999999" as CssColor,
94-
info: "#0067B3" as CssColor,
95-
success: "#59D97D" as CssColor,
96-
error: "#FE344F" as CssColor,
97-
warning: "#F59F3D" as CssColor,
98-
};
99-
10079
const logos: Logos = {
10180
mainLogo: [],
10281
footerLogo: [{ file: new File(["f"], "footer.png", { type: "image/png" }) }],
@@ -111,4 +90,28 @@ describe("BrandingDetails", () => {
11190
expect(screen.getByText("Main logo")).toBeInTheDocument();
11291
expect(screen.getByText("Default footer logo")).toBeInTheDocument();
11392
});
93+
94+
it("updates logos when a file is selected", async () => {
95+
const onColorsChange = jest.fn();
96+
const onLogosChange = jest.fn();
97+
98+
const logos: Logos = { mainLogo: [], footerLogo: [], footerReducedLogo: [], favicon: [] };
99+
100+
render(
101+
<BrandingDetails colors={colors} onColorsChange={onColorsChange} logos={logos} onLogosChange={onLogosChange} />
102+
);
103+
104+
const file = new File(["logo content"], "main-logo.png", { type: "image/png" });
105+
const mainLogoInput = screen.getByLabelText("Main logo");
106+
fireEvent.change(mainLogoInput, { target: { files: [file] } });
107+
108+
await waitFor(() => {
109+
expect(onLogosChange).toHaveBeenCalled();
110+
const firstCallArguments = onLogosChange.mock.calls[0] as [Logos];
111+
const updatedLogos = firstCallArguments[0];
112+
expect(updatedLogos.mainLogo).toHaveLength(1);
113+
expect(updatedLogos.mainLogo[0]?.file).toBeInstanceOf(File);
114+
expect(updatedLogos.mainLogo[0]?.file.name).toBe("main-logo.png");
115+
});
116+
});
114117
});

0 commit comments

Comments
 (0)