Skip to content

Commit 84ca9a3

Browse files
committed
fix: add unit test
1 parent b19d258 commit 84ca9a3

2 files changed

Lines changed: 70 additions & 34 deletions

File tree

packages/pluggableWidgets/signature-web/src/__tests__/AppEvents.spec.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import "@testing-library/jest-dom";
2+
import { render, screen } from "@testing-library/react";
3+
import { ReactElement } from "react";
4+
import { SignatureContainerProps } from "../../typings/SignatureProps";
5+
import Signature from "../Signature";
6+
7+
const mockSignatureComponent = jest.fn((_props: unknown) => <div data-testid="signature-component" />);
8+
9+
jest.mock("../components/Signature", () => ({
10+
SignatureComponent: (props: unknown): ReactElement => mockSignatureComponent(props)
11+
}));
12+
13+
describe("Signature", () => {
14+
const imageSource = {
15+
setValue: jest.fn()
16+
} as unknown as SignatureContainerProps["imageSource"];
17+
18+
const defaultProps: SignatureContainerProps = {
19+
name: "signature",
20+
class: "mx-signature",
21+
tabIndex: 0,
22+
imageSource,
23+
hasSignatureAttribute: undefined,
24+
penType: "ballpoint",
25+
penColor: "#000000",
26+
widthUnit: "pixels",
27+
width: 300,
28+
heightUnit: "pixels",
29+
height: 200,
30+
minHeightUnit: "none",
31+
minHeight: 0,
32+
maxHeightUnit: "none",
33+
maxHeight: 0,
34+
OverflowY: "auto",
35+
showGrid: true,
36+
gridBorderColor: "#cccccc",
37+
gridCellHeight: 20,
38+
gridCellWidth: 20,
39+
gridBorderWidth: 1
40+
};
41+
42+
beforeEach(() => {
43+
mockSignatureComponent.mockClear();
44+
});
45+
46+
it("renders SignatureComponent", () => {
47+
render(<Signature {...defaultProps} />);
48+
49+
expect(screen.getByTestId("signature-component")).toBeInTheDocument();
50+
});
51+
52+
it("passes derived and default props to SignatureComponent", () => {
53+
render(<Signature {...defaultProps} />);
54+
55+
expect(mockSignatureComponent).toHaveBeenCalledTimes(1);
56+
expect(mockSignatureComponent).toHaveBeenCalledWith(
57+
expect.objectContaining({
58+
className: defaultProps.class,
59+
readOnly: false,
60+
clearSignature: false,
61+
imageSource
62+
})
63+
);
64+
65+
const passedProps = mockSignatureComponent.mock.calls[0][0] as {
66+
onSignEndAction?: () => void;
67+
};
68+
expect(typeof passedProps.onSignEndAction).toBe("function");
69+
});
70+
});

0 commit comments

Comments
 (0)