makethisbetter 1.5.4 → 1.7.0
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/README.md +10 -10
- package/dist/annotate/draw-note-bar.d.ts +29 -0
- package/dist/annotate/draw-note-bar.d.ts.map +1 -0
- package/dist/annotate/draw-note-bar.test.d.ts +2 -0
- package/dist/annotate/draw-note-bar.test.d.ts.map +1 -0
- package/dist/annotate/draw.d.ts +15 -9
- package/dist/annotate/draw.d.ts.map +1 -1
- package/dist/annotate/highlighter.d.ts +2 -0
- package/dist/annotate/highlighter.d.ts.map +1 -1
- package/dist/annotate/session.d.ts +16 -2
- package/dist/annotate/session.d.ts.map +1 -1
- package/dist/api/client.d.ts +8 -5
- package/dist/api/client.d.ts.map +1 -1
- package/dist/context/breadcrumbs.d.ts +26 -0
- package/dist/context/breadcrumbs.d.ts.map +1 -0
- package/dist/context/breadcrumbs.test.d.ts +2 -0
- package/dist/context/breadcrumbs.test.d.ts.map +1 -0
- package/dist/context/dom-utils.d.ts +3 -0
- package/dist/context/dom-utils.d.ts.map +1 -0
- package/dist/context/frustration.d.ts +0 -1
- package/dist/context/frustration.d.ts.map +1 -1
- package/dist/i18n/de.d.ts +24 -0
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/en.d.ts +24 -0
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/es.d.ts +24 -0
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/fr.d.ts +24 -0
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/ja.d.ts +24 -0
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ko.d.ts +24 -0
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/zh-CN.d.ts +24 -0
- package/dist/i18n/zh-CN.d.ts.map +1 -1
- package/dist/makethisbetter.cjs +50 -25
- package/dist/makethisbetter.cjs.map +1 -1
- package/dist/makethisbetter.esm.js +1132 -590
- package/dist/makethisbetter.esm.js.map +1 -1
- package/dist/makethisbetter.js +49 -24
- package/dist/makethisbetter.js.map +1 -1
- package/dist/popup/clarify.d.ts +28 -7
- package/dist/popup/clarify.d.ts.map +1 -1
- package/dist/popup/comment.d.ts +1 -0
- package/dist/popup/comment.d.ts.map +1 -1
- package/dist/record/replay.d.ts +7 -0
- package/dist/record/replay.d.ts.map +1 -0
- package/dist/screenshot/capture.d.ts +1 -0
- package/dist/screenshot/capture.d.ts.map +1 -1
- package/dist/styles.d.ts +1 -0
- package/dist/styles.d.ts.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/widget/controller.d.ts +18 -0
- package/dist/widget/controller.d.ts.map +1 -1
- package/dist/widget/dim-overlay.d.ts +8 -0
- package/dist/widget/dim-overlay.d.ts.map +1 -0
- package/dist/widget/dim-overlay.test.d.ts +2 -0
- package/dist/widget/dim-overlay.test.d.ts.map +1 -0
- package/dist/widget/payload.d.ts +2 -2
- package/dist/widget/payload.d.ts.map +1 -1
- package/dist/widget/tab.d.ts +3 -0
- package/dist/widget/tab.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/annotate/draw-note-bar.test.ts +90 -0
- package/src/annotate/draw-note-bar.ts +105 -0
- package/src/annotate/draw.test.ts +74 -84
- package/src/annotate/draw.ts +108 -65
- package/src/annotate/highlighter.test.ts +24 -1
- package/src/annotate/highlighter.ts +16 -2
- package/src/annotate/session.test.ts +112 -96
- package/src/annotate/session.ts +54 -10
- package/src/api/client.test.ts +69 -30
- package/src/api/client.ts +68 -20
- package/src/context/breadcrumbs.test.ts +154 -0
- package/src/context/breadcrumbs.ts +157 -0
- package/src/context/dom-utils.ts +16 -0
- package/src/context/frustration.ts +4 -8
- package/src/i18n/de.ts +34 -11
- package/src/i18n/en.ts +33 -10
- package/src/i18n/es.ts +34 -11
- package/src/i18n/fr.ts +33 -10
- package/src/i18n/index.test.ts +12 -0
- package/src/i18n/ja.ts +32 -9
- package/src/i18n/ko.ts +34 -11
- package/src/i18n/zh-CN.ts +35 -12
- package/src/popup/clarify.test.ts +132 -40
- package/src/popup/clarify.ts +154 -42
- package/src/popup/comment.test.ts +57 -0
- package/src/popup/comment.ts +15 -9
- package/src/record/replay.ts +115 -0
- package/src/record/session.test.ts +8 -1
- package/src/record/session.ts +1 -1
- package/src/screenshot/capture.test.ts +51 -23
- package/src/screenshot/capture.ts +101 -55
- package/src/styles/widget.css +347 -1
- package/src/styles.ts +2 -0
- package/src/types.ts +15 -0
- package/src/widget/controller.test.ts +476 -65
- package/src/widget/controller.ts +222 -40
- package/src/widget/dim-overlay.test.ts +27 -0
- package/src/widget/dim-overlay.ts +20 -0
- package/src/widget/payload.test.ts +26 -1
- package/src/widget/payload.ts +3 -1
- package/src/widget/pet.test.ts +2 -2
- package/src/widget/tab.test.ts +15 -0
- package/src/widget/tab.ts +11 -3
|
@@ -2,9 +2,58 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
2
2
|
import { MakeThisBetter } from '../index'
|
|
3
3
|
|
|
4
4
|
vi.mock('html-to-image', () => ({
|
|
5
|
-
|
|
5
|
+
toJpeg: vi.fn(async () => 'data:image/jpeg;base64,/9j/AA=='),
|
|
6
6
|
}))
|
|
7
7
|
|
|
8
|
+
vi.mock('@rrweb/record', () => {
|
|
9
|
+
const record = Object.assign(() => () => {}, { addCustomEvent: () => {} })
|
|
10
|
+
return { record }
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
function sessionFlowResponse(
|
|
14
|
+
url: RequestInfo | URL,
|
|
15
|
+
init: RequestInit | undefined,
|
|
16
|
+
feedback: Record<string, unknown>,
|
|
17
|
+
aiClarifyAvailable = false,
|
|
18
|
+
): Response {
|
|
19
|
+
const href = String(url)
|
|
20
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
21
|
+
if (href.endsWith('/feedback')) {
|
|
22
|
+
return new Response(JSON.stringify({ feedback }), { status: 201 })
|
|
23
|
+
}
|
|
24
|
+
if (href.endsWith('/clarification')) {
|
|
25
|
+
return new Response(JSON.stringify({
|
|
26
|
+
clarification: { status: 'completed', messages: [], done: true },
|
|
27
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
28
|
+
}
|
|
29
|
+
return new Response(JSON.stringify({
|
|
30
|
+
submission_session: {
|
|
31
|
+
id: 'submission_1',
|
|
32
|
+
token: 'submission-secret',
|
|
33
|
+
ai_clarify_available: aiClarifyAvailable,
|
|
34
|
+
},
|
|
35
|
+
}), { status: 201 })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function confirmSubmission(shadow: ShadowRoot): Promise<void> {
|
|
39
|
+
await vi.waitFor(() => {
|
|
40
|
+
expect(shadow.querySelector('.mtb-clarify-summary')).not.toBeNull()
|
|
41
|
+
})
|
|
42
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-clarify-send-feedback')!.click()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function performDrawStroke(overlay: HTMLDivElement): void {
|
|
46
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 10, clientY: 10, bubbles: true }))
|
|
47
|
+
for (let i = 1; i <= 5; i++) {
|
|
48
|
+
overlay.dispatchEvent(new MouseEvent('mousemove', { clientX: 10 + i * 8, clientY: 10 + i * 8, bubbles: true }))
|
|
49
|
+
}
|
|
50
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 50, clientY: 50, bubbles: true }))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pressEscape(): void {
|
|
54
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
|
|
55
|
+
}
|
|
56
|
+
|
|
8
57
|
describe('MakeThisBetter widget flow', () => {
|
|
9
58
|
afterEach(() => {
|
|
10
59
|
MakeThisBetter.destroy()
|
|
@@ -12,7 +61,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
12
61
|
document.body.innerHTML = ''
|
|
13
62
|
})
|
|
14
63
|
|
|
15
|
-
it('
|
|
64
|
+
it('creates a Session on Submit and finalizes Feedback only after Send feedback', async () => {
|
|
16
65
|
const target = document.createElement('button')
|
|
17
66
|
target.id = 'export-btn'
|
|
18
67
|
target.textContent = 'Export PDF'
|
|
@@ -21,13 +70,26 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
21
70
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
22
71
|
|
|
23
72
|
let capturedBody: FormData | null = null
|
|
24
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
73
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
74
|
+
const href = String(url)
|
|
75
|
+
if (href.endsWith('/feedback')) {
|
|
76
|
+
return new Response(JSON.stringify({
|
|
77
|
+
feedback: { id: 'FB-1', status: 'received', project_id: 'acme' },
|
|
78
|
+
}), { status: 201 })
|
|
79
|
+
}
|
|
80
|
+
if (href.endsWith('/clarification')) {
|
|
81
|
+
return new Response(JSON.stringify({
|
|
82
|
+
clarification: { status: 'completed', messages: [], done: true },
|
|
83
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
84
|
+
}
|
|
25
85
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
26
|
-
return new Response(JSON.stringify({
|
|
86
|
+
return new Response(JSON.stringify({
|
|
87
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
88
|
+
}), { status: 201 })
|
|
27
89
|
})
|
|
28
90
|
|
|
29
91
|
MakeThisBetter.init({
|
|
30
|
-
projectKey: '
|
|
92
|
+
projectKey: 'acme',
|
|
31
93
|
apiUrl: 'https://api.example.com/api/v1',
|
|
32
94
|
user: { id: 'user_1', email: 'user@example.com', name: 'User One' },
|
|
33
95
|
})
|
|
@@ -58,10 +120,161 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
58
120
|
name: 'Export PDF',
|
|
59
121
|
}))
|
|
60
122
|
await vi.waitFor(() => {
|
|
61
|
-
expect(shadow.querySelector('.mtb-
|
|
123
|
+
expect(shadow.querySelector('.mtb-clarify-summary')).not.toBeNull()
|
|
124
|
+
}, { timeout: 5000 })
|
|
125
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
126
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
127
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-clarify-send-feedback')!.click()
|
|
128
|
+
|
|
129
|
+
await vi.waitFor(() => {
|
|
130
|
+
expect(shadow.querySelector('.mtb-success-title')?.textContent).toBe('Sent — thanks!')
|
|
62
131
|
}, { timeout: 5000 })
|
|
63
132
|
|
|
133
|
+
expect(shadow.querySelector('.mtb-success-msg')?.textContent).toBe(
|
|
134
|
+
'Your note and captured technical context are on their way to the team. You’ll hear back when it’s resolved.'
|
|
135
|
+
)
|
|
64
136
|
expect(shadow.querySelector('.mtb-toolbar')).toBeNull()
|
|
137
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('abandons the active Session on global Exit without finalizing Feedback', async () => {
|
|
141
|
+
const target = document.createElement('button')
|
|
142
|
+
target.id = 'export-btn'
|
|
143
|
+
document.body.appendChild(target)
|
|
144
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
145
|
+
|
|
146
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
147
|
+
const href = String(url)
|
|
148
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
149
|
+
if (href.endsWith('/clarification')) {
|
|
150
|
+
return new Response(JSON.stringify({
|
|
151
|
+
clarification: {
|
|
152
|
+
status: 'awaiting_response',
|
|
153
|
+
messages: [{ role: 'assistant', content: 'What were you trying to do?' }],
|
|
154
|
+
done: false,
|
|
155
|
+
},
|
|
156
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
157
|
+
}
|
|
158
|
+
return new Response(JSON.stringify({
|
|
159
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
160
|
+
}), { status: 201 })
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
164
|
+
|
|
165
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
166
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
167
|
+
tab.click()
|
|
168
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
169
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
170
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
171
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
172
|
+
textarea.value = 'Export is broken'
|
|
173
|
+
textarea.dispatchEvent(new Event('input'))
|
|
174
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
175
|
+
|
|
176
|
+
await vi.waitFor(() => {
|
|
177
|
+
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
178
|
+
})
|
|
179
|
+
tab.click()
|
|
180
|
+
|
|
181
|
+
await vi.waitFor(() => {
|
|
182
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
183
|
+
})
|
|
184
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('abandons a Session whose create response arrives after Exit', async () => {
|
|
188
|
+
const target = document.createElement('button')
|
|
189
|
+
target.id = 'export-btn'
|
|
190
|
+
document.body.appendChild(target)
|
|
191
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
192
|
+
|
|
193
|
+
let resolveCreate!: (response: Response) => void
|
|
194
|
+
const createResponse = new Promise<Response>(resolve => { resolveCreate = resolve })
|
|
195
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
196
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
197
|
+
if (String(url).endsWith('/feedback_submission_sessions')) return createResponse
|
|
198
|
+
throw new Error(`Unexpected request: ${String(url)}`)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
202
|
+
|
|
203
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
204
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
205
|
+
tab.click()
|
|
206
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
207
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
208
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
209
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
210
|
+
textarea.value = 'Export is broken'
|
|
211
|
+
textarea.dispatchEvent(new Event('input'))
|
|
212
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
213
|
+
|
|
214
|
+
await vi.waitFor(() => {
|
|
215
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback_submission_sessions'))).toBe(true)
|
|
216
|
+
})
|
|
217
|
+
tab.click()
|
|
218
|
+
resolveCreate(new Response(JSON.stringify({
|
|
219
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
220
|
+
}), { status: 201 }))
|
|
221
|
+
|
|
222
|
+
await vi.waitFor(() => {
|
|
223
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
224
|
+
})
|
|
225
|
+
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
226
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/clarification'))).toBe(false)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('does not show success when finalize completes after Exit', async () => {
|
|
230
|
+
const target = document.createElement('button')
|
|
231
|
+
target.id = 'export-btn'
|
|
232
|
+
document.body.appendChild(target)
|
|
233
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
234
|
+
|
|
235
|
+
let resolveFinalize!: (response: Response) => void
|
|
236
|
+
const finalizeResponse = new Promise<Response>(resolve => { resolveFinalize = resolve })
|
|
237
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
238
|
+
const href = String(url)
|
|
239
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
240
|
+
if (href.endsWith('/feedback')) return finalizeResponse
|
|
241
|
+
if (href.endsWith('/clarification')) {
|
|
242
|
+
return new Response(JSON.stringify({
|
|
243
|
+
clarification: { status: 'completed', messages: [], done: true },
|
|
244
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
245
|
+
}
|
|
246
|
+
return new Response(JSON.stringify({
|
|
247
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
248
|
+
}), { status: 201 })
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
MakeThisBetter.init({ projectKey: 'proj_test', apiUrl: 'https://api.example.com/api/v1' })
|
|
252
|
+
|
|
253
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
254
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
255
|
+
tab.click()
|
|
256
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
257
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
258
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
259
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
260
|
+
textarea.value = 'Export is broken'
|
|
261
|
+
textarea.dispatchEvent(new Event('input'))
|
|
262
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
263
|
+
await confirmSubmission(shadow)
|
|
264
|
+
|
|
265
|
+
await vi.waitFor(() => {
|
|
266
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
267
|
+
})
|
|
268
|
+
tab.click()
|
|
269
|
+
resolveFinalize(new Response(JSON.stringify({
|
|
270
|
+
feedback: { id: 'FB-1', status: 'received', project_id: 'acme' },
|
|
271
|
+
}), { status: 201 }))
|
|
272
|
+
|
|
273
|
+
await vi.waitFor(() => {
|
|
274
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
275
|
+
})
|
|
276
|
+
expect(shadow.querySelector('.mtb-success')).toBeNull()
|
|
277
|
+
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
65
278
|
})
|
|
66
279
|
|
|
67
280
|
it('submits anonymous feedback with a persistent anon_ reporter id', async () => {
|
|
@@ -72,13 +285,13 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
72
285
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
73
286
|
|
|
74
287
|
let capturedBody: FormData | null = null
|
|
75
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
288
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
76
289
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
77
|
-
return
|
|
290
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
78
291
|
})
|
|
79
292
|
|
|
80
293
|
MakeThisBetter.init({
|
|
81
|
-
projectKey: '
|
|
294
|
+
projectKey: 'acme',
|
|
82
295
|
apiUrl: 'https://api.example.com/api/v1',
|
|
83
296
|
})
|
|
84
297
|
|
|
@@ -110,19 +323,18 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
110
323
|
document.body.appendChild(target)
|
|
111
324
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
112
325
|
|
|
113
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
114
|
-
return
|
|
115
|
-
id: '
|
|
116
|
-
status: '
|
|
117
|
-
project_id: '
|
|
118
|
-
ai_clarify_available: false,
|
|
326
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
327
|
+
return sessionFlowResponse(url, init, {
|
|
328
|
+
id: 'FB-1',
|
|
329
|
+
status: 'received',
|
|
330
|
+
project_id: 'acme',
|
|
119
331
|
board_url: 'https://acme.example.com',
|
|
120
332
|
identity_token: 'tok_anon',
|
|
121
|
-
})
|
|
333
|
+
})
|
|
122
334
|
})
|
|
123
335
|
|
|
124
336
|
MakeThisBetter.init({
|
|
125
|
-
projectKey: '
|
|
337
|
+
projectKey: 'acme',
|
|
126
338
|
apiUrl: 'https://api.example.com/api/v1',
|
|
127
339
|
})
|
|
128
340
|
|
|
@@ -135,6 +347,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
135
347
|
textarea.value = 'Anonymous feedback'
|
|
136
348
|
textarea.dispatchEvent(new Event('input'))
|
|
137
349
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
350
|
+
await confirmSubmission(shadow)
|
|
138
351
|
|
|
139
352
|
await vi.waitFor(() => {
|
|
140
353
|
expect(shadow.querySelector('.mtb-view-feedback-link')).not.toBeNull()
|
|
@@ -153,12 +366,12 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
153
366
|
document.body.appendChild(target)
|
|
154
367
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
155
368
|
|
|
156
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
157
|
-
return
|
|
369
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
370
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
158
371
|
})
|
|
159
372
|
|
|
160
373
|
MakeThisBetter.init({
|
|
161
|
-
projectKey: '
|
|
374
|
+
projectKey: 'acme',
|
|
162
375
|
apiUrl: 'https://api.example.com/api/v1',
|
|
163
376
|
})
|
|
164
377
|
|
|
@@ -171,6 +384,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
171
384
|
textarea.value = 'Anonymous feedback'
|
|
172
385
|
textarea.dispatchEvent(new Event('input'))
|
|
173
386
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
387
|
+
await confirmSubmission(shadow)
|
|
174
388
|
|
|
175
389
|
await vi.waitFor(() => {
|
|
176
390
|
expect(shadow.querySelector('.mtb-success-title')).not.toBeNull()
|
|
@@ -192,18 +406,17 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
192
406
|
patchCalls.push({ url: String(url), init: init! })
|
|
193
407
|
return new Response(null, { status: 204 })
|
|
194
408
|
}
|
|
195
|
-
return
|
|
196
|
-
id: '
|
|
197
|
-
status: '
|
|
198
|
-
project_id: '
|
|
199
|
-
ai_clarify_available: false,
|
|
409
|
+
return sessionFlowResponse(url, init, {
|
|
410
|
+
id: 'FB-1',
|
|
411
|
+
status: 'received',
|
|
412
|
+
project_id: 'acme',
|
|
200
413
|
board_url: 'https://acme.example.com',
|
|
201
414
|
identity_token: 'tok_anon',
|
|
202
|
-
})
|
|
415
|
+
})
|
|
203
416
|
})
|
|
204
417
|
|
|
205
418
|
MakeThisBetter.init({
|
|
206
|
-
projectKey: '
|
|
419
|
+
projectKey: 'acme',
|
|
207
420
|
apiUrl: 'https://api.example.com/api/v1',
|
|
208
421
|
})
|
|
209
422
|
|
|
@@ -216,6 +429,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
216
429
|
textarea.value = 'Anonymous feedback'
|
|
217
430
|
textarea.dispatchEvent(new Event('input'))
|
|
218
431
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
432
|
+
await confirmSubmission(shadow)
|
|
219
433
|
|
|
220
434
|
await vi.waitFor(() => {
|
|
221
435
|
expect(shadow.querySelector('.mtb-email-input')).not.toBeNull()
|
|
@@ -229,7 +443,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
229
443
|
expect(patchCalls.length).toBe(1)
|
|
230
444
|
})
|
|
231
445
|
|
|
232
|
-
expect(patchCalls[0].url).toBe('https://api.example.com/api/v1/widget/feedbacks/
|
|
446
|
+
expect(patchCalls[0].url).toBe('https://api.example.com/api/v1/widget/feedbacks/FB-1/reporter')
|
|
233
447
|
const headers = patchCalls[0].init.headers as Record<string, string>
|
|
234
448
|
expect(headers['X-Identity-Token']).toBe('tok_anon')
|
|
235
449
|
expect(JSON.parse(String(patchCalls[0].init.body))).toEqual({ reporter: { email: 'anon@example.com' } })
|
|
@@ -248,20 +462,19 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
248
462
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
249
463
|
|
|
250
464
|
let capturedBody: FormData | null = null
|
|
251
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
465
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
252
466
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
253
|
-
return
|
|
254
|
-
id: '
|
|
255
|
-
status: '
|
|
256
|
-
project_id: '
|
|
257
|
-
ai_clarify_available: false,
|
|
467
|
+
return sessionFlowResponse(url, init, {
|
|
468
|
+
id: 'FB-2',
|
|
469
|
+
status: 'received',
|
|
470
|
+
project_id: 'acme',
|
|
258
471
|
board_url: 'https://acme.example.com',
|
|
259
472
|
identity_token: 'tok_anon',
|
|
260
|
-
})
|
|
473
|
+
})
|
|
261
474
|
})
|
|
262
475
|
|
|
263
476
|
MakeThisBetter.init({
|
|
264
|
-
projectKey: '
|
|
477
|
+
projectKey: 'acme',
|
|
265
478
|
apiUrl: 'https://api.example.com/api/v1',
|
|
266
479
|
})
|
|
267
480
|
|
|
@@ -274,6 +487,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
274
487
|
textarea.value = 'Second feedback'
|
|
275
488
|
textarea.dispatchEvent(new Event('input'))
|
|
276
489
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
490
|
+
await confirmSubmission(shadow)
|
|
277
491
|
|
|
278
492
|
await vi.waitFor(() => {
|
|
279
493
|
expect(shadow.querySelector('.mtb-success-title')).not.toBeNull()
|
|
@@ -302,7 +516,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
302
516
|
})
|
|
303
517
|
|
|
304
518
|
MakeThisBetter.init({
|
|
305
|
-
projectKey: '
|
|
519
|
+
projectKey: 'acme',
|
|
306
520
|
apiUrl: 'https://api.example.com/api/v1',
|
|
307
521
|
})
|
|
308
522
|
|
|
@@ -333,7 +547,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
333
547
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
334
548
|
|
|
335
549
|
MakeThisBetter.init({
|
|
336
|
-
projectKey: '
|
|
550
|
+
projectKey: 'acme',
|
|
337
551
|
apiUrl: 'https://api.example.com/api/v1',
|
|
338
552
|
})
|
|
339
553
|
|
|
@@ -355,7 +569,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
355
569
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
356
570
|
|
|
357
571
|
MakeThisBetter.init({
|
|
358
|
-
projectKey: '
|
|
572
|
+
projectKey: 'acme',
|
|
359
573
|
apiUrl: 'https://api.example.com/api/v1',
|
|
360
574
|
user: { id: 'user_1' },
|
|
361
575
|
})
|
|
@@ -379,13 +593,13 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
379
593
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
380
594
|
|
|
381
595
|
let capturedBody: FormData | null = null
|
|
382
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
596
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
383
597
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
384
|
-
return
|
|
598
|
+
return sessionFlowResponse(url, init, { id: 'FB-3', status: 'received', project_id: 'acme' })
|
|
385
599
|
})
|
|
386
600
|
|
|
387
601
|
MakeThisBetter.init({
|
|
388
|
-
projectKey: '
|
|
602
|
+
projectKey: 'acme',
|
|
389
603
|
apiUrl: 'https://api.example.com/api/v1',
|
|
390
604
|
user: { id: 'user_1', email: 'host@example.com' },
|
|
391
605
|
})
|
|
@@ -424,19 +638,19 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
424
638
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
425
639
|
|
|
426
640
|
let capturedBody: FormData | null = null
|
|
427
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
641
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
428
642
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
429
|
-
return
|
|
643
|
+
return sessionFlowResponse(url, init, { id: 'FB-4', status: 'received', project_id: 'acme' })
|
|
430
644
|
})
|
|
431
645
|
|
|
432
646
|
MakeThisBetter.init({
|
|
433
|
-
projectKey: '
|
|
647
|
+
projectKey: 'acme',
|
|
434
648
|
apiUrl: 'https://api.example.com/api/v1',
|
|
435
649
|
user: { id: 'user_1' },
|
|
436
650
|
})
|
|
437
651
|
MakeThisBetter.destroy()
|
|
438
652
|
MakeThisBetter.init({
|
|
439
|
-
projectKey: '
|
|
653
|
+
projectKey: 'acme',
|
|
440
654
|
apiUrl: 'https://api.example.com/api/v1',
|
|
441
655
|
})
|
|
442
656
|
|
|
@@ -466,18 +680,17 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
466
680
|
document.body.appendChild(target)
|
|
467
681
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
468
682
|
|
|
469
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
470
|
-
return
|
|
471
|
-
id: '
|
|
472
|
-
status: '
|
|
473
|
-
project_id: '
|
|
474
|
-
ai_clarify_available: false,
|
|
683
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
684
|
+
return sessionFlowResponse(url, init, {
|
|
685
|
+
id: 'FB-1',
|
|
686
|
+
status: 'received',
|
|
687
|
+
project_id: 'acme',
|
|
475
688
|
board_url: 'https://acme.example.com',
|
|
476
|
-
})
|
|
689
|
+
})
|
|
477
690
|
})
|
|
478
691
|
|
|
479
692
|
MakeThisBetter.init({
|
|
480
|
-
projectKey: '
|
|
693
|
+
projectKey: 'acme',
|
|
481
694
|
apiUrl: 'https://api.example.com/api/v1',
|
|
482
695
|
user: { id: 'user_1' },
|
|
483
696
|
userToken: 'host.signed.jwt',
|
|
@@ -492,6 +705,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
492
705
|
textarea.value = 'Host feedback'
|
|
493
706
|
textarea.dispatchEvent(new Event('input'))
|
|
494
707
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
708
|
+
await confirmSubmission(shadow)
|
|
495
709
|
|
|
496
710
|
await vi.waitFor(() => {
|
|
497
711
|
expect(shadow.querySelector('.mtb-view-feedback-link')).not.toBeNull()
|
|
@@ -504,7 +718,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
504
718
|
})
|
|
505
719
|
})
|
|
506
720
|
|
|
507
|
-
it('
|
|
721
|
+
it('requires Send feedback confirmation when AI clarification is unavailable', async () => {
|
|
508
722
|
const target = document.createElement('button')
|
|
509
723
|
target.id = 'export-btn'
|
|
510
724
|
target.textContent = 'Export PDF'
|
|
@@ -512,12 +726,12 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
512
726
|
|
|
513
727
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
514
728
|
|
|
515
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
516
|
-
return
|
|
729
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
730
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
517
731
|
})
|
|
518
732
|
|
|
519
733
|
MakeThisBetter.init({
|
|
520
|
-
projectKey: '
|
|
734
|
+
projectKey: 'acme',
|
|
521
735
|
apiUrl: 'https://api.example.com/api/v1',
|
|
522
736
|
})
|
|
523
737
|
|
|
@@ -534,14 +748,75 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
534
748
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
535
749
|
|
|
536
750
|
await vi.waitFor(() => {
|
|
537
|
-
expect(shadow.querySelector('.mtb-
|
|
751
|
+
expect(shadow.querySelector('.mtb-clarify-summary')).not.toBeNull()
|
|
538
752
|
}, { timeout: 5000 })
|
|
753
|
+
expect(shadow.querySelector('.mtb-success-title')).toBeNull()
|
|
754
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
755
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-clarify-send-feedback')!.click()
|
|
756
|
+
|
|
757
|
+
await vi.waitFor(() => {
|
|
758
|
+
expect(shadow.querySelector('.mtb-success-title')?.textContent).toBe("Thanks! We've received your feedback.")
|
|
759
|
+
})
|
|
539
760
|
|
|
540
761
|
expect(shadow.querySelector('.mtb-success-msg')?.textContent).toBe(
|
|
541
|
-
"
|
|
762
|
+
"The team will take it from here. You'll hear back when it's resolved."
|
|
542
763
|
)
|
|
543
764
|
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
544
|
-
expect(fetchSpy).
|
|
765
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
it('never leaves an orphaned dim scrim when a pin popup is followed by a recording popup', async () => {
|
|
769
|
+
const target = document.createElement('button')
|
|
770
|
+
target.id = 'export-btn'
|
|
771
|
+
target.textContent = 'Export PDF'
|
|
772
|
+
document.body.appendChild(target)
|
|
773
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
774
|
+
|
|
775
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
776
|
+
|
|
777
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
778
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
779
|
+
|
|
780
|
+
// Open a pin popup — this creates the first dim scrim.
|
|
781
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
782
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
783
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
784
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(1)
|
|
785
|
+
|
|
786
|
+
// Switch to Record while the popup is still open.
|
|
787
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!.click()
|
|
788
|
+
|
|
789
|
+
// Stop the recording — this opens the recording popup.
|
|
790
|
+
await vi.waitFor(() => {
|
|
791
|
+
expect(shadow.querySelector('.mtb-record-stop')).not.toBeNull()
|
|
792
|
+
})
|
|
793
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-record-stop')!.click()
|
|
794
|
+
|
|
795
|
+
await vi.waitFor(() => {
|
|
796
|
+
expect(shadow.querySelector('.mtb-popup')).not.toBeNull()
|
|
797
|
+
})
|
|
798
|
+
|
|
799
|
+
// Exactly one dim scrim must remain — the first one is not orphaned.
|
|
800
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(1)
|
|
801
|
+
|
|
802
|
+
// Dismissing the widget clears every scrim, keeping the host page interactive.
|
|
803
|
+
shadow.querySelector<HTMLDivElement>('.mtb-dim')!.click()
|
|
804
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(0)
|
|
805
|
+
})
|
|
806
|
+
|
|
807
|
+
it('keeps one recording session when Replay is clicked twice', async () => {
|
|
808
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
809
|
+
|
|
810
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
811
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
812
|
+
const replay = shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!
|
|
813
|
+
|
|
814
|
+
replay.click()
|
|
815
|
+
replay.click()
|
|
816
|
+
|
|
817
|
+
await vi.waitFor(() => {
|
|
818
|
+
expect(shadow.querySelectorAll('.mtb-record-bar')).toHaveLength(1)
|
|
819
|
+
})
|
|
545
820
|
})
|
|
546
821
|
|
|
547
822
|
it('does not start a new feedback while the current one is being clarified', async () => {
|
|
@@ -553,17 +828,21 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
553
828
|
|
|
554
829
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
555
830
|
const href = typeof url === 'string' ? url : url.toString()
|
|
556
|
-
if (href.includes('/
|
|
831
|
+
if (href.includes('/clarification')) {
|
|
557
832
|
// Keep the conversation open (done:false) so the card stays mounted.
|
|
558
833
|
return new Response(
|
|
559
|
-
JSON.stringify({
|
|
834
|
+
JSON.stringify({
|
|
835
|
+
clarification: { status: 'active', messages: [{ role: 'assistant', content: 'What broke?' }], done: false },
|
|
836
|
+
}),
|
|
560
837
|
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
|
561
838
|
)
|
|
562
839
|
}
|
|
563
|
-
return new Response(JSON.stringify({
|
|
840
|
+
return new Response(JSON.stringify({
|
|
841
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
842
|
+
}), { status: 201 })
|
|
564
843
|
})
|
|
565
844
|
|
|
566
|
-
MakeThisBetter.init({ projectKey: '
|
|
845
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
567
846
|
|
|
568
847
|
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
569
848
|
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
@@ -582,10 +861,142 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
582
861
|
await vi.waitFor(() => {
|
|
583
862
|
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
584
863
|
}, { timeout: 5000 })
|
|
864
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
865
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!.click()
|
|
866
|
+
expect(shadow.querySelector('.mtb-record-bar')).toBeNull()
|
|
585
867
|
|
|
586
868
|
// Clicking the tab now must NOT open a fresh annotation session.
|
|
587
869
|
tab.click()
|
|
588
870
|
expect(shadow.querySelector('.mtb-overlay')).toBeNull()
|
|
589
871
|
expect(shadow.querySelector('.mtb-toolbar')).toBeNull()
|
|
590
872
|
})
|
|
873
|
+
|
|
874
|
+
describe('Escape key', () => {
|
|
875
|
+
it('does nothing while idle', () => {
|
|
876
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
877
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
878
|
+
|
|
879
|
+
expect(() => pressEscape()).not.toThrow()
|
|
880
|
+
expect(shadow.querySelector('.mtb-toolbar')).toBeNull()
|
|
881
|
+
})
|
|
882
|
+
|
|
883
|
+
it('exits annotation mode back to idle', () => {
|
|
884
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
885
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
886
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
887
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
888
|
+
|
|
889
|
+
pressEscape()
|
|
890
|
+
|
|
891
|
+
expect(shadow.querySelector('.mtb-toolbar')).toBeNull()
|
|
892
|
+
expect(shadow.querySelector('.mtb-overlay')).toBeNull()
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
it('cancels an in-progress drawing back to annotation mode, keeping the toolbar', async () => {
|
|
896
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
897
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
898
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
899
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
900
|
+
performDrawStroke(overlay)
|
|
901
|
+
|
|
902
|
+
await vi.waitFor(() => {
|
|
903
|
+
expect(shadow.querySelector('.mtb-draw-bar')).not.toBeNull()
|
|
904
|
+
})
|
|
905
|
+
|
|
906
|
+
pressEscape()
|
|
907
|
+
|
|
908
|
+
expect(shadow.querySelector('.mtb-draw-bar')).toBeNull()
|
|
909
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
910
|
+
})
|
|
911
|
+
|
|
912
|
+
it('exits an open comment popup back to idle', () => {
|
|
913
|
+
const target = document.createElement('button')
|
|
914
|
+
target.id = 'export-btn'
|
|
915
|
+
document.body.appendChild(target)
|
|
916
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
917
|
+
|
|
918
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
919
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
920
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
921
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
922
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
923
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
924
|
+
expect(shadow.querySelector('.mtb-popup')).not.toBeNull()
|
|
925
|
+
|
|
926
|
+
pressEscape()
|
|
927
|
+
|
|
928
|
+
expect(shadow.querySelector('.mtb-popup')).toBeNull()
|
|
929
|
+
expect(shadow.querySelector('.mtb-dim')).toBeNull()
|
|
930
|
+
})
|
|
931
|
+
|
|
932
|
+
it('stops an active recording, same as clicking Stop', async () => {
|
|
933
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
934
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
935
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
936
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!.click()
|
|
937
|
+
|
|
938
|
+
await vi.waitFor(() => {
|
|
939
|
+
expect(shadow.querySelector('.mtb-record-bar')).not.toBeNull()
|
|
940
|
+
})
|
|
941
|
+
|
|
942
|
+
pressEscape()
|
|
943
|
+
|
|
944
|
+
expect(shadow.querySelector('.mtb-record-bar')).toBeNull()
|
|
945
|
+
await vi.waitFor(() => {
|
|
946
|
+
expect(shadow.querySelector('.mtb-popup')).not.toBeNull()
|
|
947
|
+
})
|
|
948
|
+
})
|
|
949
|
+
|
|
950
|
+
it('does nothing while a clarification conversation is open', async () => {
|
|
951
|
+
const target = document.createElement('button')
|
|
952
|
+
target.id = 'export-btn'
|
|
953
|
+
document.body.appendChild(target)
|
|
954
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
955
|
+
|
|
956
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
957
|
+
const href = String(url)
|
|
958
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
959
|
+
if (href.endsWith('/clarification')) {
|
|
960
|
+
return new Response(JSON.stringify({
|
|
961
|
+
clarification: { status: 'active', messages: [{ role: 'assistant', content: 'What broke?' }], done: false },
|
|
962
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
963
|
+
}
|
|
964
|
+
return new Response(JSON.stringify({
|
|
965
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
966
|
+
}), { status: 201 })
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
970
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
971
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
972
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
973
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
974
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
975
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
976
|
+
textarea.value = 'Export is broken'
|
|
977
|
+
textarea.dispatchEvent(new Event('input'))
|
|
978
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
979
|
+
|
|
980
|
+
await vi.waitFor(() => {
|
|
981
|
+
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
982
|
+
}, { timeout: 5000 })
|
|
983
|
+
|
|
984
|
+
// Snapshot before Escape: an unrelated prior test's fire-and-forget abandon
|
|
985
|
+
// call can still land on this shared fetch spy, so only the delta from
|
|
986
|
+
// pressing Escape (not the running total) tells us whether it acted.
|
|
987
|
+
const deleteCallsBefore = fetchSpy.mock.calls.filter(([, init]) => init?.method === 'DELETE').length
|
|
988
|
+
|
|
989
|
+
pressEscape()
|
|
990
|
+
|
|
991
|
+
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
992
|
+
expect(fetchSpy.mock.calls.filter(([, init]) => init?.method === 'DELETE').length).toBe(deleteCallsBefore)
|
|
993
|
+
})
|
|
994
|
+
|
|
995
|
+
it('stops listening after destroy', () => {
|
|
996
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
997
|
+
MakeThisBetter.destroy()
|
|
998
|
+
|
|
999
|
+
expect(() => pressEscape()).not.toThrow()
|
|
1000
|
+
})
|
|
1001
|
+
})
|
|
591
1002
|
})
|