import { render, screen, fireEvent } from "@testing-library/vue"; import { defineComponent, ref } from "vue"; import { describe, it, expect, vi } from "vitest"; import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue"; import CopilotChatConfigurationProvider from "../../../providers/CopilotChatConfigurationProvider.vue"; import CopilotChatView from "../CopilotChatView.vue"; import CopilotChatInput from "../CopilotChatInput.vue"; import CopilotChatMessageView from "../CopilotChatMessageView.vue"; import CopilotChatAssistantMessage from "../CopilotChatAssistantMessage.vue"; import CopilotChatUserMessage from "../CopilotChatUserMessage.vue"; import CopilotChatSuggestionView from "../CopilotChatSuggestionView.vue"; const createMessages = () => [ { id: "1", role: "user" as const, content: "Hello" }, { id: "2", role: "assistant" as const, content: "Hi there! How can I help?" }, { id: "3", role: "user" as const, content: "Tell me a joke" }, { id: "4", role: "assistant" as const, content: "Why did the chicken cross the road?", }, ]; const createSuggestions = () => [ { title: "Tell me more", message: "Tell me more about that", isLoading: false, }, { title: "Another topic", message: "Let's talk about something else", isLoading: false, }, ]; function renderInWrapper(component: ReturnType) { const Host = defineComponent({ components: { CopilotKitProvider, CopilotChatConfigurationProvider, UnderTest: component, }, template: `
`, }); return render(Host); } describe("CopilotChatView onClick Handlers - Drill-Down E2E Tests", () => { describe("Level 1: CopilotChatView Direct Slots", () => { describe("scrollToBottomButton onClick (nested under scrollView)", () => { it("should handle onClick on scrollToBottomButton via scrollView props", async () => { const onClick = vi.fn(); const Host = defineComponent({ components: { CopilotChatView }, setup() { return { messages: createMessages(), onClick }; }, template: ` `, }); renderInWrapper(Host); const scrollBtn = screen.queryByTestId("scroll-to-bottom-button"); if (scrollBtn) { await fireEvent.click(scrollBtn); expect(onClick).toHaveBeenCalled(); } }); }); describe("input onClick", () => { it("should handle onClick on input via props object", async () => { const onClick = vi.fn(); const Host = defineComponent({ components: { CopilotChatView, CopilotChatInput }, setup() { return { messages: createMessages(), onClick }; }, template: ` `, }); renderInWrapper(Host); await fireEvent.click(screen.getByTestId("input-slot")); expect(onClick).toHaveBeenCalled(); }); }); describe("suggestionView onClick", () => { it("should handle onSelectSuggestion when suggestion is clicked", async () => { const onSelectSuggestion = vi.fn(); const Host = defineComponent({ components: { CopilotChatView }, setup() { return { messages: createMessages(), suggestions: createSuggestions(), onSelectSuggestion, }; }, template: ` `, }); renderInWrapper(Host); const suggestion = screen.queryByText("Tell me more"); if (suggestion) { await fireEvent.click(suggestion); expect(onSelectSuggestion).toHaveBeenCalled(); } }); }); }); describe("Level 2: CopilotChatInput Drill-Down", () => { describe("input -> sendButton onClick", () => { it("should handle onClick on sendButton via input props drill-down", async () => { const onClick = vi.fn(); const Host = defineComponent({ components: { CopilotChatView, CopilotChatInput }, setup() { return { messages: createMessages(), onClick }; }, template: ` `, }); renderInWrapper(Host); await fireEvent.click(screen.getByTestId("send-button")); expect(onClick).toHaveBeenCalled(); }); }); describe("input -> startTranscribeButton onClick", () => { it("should handle onClick on startTranscribeButton via input props drill-down", async () => { const onClick = vi.fn(); const onStartTranscribe = vi.fn(); const Host = defineComponent({ components: { CopilotChatView, CopilotChatInput }, setup() { return { messages: createMessages(), onClick, onStartTranscribe }; }, template: ` `, }); renderInWrapper(Host); await fireEvent.click(screen.getByTestId("start-transcribe-button")); expect(onClick).toHaveBeenCalled(); }); }); describe("input -> addMenuButton onClick", () => { it("should handle onClick on addMenuButton via input props drill-down", async () => { const onClick = vi.fn(); const toolsMenu = [{ label: "Action", action: vi.fn() }]; const Host = defineComponent({ components: { CopilotChatView, CopilotChatInput }, setup() { return { messages: createMessages(), onClick, toolsMenu }; }, template: ` `, }); renderInWrapper(Host); await fireEvent.click(screen.getByTestId("add-menu-button")); expect(onClick).toHaveBeenCalled(); }); }); describe("input -> textArea onFocus/onBlur", () => { it("should handle onFocus on textArea via input props drill-down", async () => { const onFocus = vi.fn(); const Host = defineComponent({ components: { CopilotChatView, CopilotChatInput }, setup() { return { messages: createMessages(), onFocus }; }, template: `