import { render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import userEvent from "@testing-library/user-event"; import { SettingsInput } from "#/components/features/settings/settings-input"; describe("SettingsInput", () => { it("should render an optional tag if showOptionalTag is true", async () => { const { rerender } = render( , ); expect(screen.queryByText(/optional/i)).not.toBeInTheDocument(); rerender( , ); expect(screen.getByText(/optional/i)).toBeInTheDocument(); }); it("should disable the input if isDisabled is true", async () => { const { rerender } = render( , ); expect(screen.getByTestId("test-input")).toBeEnabled(); rerender( , ); expect(screen.getByTestId("test-input")).toBeDisabled(); }); it("should set a placeholder on the input", async () => { render( , ); expect(screen.getByTestId("test-input")).toHaveAttribute( "placeholder", "Test Placeholder", ); }); it("should set a default value on the input", async () => { render( , ); expect(screen.getByTestId("test-input")).toHaveValue("Test Value"); }); it("should render start content", async () => { const startContent =
Start Content
; render( , ); expect(screen.getByText("Start Content")).toBeInTheDocument(); }); it("should call onChange with the input value", async () => { const onChangeMock = vi.fn(); const user = userEvent.setup(); render( , ); const input = screen.getByTestId("test-input"); await user.type(input, "Test"); expect(onChangeMock).toHaveBeenCalledTimes(4); expect(onChangeMock).toHaveBeenNthCalledWith(4, "Test"); }); });