Skip to content

Commit 8d73183

Browse files
test(color-picker-web): refactor snapshots and tests for improved structure
1 parent 53b0e08 commit 8d73183

File tree

4 files changed

+71
-72
lines changed

4 files changed

+71
-72
lines changed

packages/pluggableWidgets/color-picker-web/src/components/__tests__/ColorPicker.spec.tsx

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "@testing-library/jest-dom";
2-
import { act, render, RenderResult } from "@testing-library/react";
2+
import { render, RenderResult } from "@testing-library/react";
33
import userEvent, { UserEvent } from "@testing-library/user-event";
44
import { createElement } from "react";
55
import { ColorPicker, ColorPickerProps } from "../ColorPicker";
@@ -28,33 +28,6 @@ describe("ColorPicker", () => {
2828
return render(<ColorPicker {...colorPickerProps} {...configs} />);
2929
}
3030

31-
it("renders the structure correctly", () => {
32-
const colorPickerComponent = renderColorPicker();
33-
34-
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
35-
});
36-
37-
it("that is disabled renders with the structure", () => {
38-
const colorPickerComponent = renderColorPicker({ disabled: true });
39-
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
40-
});
41-
42-
it("renders picker with pre-defined default colors", () => {
43-
const colorPickerComponent = renderColorPicker();
44-
45-
act(() => {
46-
colorPickerComponent.rerender(
47-
<ColorPicker
48-
{...colorPickerProps}
49-
mode="inline"
50-
defaultColors={[{ color: "#2CCCE4" }, { color: "#555555" }]}
51-
/>
52-
);
53-
});
54-
55-
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
56-
});
57-
5831
it("should handle on change event", async () => {
5932
const { getByTitle } = renderColorPicker({
6033
type: "block",

packages/pluggableWidgets/color-picker-web/src/components/__tests__/ColorPickerSnapshots.spec.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "@testing-library/jest-dom";
2-
import { render, RenderResult } from "@testing-library/react";
2+
import { act, render, RenderResult } from "@testing-library/react";
33
import { createElement } from "react";
44
import { ColorPicker, ColorPickerProps } from "../ColorPicker";
55

@@ -29,6 +29,33 @@ describe("ColorPicker", () => {
2929
return render(<ColorPicker {...colorPickerProps} {...configs} />);
3030
}
3131

32+
it("renders the structure correctly", () => {
33+
const colorPickerComponent = renderColorPicker();
34+
35+
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
36+
});
37+
38+
it("that is disabled renders with the structure", () => {
39+
const colorPickerComponent = renderColorPicker({ disabled: true });
40+
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
41+
});
42+
43+
it("renders picker with pre-defined default colors", () => {
44+
const colorPickerComponent = renderColorPicker();
45+
46+
act(() => {
47+
colorPickerComponent.rerender(
48+
<ColorPicker
49+
{...colorPickerProps}
50+
mode="inline"
51+
defaultColors={[{ color: "#2CCCE4" }, { color: "#555555" }]}
52+
/>
53+
);
54+
});
55+
56+
expect(colorPickerComponent.asFragment()).toMatchSnapshot();
57+
});
58+
3259
describe("with a mode as", () => {
3360
it("popover or input renders with the structure", () => {
3461
const colorPickerComponent = renderColorPicker({ mode: "popover" });

packages/pluggableWidgets/color-picker-web/src/components/__tests__/__snapshots__/ColorPicker.spec.tsx.snap

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/pluggableWidgets/color-picker-web/src/components/__tests__/__snapshots__/ColorPickerSnapshots.spec.tsx.snap

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`ColorPicker renders picker with pre-defined default colors 1`] = `
4+
<DocumentFragment>
5+
<div
6+
class="widget-color-picker widget-color-picker-picker"
7+
/>
8+
</DocumentFragment>
9+
`;
10+
11+
exports[`ColorPicker renders the structure correctly 1`] = `
12+
<DocumentFragment>
13+
<div
14+
class="widget-color-picker widget-color-picker-picker"
15+
>
16+
<button
17+
class="btn"
18+
>
19+
<div
20+
class="widget-color-picker-inner"
21+
style="background: rgb(0, 0, 0);"
22+
/>
23+
</button>
24+
</div>
25+
</DocumentFragment>
26+
`;
27+
28+
exports[`ColorPicker that is disabled renders with the structure 1`] = `
29+
<DocumentFragment>
30+
<div
31+
class="widget-color-picker widget-color-picker-picker widget-color-picker-disabled"
32+
>
33+
<button
34+
class="btn disabled"
35+
>
36+
<div
37+
class="widget-color-picker-inner"
38+
style="background: rgb(0, 0, 0);"
39+
/>
40+
</button>
41+
</div>
42+
</DocumentFragment>
43+
`;
44+
345
exports[`ColorPicker with a mode as inline renders with the structure 1`] = `
446
<DocumentFragment>
547
<div

0 commit comments

Comments
 (0)