@antelopejs/dms-assistant 0.2.7-next.444.g0da96b6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -2
- package/frontend-vue/builder/tests/database-build.test.ts +0 -232
- package/frontend-vue/builder/tests/database-connect.test.ts +0 -348
- package/frontend-vue/builder/tests/database-display.test.ts +0 -112
- package/frontend-vue/builder/tests/database.test.ts +0 -138
- package/frontend-vue/builder/tests/enabled.test.ts +0 -17
- package/frontend-vue/builder/tests/owner-ui.test.ts +0 -29
- package/frontend-vue/builder/tests/stubs/frontend-module.ts +0 -63
- package/frontend-vue/builder/vitest.config.ts +0 -21
- package/frontend-vue/tests/assistant-actions.test.ts +0 -109
- package/frontend-vue/tests/assistant-activity.test.ts +0 -281
- package/frontend-vue/tests/backend-boundary.test.ts +0 -130
- package/frontend-vue/tests/backoff.test.ts +0 -40
- package/frontend-vue/tests/block-health.test.ts +0 -142
- package/frontend-vue/tests/channel-client.test.ts +0 -246
- package/frontend-vue/tests/chat/block-preview.test.ts +0 -367
- package/frontend-vue/tests/chat/block-target.test.ts +0 -133
- package/frontend-vue/tests/chat/build-view.test.ts +0 -171
- package/frontend-vue/tests/chat/chat-scroll.test.ts +0 -251
- package/frontend-vue/tests/chat/conversation-events.test.ts +0 -622
- package/frontend-vue/tests/chat/diff-and-keys.test.ts +0 -178
- package/frontend-vue/tests/chat/held-card.test.ts +0 -133
- package/frontend-vue/tests/chat/markdown-content.test.ts +0 -86
- package/frontend-vue/tests/chat/markdown.test.ts +0 -352
- package/frontend-vue/tests/chat/provider-notice.test.ts +0 -33
- package/frontend-vue/tests/chat/tool-lexicon.test.ts +0 -212
- package/frontend-vue/tests/chat/useChatChannel.test.ts +0 -124
- package/frontend-vue/tests/chat/useConversation.test.ts +0 -288
- package/frontend-vue/tests/chat-panel.test.ts +0 -300
- package/frontend-vue/tests/chat-transport.test.ts +0 -94
- package/frontend-vue/tests/embedding.test.ts +0 -10
- package/frontend-vue/tests/formal/connection-analysis-scenarios.ts +0 -130
- package/frontend-vue/tests/formal/connection-analysis-world.ts +0 -497
- package/frontend-vue/tests/formal/connection-analysis.test.ts +0 -36
- package/frontend-vue/tests/host-commands.test.ts +0 -182
- package/frontend-vue/tests/launcher-icon.test.ts +0 -62
- package/frontend-vue/tests/launcher-label.test.ts +0 -40
- package/frontend-vue/tests/launcher-state.test.ts +0 -215
- package/frontend-vue/tests/mockup-fold.test.ts +0 -95
- package/frontend-vue/tests/navigation.test.ts +0 -142
- package/frontend-vue/tests/onboarding-api.test.ts +0 -29
- package/frontend-vue/tests/onboarding-claude.test.ts +0 -144
- package/frontend-vue/tests/onboarding-connect-memory.test.ts +0 -126
- package/frontend-vue/tests/onboarding-controller-restart.test.ts +0 -134
- package/frontend-vue/tests/onboarding-controller.test.ts +0 -307
- package/frontend-vue/tests/onboarding-database-driver-install.test.ts +0 -112
- package/frontend-vue/tests/onboarding-database-engines.test.ts +0 -142
- package/frontend-vue/tests/onboarding-database-new-url.test.ts +0 -174
- package/frontend-vue/tests/onboarding-database-reload.test.ts +0 -229
- package/frontend-vue/tests/onboarding-database-tabs.test.ts +0 -184
- package/frontend-vue/tests/onboarding-database.test.ts +0 -540
- package/frontend-vue/tests/onboarding-deep-link.test.ts +0 -51
- package/frontend-vue/tests/onboarding-flow.test.ts +0 -204
- package/frontend-vue/tests/onboarding-install.test.ts +0 -62
- package/frontend-vue/tests/onboarding-mockups.test.ts +0 -86
- package/frontend-vue/tests/onboarding-scratch.test.ts +0 -70
- package/frontend-vue/tests/onboarding-widget.test.ts +0 -97
- package/frontend-vue/tests/palette-assistant.test.ts +0 -241
- package/frontend-vue/tests/panel-approvals.test.ts +0 -226
- package/frontend-vue/tests/panel-closed-conversation.test.ts +0 -53
- package/frontend-vue/tests/panel-mockup-prompt.test.ts +0 -238
- package/frontend-vue/tests/panel-modes.test.ts +0 -131
- package/frontend-vue/tests/panel-questions.test.ts +0 -151
- package/frontend-vue/tests/panel-states.test.ts +0 -252
- package/frontend-vue/tests/panel-tools.test.ts +0 -219
- package/frontend-vue/tests/session-gate.test.ts +0 -66
- package/frontend-vue/tests/sidecar-guest.test.ts +0 -81
- package/frontend-vue/tests/sidecar-status.test.ts +0 -117
- package/frontend-vue/tests/support/api-error-presenter.ts +0 -30
- package/frontend-vue/tests/support/database-connect.ts +0 -129
- package/frontend-vue/tests/support/dms-frontend-module.ts +0 -9
- package/frontend-vue/tests/support/dms-state.ts +0 -12
- package/frontend-vue/tests/support/fake-layout.ts +0 -119
- package/frontend-vue/tests/support/i18n.ts +0 -49
- package/frontend-vue/tests/support/onboarding-host.ts +0 -104
- package/frontend-vue/tests/support/onboarding.ts +0 -176
- package/frontend-vue/tests/support/panel-fixtures.ts +0 -155
- package/frontend-vue/tests/support/panel-harness.ts +0 -211
- package/frontend-vue/tests/support/setup-layout.ts +0 -3
- package/frontend-vue/tests/support/stand-ins/DmsBlockPreview.ts +0 -18
- package/frontend-vue/tests/support/stand-ins/DmsEmptyState.ts +0 -17
- package/frontend-vue/tests/support/stand-ins/DmsSegmentedControl.ts +0 -35
- package/frontend-vue/tests/support/stand-ins/DmsStatusPill.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/OnboardingModal.ts +0 -13
- package/frontend-vue/tests/support/stand-ins/UBadge.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UButton.ts +0 -27
- package/frontend-vue/tests/support/stand-ins/UCheckbox.ts +0 -25
- package/frontend-vue/tests/support/stand-ins/UDropdownMenu.ts +0 -34
- package/frontend-vue/tests/support/stand-ins/UFormField.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UInput.ts +0 -16
- package/frontend-vue/tests/support/stand-ins/UKbd.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UModal.ts +0 -20
- package/frontend-vue/tests/support/stand-ins/UPopover.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UTabs.ts +0 -31
- package/frontend-vue/tests/support/stand-ins/UTextarea.ts +0 -19
- package/frontend-vue/tests/support/stubs.ts +0 -28
- package/frontend-vue/tests/views/api-data-reads.test.ts +0 -451
- package/frontend-vue/tests/views/api-error-presentation.test.ts +0 -89
- package/frontend-vue/tests/views/diff-view.test.ts +0 -167
- package/frontend-vue/tests/views/use-assistant.test.ts +0 -53
- package/frontend-vue/tests/views/view-format.test.ts +0 -59
- package/frontend-vue/vitest.config.ts +0 -33
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
type ChannelStatus,
|
|
4
|
-
createChannelClient,
|
|
5
|
-
} from "../app/runtime/channel-client";
|
|
6
|
-
import { CHANNEL_RECONNECT_DELAYS_MS } from "../app/runtime/constants";
|
|
7
|
-
|
|
8
|
-
interface FakeStream {
|
|
9
|
-
path: string;
|
|
10
|
-
emit: (name: string, data: string) => void;
|
|
11
|
-
end: () => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface Harness {
|
|
15
|
-
streams: FakeStream[];
|
|
16
|
-
posts: Array<{ path: string; body: unknown }>;
|
|
17
|
-
statuses: ChannelStatus[];
|
|
18
|
-
ready: ReturnType<typeof vi.fn>;
|
|
19
|
-
frames: string[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const READY = '{"connectionId":"c 1"}';
|
|
24
|
-
|
|
25
|
-
function openFakeStream(
|
|
26
|
-
streams: FakeStream[],
|
|
27
|
-
path: string,
|
|
28
|
-
signal: AbortSignal,
|
|
29
|
-
): Promise<Response> {
|
|
30
|
-
let controller!: ReadableStreamDefaultController<Uint8Array>;
|
|
31
|
-
const body = new ReadableStream<Uint8Array>({
|
|
32
|
-
start: (c) => {
|
|
33
|
-
controller = c;
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
signal.addEventListener("abort", () =>
|
|
37
|
-
controller.error(new DOMException("aborted", "AbortError")),
|
|
38
|
-
);
|
|
39
|
-
streams.push({
|
|
40
|
-
path,
|
|
41
|
-
emit: (name, data) =>
|
|
42
|
-
controller.enqueue(encoder.encode(`event: ${name}\ndata: ${data}\n\n`)),
|
|
43
|
-
end: () => controller.close(),
|
|
44
|
-
});
|
|
45
|
-
return Promise.resolve(new Response(body, { status: 200 }));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function startClient(post = vi.fn(async () => undefined)) {
|
|
49
|
-
const harness: Harness = {
|
|
50
|
-
streams: [],
|
|
51
|
-
posts: [],
|
|
52
|
-
statuses: [],
|
|
53
|
-
ready: vi.fn(),
|
|
54
|
-
frames: [],
|
|
55
|
-
};
|
|
56
|
-
const client = createChannelClient({
|
|
57
|
-
post: async (path, body) => {
|
|
58
|
-
harness.posts.push({ path, body });
|
|
59
|
-
return post(path, body);
|
|
60
|
-
},
|
|
61
|
-
openStream: (path, signal) => openFakeStream(harness.streams, path, signal),
|
|
62
|
-
onReady: harness.ready,
|
|
63
|
-
onFrame: (raw) => harness.frames.push(raw),
|
|
64
|
-
onStatusChange: (status) => harness.statuses.push(status),
|
|
65
|
-
});
|
|
66
|
-
client.start();
|
|
67
|
-
return { client, harness };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function flush(): Promise<void> {
|
|
71
|
-
for (let i = 0; i < 10; i += 1) await Promise.resolve();
|
|
72
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
afterEach(() => {
|
|
76
|
-
vi.useRealTimers();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("channel client", () => {
|
|
80
|
-
it("stays closed until started", async () => {
|
|
81
|
-
const streams: FakeStream[] = [];
|
|
82
|
-
const client = createChannelClient({
|
|
83
|
-
post: vi.fn(),
|
|
84
|
-
openStream: (path, signal) => openFakeStream(streams, path, signal),
|
|
85
|
-
});
|
|
86
|
-
await flush();
|
|
87
|
-
expect(streams).toEqual([]);
|
|
88
|
-
expect(client.getStatus()).toBe("disconnected");
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("opens one stream for the dashboard and its chat, on the dashboard origin, with no credential", async () => {
|
|
92
|
-
const { client, harness } = startClient();
|
|
93
|
-
await flush();
|
|
94
|
-
expect(harness.streams.map((stream) => stream.path)).toEqual([
|
|
95
|
-
"/ai/channel/events",
|
|
96
|
-
]);
|
|
97
|
-
client.stop();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("announces the connection, then hands over every frame raw, whoever it is for", async () => {
|
|
101
|
-
const { client, harness } = startClient();
|
|
102
|
-
await flush();
|
|
103
|
-
harness.streams[0]?.emit("ready", READY);
|
|
104
|
-
harness.streams[0]?.emit(
|
|
105
|
-
"message",
|
|
106
|
-
'{"type":"host_command_navigate","path":"/x"}',
|
|
107
|
-
);
|
|
108
|
-
harness.streams[0]?.emit("message", '{"type":"run_done"}');
|
|
109
|
-
harness.streams[0]?.emit("unknown", "{}");
|
|
110
|
-
await flush();
|
|
111
|
-
expect(harness.ready).toHaveBeenCalledTimes(1);
|
|
112
|
-
expect(client.isConnected()).toBe(true);
|
|
113
|
-
expect(harness.frames).toEqual([
|
|
114
|
-
'{"type":"host_command_navigate","path":"/x"}',
|
|
115
|
-
'{"type":"run_done"}',
|
|
116
|
-
]);
|
|
117
|
-
client.stop();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("posts one message at a time, in order, to the connection", async () => {
|
|
121
|
-
const pending: Array<() => void> = [];
|
|
122
|
-
const post = vi.fn(
|
|
123
|
-
() => new Promise<void>((resolve) => pending.push(() => resolve())),
|
|
124
|
-
);
|
|
125
|
-
const { client, harness } = startClient(post);
|
|
126
|
-
await flush();
|
|
127
|
-
harness.streams[0]?.emit("ready", READY);
|
|
128
|
-
await flush();
|
|
129
|
-
client.send({ n: 1 });
|
|
130
|
-
client.send({ n: 2 });
|
|
131
|
-
await flush();
|
|
132
|
-
expect(harness.posts).toEqual([
|
|
133
|
-
{ path: "/ai/channel/c%201/messages", body: { n: 1 } },
|
|
134
|
-
]);
|
|
135
|
-
pending.shift()?.();
|
|
136
|
-
await flush();
|
|
137
|
-
expect(harness.posts.at(-1)).toEqual({
|
|
138
|
-
path: "/ai/channel/c%201/messages",
|
|
139
|
-
body: { n: 2 },
|
|
140
|
-
});
|
|
141
|
-
client.stop();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("drops a message sent before the connection is ready, and says so", async () => {
|
|
145
|
-
const { client, harness } = startClient();
|
|
146
|
-
expect(client.send({ n: 1 })).toBe(false);
|
|
147
|
-
await flush();
|
|
148
|
-
expect(harness.posts).toEqual([]);
|
|
149
|
-
harness.streams[0]?.emit("ready", READY);
|
|
150
|
-
await flush();
|
|
151
|
-
expect(client.send({ n: 2 })).toBe(true);
|
|
152
|
-
client.stop();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("reconnects with backoff when the stream ends, and announces the new connection", async () => {
|
|
156
|
-
vi.useFakeTimers();
|
|
157
|
-
const { client, harness } = startClient();
|
|
158
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
159
|
-
harness.streams[0]?.emit("ready", READY);
|
|
160
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
161
|
-
harness.streams[0]?.end();
|
|
162
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
163
|
-
expect(client.isConnected()).toBe(false);
|
|
164
|
-
expect(harness.statuses).toEqual([
|
|
165
|
-
"connecting",
|
|
166
|
-
"connected",
|
|
167
|
-
"reconnecting",
|
|
168
|
-
]);
|
|
169
|
-
await vi.advanceTimersByTimeAsync(CHANNEL_RECONNECT_DELAYS_MS[0]);
|
|
170
|
-
harness.streams[1]?.emit("ready", READY);
|
|
171
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
172
|
-
expect(harness.streams).toHaveLength(2);
|
|
173
|
-
expect(harness.ready).toHaveBeenCalledTimes(2);
|
|
174
|
-
expect(harness.statuses.at(-1)).toBe("connected");
|
|
175
|
-
client.stop();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("drops the connection and reconnects when a post fails", async () => {
|
|
179
|
-
vi.useFakeTimers();
|
|
180
|
-
const post = vi.fn(async () => {
|
|
181
|
-
throw new Error("404");
|
|
182
|
-
});
|
|
183
|
-
const { client, harness } = startClient(post);
|
|
184
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
185
|
-
harness.streams[0]?.emit("ready", READY);
|
|
186
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
187
|
-
client.send({ n: 1 });
|
|
188
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
189
|
-
expect(client.getStatus()).toBe("reconnecting");
|
|
190
|
-
await vi.advanceTimersByTimeAsync(CHANNEL_RECONNECT_DELAYS_MS[0]);
|
|
191
|
-
expect(harness.streams).toHaveLength(2);
|
|
192
|
-
client.stop();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("says connecting while reconnectNow replaces a live stream, until the new one is ready", async () => {
|
|
196
|
-
const { client, harness } = startClient();
|
|
197
|
-
await flush();
|
|
198
|
-
harness.streams[0]?.emit("ready", READY);
|
|
199
|
-
await flush();
|
|
200
|
-
client.reconnectNow();
|
|
201
|
-
await flush();
|
|
202
|
-
expect(client.getStatus()).toBe("connecting");
|
|
203
|
-
expect(client.send({ n: 1 })).toBe(false);
|
|
204
|
-
harness.streams[1]?.emit("ready", READY);
|
|
205
|
-
await flush();
|
|
206
|
-
expect(harness.statuses).toEqual([
|
|
207
|
-
"connecting",
|
|
208
|
-
"connected",
|
|
209
|
-
"connecting",
|
|
210
|
-
"connected",
|
|
211
|
-
]);
|
|
212
|
-
expect(harness.ready).toHaveBeenCalledTimes(2);
|
|
213
|
-
client.stop();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("skips the backoff on reconnectNow", async () => {
|
|
217
|
-
vi.useFakeTimers();
|
|
218
|
-
const { client, harness } = startClient();
|
|
219
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
220
|
-
harness.streams[0]?.end();
|
|
221
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
222
|
-
client.reconnectNow();
|
|
223
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
224
|
-
expect(harness.streams).toHaveLength(2);
|
|
225
|
-
client.stop();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("stops reconnecting once stopped, and opens again on start", async () => {
|
|
229
|
-
vi.useFakeTimers();
|
|
230
|
-
const { client, harness } = startClient();
|
|
231
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
232
|
-
client.stop();
|
|
233
|
-
await vi.advanceTimersByTimeAsync(
|
|
234
|
-
CHANNEL_RECONNECT_DELAYS_MS[CHANNEL_RECONNECT_DELAYS_MS.length - 1] * 2,
|
|
235
|
-
);
|
|
236
|
-
expect(harness.streams).toHaveLength(1);
|
|
237
|
-
expect(client.getStatus()).toBe("disconnected");
|
|
238
|
-
client.reconnectNow();
|
|
239
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
240
|
-
expect(harness.streams).toHaveLength(1);
|
|
241
|
-
client.start();
|
|
242
|
-
await vi.advanceTimersByTimeAsync(0);
|
|
243
|
-
expect(harness.streams).toHaveLength(2);
|
|
244
|
-
client.stop();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { mount, type VueWrapper } from "@vue/test-utils";
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
import { nextTick, ref } from "vue";
|
|
5
|
-
import BlockPreviewCard from "../../app/chat/components/BlockPreviewCard.vue";
|
|
6
|
-
import { useConversation } from "../../app/chat/composables/useConversation";
|
|
7
|
-
import { CHAT_I18N_KEY } from "../../app/chat/composables/useChatI18n";
|
|
8
|
-
import type { ConversationMessage } from "../../app/chat/types/conversation";
|
|
9
|
-
import type { BlockPreview } from "../../app/chat/types/protocol";
|
|
10
|
-
import {
|
|
11
|
-
countBlocks,
|
|
12
|
-
previewTabs,
|
|
13
|
-
referenceView,
|
|
14
|
-
type ReferenceView,
|
|
15
|
-
} from "../../app/chat/utils/block-preview";
|
|
16
|
-
import { buildUserMessage } from "../../app/chat/utils/conversation-messages";
|
|
17
|
-
import { createTestI18n } from "../support/i18n";
|
|
18
|
-
import { DmsBlockPreview } from "../support/stand-ins/DmsBlockPreview";
|
|
19
|
-
import { UTabs } from "../support/stand-ins/UTabs";
|
|
20
|
-
import { PANEL_STUBS } from "../support/stubs";
|
|
21
|
-
|
|
22
|
-
const CONVERSATION_ID = "conv-1";
|
|
23
|
-
const MOCKUP_NAME = "mockup.png";
|
|
24
|
-
const MOCKUP_DATA_URL = "data:image/png;base64,AAAA";
|
|
25
|
-
|
|
26
|
-
const PREVIEW: BlockPreview = {
|
|
27
|
-
id: "preview-1",
|
|
28
|
-
title: "Revenue card",
|
|
29
|
-
description: "Same layout; the trend sits under the value.",
|
|
30
|
-
tree: {
|
|
31
|
-
type: "Section",
|
|
32
|
-
children: [
|
|
33
|
-
{ type: "KpiCard", options: { label: "Revenue" } },
|
|
34
|
-
{ type: "KpiCard", options: { label: "Orders" } },
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
timestampMs: 1_000,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const WITH_VARIANTS: BlockPreview = {
|
|
41
|
-
...PREVIEW,
|
|
42
|
-
variants: [
|
|
43
|
-
{ label: "Compact", tree: [{ type: "KpiCard", options: { size: "sm" } }] },
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const SKETCH = {
|
|
48
|
-
html: '<article class="card"><h3>Revenue</h3><p>12 400 €</p></article>',
|
|
49
|
-
css: ".card { background: var(--sketch-surface); }",
|
|
50
|
-
caption: "Revenue card with a sparkline",
|
|
51
|
-
height: 240,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const DMS_VS_SKETCH: BlockPreview = {
|
|
55
|
-
id: "preview-2",
|
|
56
|
-
title: "Revenue card: DMS or custom",
|
|
57
|
-
label: "DMS KpiCard",
|
|
58
|
-
tree: { type: "KpiCard", options: { label: "Revenue" } },
|
|
59
|
-
variants: [{ label: "Custom sketch", sketch: SKETCH }],
|
|
60
|
-
timestampMs: 2_000,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const SKETCH_ONLY: BlockPreview = {
|
|
64
|
-
id: "preview-3",
|
|
65
|
-
title: "Custom revenue card",
|
|
66
|
-
sketch: SKETCH,
|
|
67
|
-
timestampMs: 3_000,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
interface MountOptions {
|
|
71
|
-
preview?: BlockPreview;
|
|
72
|
-
reference?: ReferenceView | null;
|
|
73
|
-
hasPreviewComponent?: boolean;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function mountCard(options: MountOptions = {}): VueWrapper {
|
|
77
|
-
return mount(BlockPreviewCard, {
|
|
78
|
-
props: {
|
|
79
|
-
preview: options.preview ?? PREVIEW,
|
|
80
|
-
reference: options.reference ?? null,
|
|
81
|
-
},
|
|
82
|
-
global: {
|
|
83
|
-
stubs: { ...PANEL_STUBS, UTabs },
|
|
84
|
-
components:
|
|
85
|
-
options.hasPreviewComponent === false ? {} : { DmsBlockPreview },
|
|
86
|
-
provide: { [CHAT_I18N_KEY as symbol]: createTestI18n() },
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function openModal(wrapper: VueWrapper): Promise<void> {
|
|
92
|
-
await wrapper.find("button.bp-card").trigger("click");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
describe("block preview helpers", () => {
|
|
96
|
-
it("counts nested blocks", () => {
|
|
97
|
-
expect(countBlocks(PREVIEW.tree)).toBe(3);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("puts the proposed tree first, then one tab per variant", () => {
|
|
101
|
-
const tabs = previewTabs(WITH_VARIANTS);
|
|
102
|
-
expect(tabs.map((tab) => tab.label)).toEqual([null, "Compact"]);
|
|
103
|
-
expect(tabs[1].tree).toEqual(WITH_VARIANTS.variants?.[0].tree);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("finds the mockup among the images attached in this session", () => {
|
|
107
|
-
const messages: ConversationMessage[] = [
|
|
108
|
-
buildUserMessage("like this", [
|
|
109
|
-
{
|
|
110
|
-
name: MOCKUP_NAME,
|
|
111
|
-
mimeType: "image/png",
|
|
112
|
-
size: 4,
|
|
113
|
-
dataUrl: MOCKUP_DATA_URL,
|
|
114
|
-
},
|
|
115
|
-
]),
|
|
116
|
-
];
|
|
117
|
-
expect(referenceView({ attachmentName: MOCKUP_NAME }, messages)).toEqual({
|
|
118
|
-
kind: "image",
|
|
119
|
-
src: MOCKUP_DATA_URL,
|
|
120
|
-
name: MOCKUP_NAME,
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("says the mockup is gone when only its name survived a reload", () => {
|
|
125
|
-
const messages = [
|
|
126
|
-
buildUserMessage("like this", [
|
|
127
|
-
{ name: MOCKUP_NAME, mimeType: "image/png", size: 4 },
|
|
128
|
-
]),
|
|
129
|
-
];
|
|
130
|
-
expect(referenceView({ attachmentName: MOCKUP_NAME }, messages)).toEqual({
|
|
131
|
-
kind: "missing",
|
|
132
|
-
name: MOCKUP_NAME,
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("loads a same-origin path, frames the mockup viewer, links an external URL, ignores the rest (fails when the mockup viewer is drawn as a broken image)", () => {
|
|
137
|
-
expect(referenceView({ url: "/media/a.png" }, [])?.kind).toBe("image");
|
|
138
|
-
expect(referenceView({ url: "/mockup?name=bikes&page=home" }, [])).toEqual({
|
|
139
|
-
kind: "page",
|
|
140
|
-
src: "/mockup?name=bikes&page=home",
|
|
141
|
-
});
|
|
142
|
-
expect(referenceView({ url: "/mockup/bikes" }, [])?.kind).toBe("page");
|
|
143
|
-
expect(referenceView({ url: "/mockups/a.png" }, [])?.kind).toBe("image");
|
|
144
|
-
expect(referenceView({ url: "https://x.example/a.png" }, [])?.kind).toBe(
|
|
145
|
-
"link",
|
|
146
|
-
);
|
|
147
|
-
expect(referenceView({ url: "//x.example/a.png" }, [])).toBeNull();
|
|
148
|
-
expect(referenceView({ url: "javascript:alert(1)" }, [])).toBeNull();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe("block preview events", () => {
|
|
153
|
-
function conversation() {
|
|
154
|
-
const handlers: ((msg: unknown) => void)[] = [];
|
|
155
|
-
const result = useConversation({
|
|
156
|
-
activeId: ref(CONVERSATION_ID),
|
|
157
|
-
send: () => true,
|
|
158
|
-
onMessage: (handler) => {
|
|
159
|
-
handlers.push(handler);
|
|
160
|
-
return () => undefined;
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
const receive = (event: Record<string, unknown>) =>
|
|
164
|
-
handlers.forEach((handler) =>
|
|
165
|
-
handler({ conversationId: CONVERSATION_ID, ...event }),
|
|
166
|
-
);
|
|
167
|
-
return { ...result, receive };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
it("appends a live preview once", () => {
|
|
171
|
-
const chat = conversation();
|
|
172
|
-
chat.receive({ type: "block_preview", preview: PREVIEW });
|
|
173
|
-
chat.receive({ type: "block_preview", preview: PREVIEW });
|
|
174
|
-
expect(chat.messages.value).toHaveLength(1);
|
|
175
|
-
expect(chat.messages.value[0]).toMatchObject({
|
|
176
|
-
role: "block_preview",
|
|
177
|
-
preview: PREVIEW,
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("restores a preview from the stored transcript", () => {
|
|
182
|
-
const chat = conversation();
|
|
183
|
-
chat.receive({
|
|
184
|
-
type: "conversation_snapshot",
|
|
185
|
-
messages: [
|
|
186
|
-
{ role: "user", content: "show me", timestampMs: 1 },
|
|
187
|
-
{
|
|
188
|
-
role: "block_preview",
|
|
189
|
-
content: "",
|
|
190
|
-
preview: PREVIEW,
|
|
191
|
-
timestampMs: 2,
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
});
|
|
195
|
-
expect(chat.messages.value.map((m) => m.role)).toEqual([
|
|
196
|
-
"user",
|
|
197
|
-
"block_preview",
|
|
198
|
-
]);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("keeps the preview when a running turn is replayed", () => {
|
|
202
|
-
const chat = conversation();
|
|
203
|
-
chat.receive({
|
|
204
|
-
type: "conversation_snapshot",
|
|
205
|
-
messages: [{ role: "user", content: "show me", timestampMs: 1 }],
|
|
206
|
-
});
|
|
207
|
-
chat.receive({ type: "block_preview", preview: PREVIEW });
|
|
208
|
-
chat.receive({ type: "run_resumed" });
|
|
209
|
-
expect(chat.messages.value.at(-1)?.role).toBe("block_preview");
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("the block preview attachment", () => {
|
|
214
|
-
it("reads as a file: thumbnail, title, what it holds", () => {
|
|
215
|
-
const wrapper = mountCard({ preview: WITH_VARIANTS });
|
|
216
|
-
const card = wrapper.find("button.bp-card");
|
|
217
|
-
expect(card.attributes("aria-haspopup")).toBe("dialog");
|
|
218
|
-
expect(card.attributes("aria-label")).toBe(
|
|
219
|
-
"Open the block preview: Revenue card",
|
|
220
|
-
);
|
|
221
|
-
expect(wrapper.find(".bp-thumb .dms-block-preview").exists()).toBe(true);
|
|
222
|
-
expect(wrapper.find(".bp-card__meta").text()).toBe(
|
|
223
|
-
"Section · 3 blocks · 2 variants",
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("draws a schematic thumbnail when the DMS has no preview component", () => {
|
|
228
|
-
const wrapper = mountCard({ hasPreviewComponent: false });
|
|
229
|
-
expect(wrapper.findAll(".bp-thumb__cell")).toHaveLength(2);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("opens a dialog rendering the real blocks", async () => {
|
|
233
|
-
const wrapper = mountCard();
|
|
234
|
-
expect(wrapper.find("[role=dialog]").exists()).toBe(false);
|
|
235
|
-
await openModal(wrapper);
|
|
236
|
-
const dialog = wrapper.find("[role=dialog]");
|
|
237
|
-
expect(dialog.text()).toContain("Revenue card");
|
|
238
|
-
expect(dialog.find(".bp-pane__stage .dms-block-preview").text()).toBe(
|
|
239
|
-
JSON.stringify(PREVIEW.tree),
|
|
240
|
-
);
|
|
241
|
-
expect(dialog.find(".bp-fallback").exists()).toBe(false);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("shows the tree as JSON when the DMS cannot render it", async () => {
|
|
245
|
-
const wrapper = mountCard({ hasPreviewComponent: false });
|
|
246
|
-
await openModal(wrapper);
|
|
247
|
-
const fallback = wrapper.find(".bp-fallback");
|
|
248
|
-
expect(fallback.text()).toContain(
|
|
249
|
-
"This DMS version cannot draw block previews",
|
|
250
|
-
);
|
|
251
|
-
expect(JSON.parse(fallback.find("pre").text())).toEqual(PREVIEW.tree);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("switches the rendered tree with the variant tabs", async () => {
|
|
255
|
-
const wrapper = mountCard({ preview: WITH_VARIANTS });
|
|
256
|
-
await openModal(wrapper);
|
|
257
|
-
const tabs = wrapper.findAll("[role=tab]");
|
|
258
|
-
expect(tabs.map((tab) => tab.text())).toEqual(["Proposed", "Compact"]);
|
|
259
|
-
await tabs[1].trigger("click");
|
|
260
|
-
expect(wrapper.find(".bp-pane__stage .dms-block-preview").text()).toBe(
|
|
261
|
-
JSON.stringify(WITH_VARIANTS.variants?.[0].tree),
|
|
262
|
-
);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("puts the mockup beside the blocks", async () => {
|
|
266
|
-
const wrapper = mountCard({
|
|
267
|
-
preview: { ...PREVIEW, reference: { caption: "Your Figma frame" } },
|
|
268
|
-
reference: { kind: "image", src: MOCKUP_DATA_URL, name: MOCKUP_NAME },
|
|
269
|
-
});
|
|
270
|
-
await openModal(wrapper);
|
|
271
|
-
expect(wrapper.find(".bp-modal__panes").classes()).toContain("is-split");
|
|
272
|
-
const image = wrapper.find(".bp-pane__image");
|
|
273
|
-
expect(image.attributes("src")).toBe(MOCKUP_DATA_URL);
|
|
274
|
-
expect(image.attributes("alt")).toBe("Your Figma frame");
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it("links an external mockup instead of loading it", async () => {
|
|
278
|
-
const href = "https://figma.example/frame.png";
|
|
279
|
-
const wrapper = mountCard({ reference: { kind: "link", href } });
|
|
280
|
-
await openModal(wrapper);
|
|
281
|
-
expect(wrapper.find(".bp-pane__image").exists()).toBe(false);
|
|
282
|
-
const link = wrapper.find(".bp-pane__link");
|
|
283
|
-
expect(link.attributes("href")).toBe(href);
|
|
284
|
-
expect(link.attributes("rel")).toBe("noopener noreferrer");
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
describe("a custom sketch in the preview", () => {
|
|
289
|
-
const SKETCH_NODE = { type: "sketch", options: SKETCH };
|
|
290
|
-
|
|
291
|
-
function drawnTree(wrapper: VueWrapper, selector: string): unknown {
|
|
292
|
-
const preview = wrapper.find(`${selector} .dms-block-preview`);
|
|
293
|
-
expect(preview.attributes("data-fetches-block-types")).toBe("false");
|
|
294
|
-
return JSON.parse(preview.text());
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async function openOnSketchTab(wrapper: VueWrapper): Promise<void> {
|
|
298
|
-
await openModal(wrapper);
|
|
299
|
-
await wrapper.findAll("[role=tab]")[1].trigger("click");
|
|
300
|
-
await nextTick();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
it("tabs a DMS block against a custom sketch", async () => {
|
|
304
|
-
const wrapper = mountCard({ preview: DMS_VS_SKETCH });
|
|
305
|
-
await openModal(wrapper);
|
|
306
|
-
const tabs = wrapper.findAll("[role=tab]");
|
|
307
|
-
expect(tabs.map((tab) => tab.text())).toEqual([
|
|
308
|
-
"DMS KpiCard",
|
|
309
|
-
"Custom sketch",
|
|
310
|
-
]);
|
|
311
|
-
expect(wrapper.find(".bp-pane__stage .dms-block-preview").exists()).toBe(
|
|
312
|
-
true,
|
|
313
|
-
);
|
|
314
|
-
expect(wrapper.find(".bp-pane--sketch").exists()).toBe(false);
|
|
315
|
-
await openOnSketchTab(wrapper);
|
|
316
|
-
expect(wrapper.find(".bp-pane__stage").exists()).toBe(false);
|
|
317
|
-
expect(wrapper.find(".bp-pane--sketch").text()).toContain(
|
|
318
|
-
"Custom sketch — not a DMS block",
|
|
319
|
-
);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("draws the sketch as the DMS sketch node without waiting on the block types, never in a frame of its own (fails when the chat builds the sketch document itself, or leaves the sketch to wait on the block types fetch)", async () => {
|
|
323
|
-
const wrapper = mountCard({ preview: DMS_VS_SKETCH });
|
|
324
|
-
await openOnSketchTab(wrapper);
|
|
325
|
-
expect(drawnTree(wrapper, ".bp-pane--sketch")).toEqual(SKETCH_NODE);
|
|
326
|
-
expect(wrapper.find("iframe").exists()).toBe(false);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("labels the attachment as holding a custom sketch", () => {
|
|
330
|
-
const wrapper = mountCard({ preview: DMS_VS_SKETCH });
|
|
331
|
-
expect(wrapper.find(".bp-thumb__badge").text()).toBe("Custom sketch");
|
|
332
|
-
expect(wrapper.find(".bp-card__meta").text()).toBe(
|
|
333
|
-
"KpiCard · 1 block · 2 variants · custom sketch",
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it("thumbnails a sketch-only preview with the DMS sketch node at the thumbnail height", async () => {
|
|
338
|
-
const wrapper = mountCard({ preview: SKETCH_ONLY });
|
|
339
|
-
await nextTick();
|
|
340
|
-
expect(drawnTree(wrapper, ".bp-thumb")).toEqual({
|
|
341
|
-
type: "sketch",
|
|
342
|
-
options: { html: SKETCH.html, css: SKETCH.css, height: 360 },
|
|
343
|
-
});
|
|
344
|
-
expect(wrapper.find(".bp-card__meta").text()).toBe("custom sketch");
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("shows the sketch node as JSON when the DMS cannot render it (fails when the chat falls back to a frame of its own)", async () => {
|
|
348
|
-
const wrapper = mountCard({
|
|
349
|
-
preview: { ...SKETCH_ONLY, tree: { type: "KpiCard" } },
|
|
350
|
-
hasPreviewComponent: false,
|
|
351
|
-
});
|
|
352
|
-
await openModal(wrapper);
|
|
353
|
-
await nextTick();
|
|
354
|
-
expect(wrapper.find("iframe").exists()).toBe(false);
|
|
355
|
-
expect(
|
|
356
|
-
JSON.parse(wrapper.find(".bp-pane--sketch .bp-fallback__json").text()),
|
|
357
|
-
).toEqual(SKETCH_NODE);
|
|
358
|
-
expect(wrapper.find(".bp-modal__panes").classes()).toContain("is-split");
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
it("keeps a sketch-only preview as a single tab", () => {
|
|
362
|
-
const restored = previewTabs(SKETCH_ONLY);
|
|
363
|
-
expect(restored).toHaveLength(1);
|
|
364
|
-
expect(restored[0].sketch).toEqual(SKETCH);
|
|
365
|
-
expect(restored[0].tree).toBeUndefined();
|
|
366
|
-
});
|
|
367
|
-
});
|