* early UI refresher of workflows using v3 designs. needs tons of testing, might have broken * Delete .claude/settings.local.json * fix: bunch of design fixes, merge conflict fixes * fix: e2e and type-check * fix: await button click * review fixes * code rabbit fixes * fix styles in variables dropdown * fix text truncate * fix: unit tests * fix: unit tests * chore: add missing i18n * review fixes * review fixes * fix testing info message * move timeSectionText up * fix which team does this apply to info message * disable set up agent button with read only * fix: cal.ai breaking on mobile screen --------- Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: Udit Takkar <udit222001@gmail.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com>
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
import { vi, describe, it, expect } from "vitest";
|
|
|
|
import { AddVariablesDropdown } from "./AddVariablesDropdown";
|
|
|
|
vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
|
useLocale: () => ({
|
|
t: (key: string) => key,
|
|
}),
|
|
}));
|
|
|
|
// Mock the Dropdown component
|
|
vi.mock("../../dropdown", () => ({
|
|
Dropdown: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuTrigger: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
DropdownMenuItem: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
}));
|
|
|
|
vi.mock("@calcom/lib/hooks/useMediaQuery", () => ({
|
|
default: (_query: string) => false,
|
|
}));
|
|
|
|
describe("AddVariablesDropdown", () => {
|
|
const mockAddVariable = vi.fn();
|
|
const variables = ["var1", "var2", "var3"];
|
|
|
|
it("renders correctly", () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} />);
|
|
expect(screen.getByText("add_variable")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders text editor version correctly", () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} isTextEditor />);
|
|
expect(screen.getByText("add_variable")).toBeInTheDocument();
|
|
expect(screen.getByText("+")).toBeInTheDocument();
|
|
});
|
|
|
|
it("opens dropdown on click", async () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} />);
|
|
fireEvent.click(screen.getByText("add_variable"));
|
|
await waitFor(() => {
|
|
expect(screen.getByText("add_dynamic_variables")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it("renders all variables", async () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} />);
|
|
fireEvent.click(screen.getByText("add_variable"));
|
|
await waitFor(() => {
|
|
for (const variable of variables) {
|
|
expect(
|
|
screen.getByText((content) => content.includes(`{${variable}_variable}`.toUpperCase()))
|
|
).toBeInTheDocument();
|
|
}
|
|
});
|
|
});
|
|
|
|
it("calls addVariable when a variable is clicked", async () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} />);
|
|
fireEvent.click(screen.getByText("add_variable"));
|
|
await waitFor(() => {
|
|
fireEvent.click(screen.getByText((content) => content.includes("{VAR1_VARIABLE}")));
|
|
});
|
|
expect(mockAddVariable).toHaveBeenCalledWith("var1_variable");
|
|
});
|
|
|
|
it("renders variable info for each variable", async () => {
|
|
render(<AddVariablesDropdown addVariable={mockAddVariable} variables={variables} />);
|
|
fireEvent.click(screen.getByText("add_variable"));
|
|
await waitFor(() => {
|
|
for (const variable of variables) {
|
|
expect(screen.getByText(`${variable}_info`)).toBeInTheDocument();
|
|
}
|
|
});
|
|
});
|
|
});
|