test(ai-toolbar): isolate split suites and action coverage
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { describe, expect, mock, test } from "bun:test";
|
||||
import {
|
||||
getButtonOpeningTag,
|
||||
registerAIToolbarTestHooks,
|
||||
renderToolbarActionBoundary,
|
||||
registerAIToolbarMarkupHooks,
|
||||
renderToolbarMarkup,
|
||||
} from "./helpers/ai-toolbar-test-helpers";
|
||||
|
||||
registerAIToolbarTestHooks();
|
||||
registerAIToolbarMarkupHooks();
|
||||
|
||||
describe("AI toolbar state rendering", () => {
|
||||
test("unauthenticated users see the sign-in-required callout", async () => {
|
||||
@@ -54,6 +55,14 @@ describe("AI toolbar state rendering", () => {
|
||||
expect(markup).toContain("Dismiss AI summary");
|
||||
});
|
||||
|
||||
test("pending state renders loading skeletons instead of the live composer", async () => {
|
||||
const markup = await renderToolbarMarkup({ isPending: true });
|
||||
|
||||
expect(markup).toContain("h-[160px]");
|
||||
expect(markup).toContain("h-12");
|
||||
expect(markup).not.toContain("Type or paste event details...");
|
||||
});
|
||||
|
||||
test("Summarize only appears when there are events to summarize", async () => {
|
||||
const emptyMarkup = await renderToolbarMarkup({ events: [] });
|
||||
const populatedMarkup = await renderToolbarMarkup({
|
||||
@@ -98,4 +107,62 @@ describe("AI toolbar state rendering", () => {
|
||||
expect(markup).not.toContain("Type or paste event details...");
|
||||
expect(markup).not.toContain("Generate event");
|
||||
});
|
||||
|
||||
test("example prompt buttons call onAiTemplateSelect with the selected prompt", async () => {
|
||||
const onAiTemplateSelectMock = mock();
|
||||
const actions = await renderToolbarActionBoundary({
|
||||
onAiTemplateSelect: onAiTemplateSelectMock,
|
||||
});
|
||||
const promptButton = actions.getButtonByLabel("Lunch with Maya next Thursday");
|
||||
|
||||
promptButton.onClick?.({} as never);
|
||||
|
||||
expect(onAiTemplateSelectMock).toHaveBeenCalledTimes(1);
|
||||
expect(onAiTemplateSelectMock).toHaveBeenCalledWith(
|
||||
"Lunch with Maya next Thursday at 12:30pm at Toma, remind me 30 minutes before.",
|
||||
);
|
||||
});
|
||||
|
||||
test("Summarize button calls onAiSummarize when events are present", async () => {
|
||||
const onAiSummarizeMock = mock();
|
||||
const actions = await renderToolbarActionBoundary({
|
||||
events: [{ id: "event-1" }],
|
||||
onAiSummarize: onAiSummarizeMock,
|
||||
});
|
||||
|
||||
actions
|
||||
.getButtonByLabel("Summarize")
|
||||
.onClick?.({} as never);
|
||||
|
||||
expect(onAiSummarizeMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("summary dismiss button calls onSummaryDismiss", async () => {
|
||||
const onSummaryDismissMock = mock();
|
||||
const actions = await renderToolbarActionBoundary({
|
||||
summary: "Three events need attention.",
|
||||
onSummaryDismiss: onSummaryDismissMock,
|
||||
});
|
||||
|
||||
actions
|
||||
.getButtonByAriaLabel("Dismiss AI summary")
|
||||
.onClick?.({} as never);
|
||||
|
||||
expect(onSummaryDismissMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("remove image button calls onImageRemove with the preview index", async () => {
|
||||
const onImageRemoveMock = mock();
|
||||
const actions = await renderToolbarActionBoundary({
|
||||
imagePreviews: ["blob:first", "blob:second"],
|
||||
onImageRemove: onImageRemoveMock,
|
||||
});
|
||||
|
||||
actions
|
||||
.getButtonByAriaLabel("Remove image 2")
|
||||
.onClick?.({} as never);
|
||||
|
||||
expect(onImageRemoveMock).toHaveBeenCalledTimes(1);
|
||||
expect(onImageRemoveMock).toHaveBeenCalledWith(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user