forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopilot-chat-user-message.component.spec.ts
More file actions
66 lines (57 loc) · 1.95 KB
/
Copy pathcopilot-chat-user-message.component.spec.ts
File metadata and controls
66 lines (57 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {
EnvironmentInjector,
runInInjectionContext,
computed,
} from "@angular/core";
import { TestBed } from "@angular/core/testing";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { CopilotChatUserMessage } from "../copilot-chat-user-message";
import type { UserMessage } from "../copilot-chat-user-message.types";
const sampleMessage: UserMessage = {
id: "msg-1",
role: "user",
content: "Hello from user",
};
describe("CopilotChatUserMessage", () => {
let injector: EnvironmentInjector;
let component: CopilotChatUserMessage;
beforeEach(() => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({});
injector = TestBed.inject(EnvironmentInjector);
component = runInInjectionContext(
injector,
() => new CopilotChatUserMessage(),
);
(component as any).message = () => sampleMessage;
});
it("emits edit events when handleEdit is invoked", () => {
const editSpy = vi.fn();
component.editMessage.subscribe(editSpy);
component.handleEdit();
expect(editSpy).toHaveBeenCalledWith({ message: sampleMessage });
});
it("indicates when branch navigation should be shown", () => {
(component as any).numberOfBranches = () => 3;
component.showBranchNavigation = computed(
() => ((component as any).numberOfBranches() ?? 1) > 1,
);
expect(component.showBranchNavigation()).toBe(true);
(component as any).numberOfBranches = () => 1;
component.showBranchNavigation = computed(
() => ((component as any).numberOfBranches() ?? 1) > 1,
);
expect(component.showBranchNavigation()).toBe(false);
});
it("forwards branch navigation events", () => {
const switchSpy = vi.fn();
component.switchToBranch.subscribe(switchSpy);
const payload = {
branchIndex: 2,
numberOfBranches: 3,
message: sampleMessage,
};
component.handleSwitchToBranch(payload);
expect(switchSpy).toHaveBeenCalledWith(payload);
});
});