test: Create unit tests for react components in packages/ui/components/TokenHandle (#10407)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-07-27 15:48:23 +02:00
1 parent a1e6e8ff32
commit e81985c80d
2 files changed
+41 -1

No files matched your search

@@ -0,0 +1,30 @@
/* eslint-disable playwright/missing-playwright-await */
import { render, screen, fireEvent } from "@testing-library/react";
import { vi } from "vitest";
import TokenHandler from "./TokenHandler";
describe("Tests for TokenHandler component", () => {
test("Should render the correct number of input elements", () => {
const digits = [
{ value: 1, onChange: vi.fn() },
{ value: 2, onChange: vi.fn() },
{ value: 3, onChange: vi.fn() },
];
render(<TokenHandler digits={digits} digitClassName="digit" />);
expect(screen.getAllByRole("textbox")).toHaveLength(digits.length);
});
test("Should handle digit input correctly", () => {
const onChangeMock = vi.fn();
const digits = [{ value: 1, onChange: onChangeMock }];
render(<TokenHandler digits={digits} digitClassName="digit" />);
const inputElement = screen.getByRole("textbox");
fireEvent.change(inputElement, { target: { value: "5" } });
expect(onChangeMock).toHaveBeenCalledTimes(1);
});
});