Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ContextLimitBanner.test.tsx

43 lines1.5 KB

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it, vi } from "vite-plus/test";
3​
4import { buildContextLimitBannerItem } from "./ContextLimitBanner";
5​
6describe("buildContextLimitBannerItem", () => {
7 it("keeps token-limit settings with the limit and reserves actions for handover", () => {
8 const item = buildContextLimitBannerItem({
9 threadId: "thread-1",
10 tokenLimit: 250_000,
11 canChangeTokenLimit: true,
12 supportsGeneration: true,
13 isGeneratingHandover: false,
14 hasSavedHandover: false,
15 onChangeTokenLimit: vi.fn(),
16 onGenerateHandover: vi.fn(),
17 });
18​
19 const title = renderToStaticMarkup(<>{item.title}</>);
20 const actions = renderToStaticMarkup(<>{item.actions}</>);
21​
22 expect(title).toContain("This thread has reached 250,000 tokens");
23 expect(title).toContain("Change thread token limit");
24 expect(actions).toContain("Handover to new thread");
25 expect(actions).not.toContain("Change thread token limit");
26 });
27​
28 it("does not strand a settings control in the action area on an older server", () => {
29 const item = buildContextLimitBannerItem({
30 threadId: "thread-1",
31 tokenLimit: 250_000,
32 canChangeTokenLimit: true,
33 supportsGeneration: false,
34 isGeneratingHandover: false,
35 hasSavedHandover: false,
36 onChangeTokenLimit: vi.fn(),
37 onGenerateHandover: vi.fn(),
38 });
39​
40 expect(renderToStaticMarkup(<>{item.title}</>)).toContain("Change thread token limit");
41 expect(item.actions).toBeUndefined();
42 });
43});