makethisbetter 1.5.3 → 1.6.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 +51 -26
- package/dist/makethisbetter.cjs.map +1 -1
- package/dist/makethisbetter.esm.js +1124 -591
- package/dist/makethisbetter.esm.js.map +1 -1
- package/dist/makethisbetter.js +50 -25
- 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 +16 -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 +2 -2
- 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 +143 -43
- package/src/popup/clarify.ts +160 -46
- 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 +335 -65
- package/src/widget/controller.ts +187 -35
- 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
- package/dist/index.d.cts +0 -8
- package/dist/index.d.mts +0 -8
|
@@ -2,9 +2,46 @@ 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
|
+
|
|
8
45
|
describe('MakeThisBetter widget flow', () => {
|
|
9
46
|
afterEach(() => {
|
|
10
47
|
MakeThisBetter.destroy()
|
|
@@ -12,7 +49,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
12
49
|
document.body.innerHTML = ''
|
|
13
50
|
})
|
|
14
51
|
|
|
15
|
-
it('
|
|
52
|
+
it('creates a Session on Submit and finalizes Feedback only after Send feedback', async () => {
|
|
16
53
|
const target = document.createElement('button')
|
|
17
54
|
target.id = 'export-btn'
|
|
18
55
|
target.textContent = 'Export PDF'
|
|
@@ -21,13 +58,26 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
21
58
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
22
59
|
|
|
23
60
|
let capturedBody: FormData | null = null
|
|
24
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
61
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
62
|
+
const href = String(url)
|
|
63
|
+
if (href.endsWith('/feedback')) {
|
|
64
|
+
return new Response(JSON.stringify({
|
|
65
|
+
feedback: { id: 'FB-1', status: 'received', project_id: 'acme' },
|
|
66
|
+
}), { status: 201 })
|
|
67
|
+
}
|
|
68
|
+
if (href.endsWith('/clarification')) {
|
|
69
|
+
return new Response(JSON.stringify({
|
|
70
|
+
clarification: { status: 'completed', messages: [], done: true },
|
|
71
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
72
|
+
}
|
|
25
73
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
26
|
-
return new Response(JSON.stringify({
|
|
74
|
+
return new Response(JSON.stringify({
|
|
75
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
76
|
+
}), { status: 201 })
|
|
27
77
|
})
|
|
28
78
|
|
|
29
79
|
MakeThisBetter.init({
|
|
30
|
-
projectKey: '
|
|
80
|
+
projectKey: 'acme',
|
|
31
81
|
apiUrl: 'https://api.example.com/api/v1',
|
|
32
82
|
user: { id: 'user_1', email: 'user@example.com', name: 'User One' },
|
|
33
83
|
})
|
|
@@ -58,10 +108,161 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
58
108
|
name: 'Export PDF',
|
|
59
109
|
}))
|
|
60
110
|
await vi.waitFor(() => {
|
|
61
|
-
expect(shadow.querySelector('.mtb-
|
|
111
|
+
expect(shadow.querySelector('.mtb-clarify-summary')).not.toBeNull()
|
|
112
|
+
}, { timeout: 5000 })
|
|
113
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
114
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
115
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-clarify-send-feedback')!.click()
|
|
116
|
+
|
|
117
|
+
await vi.waitFor(() => {
|
|
118
|
+
expect(shadow.querySelector('.mtb-success-title')?.textContent).toBe('Sent — thanks!')
|
|
62
119
|
}, { timeout: 5000 })
|
|
63
120
|
|
|
121
|
+
expect(shadow.querySelector('.mtb-success-msg')?.textContent).toBe(
|
|
122
|
+
'Your note and captured technical context are on their way to the team. You’ll hear back when it’s resolved.'
|
|
123
|
+
)
|
|
64
124
|
expect(shadow.querySelector('.mtb-toolbar')).toBeNull()
|
|
125
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('abandons the active Session on global Exit without finalizing Feedback', async () => {
|
|
129
|
+
const target = document.createElement('button')
|
|
130
|
+
target.id = 'export-btn'
|
|
131
|
+
document.body.appendChild(target)
|
|
132
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
133
|
+
|
|
134
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
135
|
+
const href = String(url)
|
|
136
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
137
|
+
if (href.endsWith('/clarification')) {
|
|
138
|
+
return new Response(JSON.stringify({
|
|
139
|
+
clarification: {
|
|
140
|
+
status: 'awaiting_response',
|
|
141
|
+
messages: [{ role: 'assistant', content: 'What were you trying to do?' }],
|
|
142
|
+
done: false,
|
|
143
|
+
},
|
|
144
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
145
|
+
}
|
|
146
|
+
return new Response(JSON.stringify({
|
|
147
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
148
|
+
}), { status: 201 })
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
152
|
+
|
|
153
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
154
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
155
|
+
tab.click()
|
|
156
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
157
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
158
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
159
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
160
|
+
textarea.value = 'Export is broken'
|
|
161
|
+
textarea.dispatchEvent(new Event('input'))
|
|
162
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
163
|
+
|
|
164
|
+
await vi.waitFor(() => {
|
|
165
|
+
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
166
|
+
})
|
|
167
|
+
tab.click()
|
|
168
|
+
|
|
169
|
+
await vi.waitFor(() => {
|
|
170
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
171
|
+
})
|
|
172
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('abandons a Session whose create response arrives after Exit', async () => {
|
|
176
|
+
const target = document.createElement('button')
|
|
177
|
+
target.id = 'export-btn'
|
|
178
|
+
document.body.appendChild(target)
|
|
179
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
180
|
+
|
|
181
|
+
let resolveCreate!: (response: Response) => void
|
|
182
|
+
const createResponse = new Promise<Response>(resolve => { resolveCreate = resolve })
|
|
183
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
184
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
185
|
+
if (String(url).endsWith('/feedback_submission_sessions')) return createResponse
|
|
186
|
+
throw new Error(`Unexpected request: ${String(url)}`)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
190
|
+
|
|
191
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
192
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
193
|
+
tab.click()
|
|
194
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
195
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
196
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
197
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
198
|
+
textarea.value = 'Export is broken'
|
|
199
|
+
textarea.dispatchEvent(new Event('input'))
|
|
200
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
201
|
+
|
|
202
|
+
await vi.waitFor(() => {
|
|
203
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback_submission_sessions'))).toBe(true)
|
|
204
|
+
})
|
|
205
|
+
tab.click()
|
|
206
|
+
resolveCreate(new Response(JSON.stringify({
|
|
207
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
208
|
+
}), { status: 201 }))
|
|
209
|
+
|
|
210
|
+
await vi.waitFor(() => {
|
|
211
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
212
|
+
})
|
|
213
|
+
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
214
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/clarification'))).toBe(false)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('does not show success when finalize completes after Exit', async () => {
|
|
218
|
+
const target = document.createElement('button')
|
|
219
|
+
target.id = 'export-btn'
|
|
220
|
+
document.body.appendChild(target)
|
|
221
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
222
|
+
|
|
223
|
+
let resolveFinalize!: (response: Response) => void
|
|
224
|
+
const finalizeResponse = new Promise<Response>(resolve => { resolveFinalize = resolve })
|
|
225
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
226
|
+
const href = String(url)
|
|
227
|
+
if (init?.method === 'DELETE') return new Response(null, { status: 204 })
|
|
228
|
+
if (href.endsWith('/feedback')) return finalizeResponse
|
|
229
|
+
if (href.endsWith('/clarification')) {
|
|
230
|
+
return new Response(JSON.stringify({
|
|
231
|
+
clarification: { status: 'completed', messages: [], done: true },
|
|
232
|
+
}), { status: 200, headers: { 'Content-Type': 'application/json' } })
|
|
233
|
+
}
|
|
234
|
+
return new Response(JSON.stringify({
|
|
235
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
236
|
+
}), { status: 201 })
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
MakeThisBetter.init({ projectKey: 'proj_test', apiUrl: 'https://api.example.com/api/v1' })
|
|
240
|
+
|
|
241
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
242
|
+
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
243
|
+
tab.click()
|
|
244
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
245
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
246
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
247
|
+
const textarea = shadow.querySelector<HTMLTextAreaElement>('.mtb-textarea')!
|
|
248
|
+
textarea.value = 'Export is broken'
|
|
249
|
+
textarea.dispatchEvent(new Event('input'))
|
|
250
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
251
|
+
await confirmSubmission(shadow)
|
|
252
|
+
|
|
253
|
+
await vi.waitFor(() => {
|
|
254
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
255
|
+
})
|
|
256
|
+
tab.click()
|
|
257
|
+
resolveFinalize(new Response(JSON.stringify({
|
|
258
|
+
feedback: { id: 'FB-1', status: 'received', project_id: 'acme' },
|
|
259
|
+
}), { status: 201 }))
|
|
260
|
+
|
|
261
|
+
await vi.waitFor(() => {
|
|
262
|
+
expect(fetchSpy.mock.calls.some(([, init]) => init?.method === 'DELETE')).toBe(true)
|
|
263
|
+
})
|
|
264
|
+
expect(shadow.querySelector('.mtb-success')).toBeNull()
|
|
265
|
+
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
65
266
|
})
|
|
66
267
|
|
|
67
268
|
it('submits anonymous feedback with a persistent anon_ reporter id', async () => {
|
|
@@ -72,13 +273,13 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
72
273
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
73
274
|
|
|
74
275
|
let capturedBody: FormData | null = null
|
|
75
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
276
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
76
277
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
77
|
-
return
|
|
278
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
78
279
|
})
|
|
79
280
|
|
|
80
281
|
MakeThisBetter.init({
|
|
81
|
-
projectKey: '
|
|
282
|
+
projectKey: 'acme',
|
|
82
283
|
apiUrl: 'https://api.example.com/api/v1',
|
|
83
284
|
})
|
|
84
285
|
|
|
@@ -110,19 +311,18 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
110
311
|
document.body.appendChild(target)
|
|
111
312
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
112
313
|
|
|
113
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
114
|
-
return
|
|
115
|
-
id: '
|
|
116
|
-
status: '
|
|
117
|
-
project_id: '
|
|
118
|
-
ai_clarify_available: false,
|
|
314
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
315
|
+
return sessionFlowResponse(url, init, {
|
|
316
|
+
id: 'FB-1',
|
|
317
|
+
status: 'received',
|
|
318
|
+
project_id: 'acme',
|
|
119
319
|
board_url: 'https://acme.example.com',
|
|
120
320
|
identity_token: 'tok_anon',
|
|
121
|
-
})
|
|
321
|
+
})
|
|
122
322
|
})
|
|
123
323
|
|
|
124
324
|
MakeThisBetter.init({
|
|
125
|
-
projectKey: '
|
|
325
|
+
projectKey: 'acme',
|
|
126
326
|
apiUrl: 'https://api.example.com/api/v1',
|
|
127
327
|
})
|
|
128
328
|
|
|
@@ -135,6 +335,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
135
335
|
textarea.value = 'Anonymous feedback'
|
|
136
336
|
textarea.dispatchEvent(new Event('input'))
|
|
137
337
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
338
|
+
await confirmSubmission(shadow)
|
|
138
339
|
|
|
139
340
|
await vi.waitFor(() => {
|
|
140
341
|
expect(shadow.querySelector('.mtb-view-feedback-link')).not.toBeNull()
|
|
@@ -153,12 +354,12 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
153
354
|
document.body.appendChild(target)
|
|
154
355
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
155
356
|
|
|
156
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
157
|
-
return
|
|
357
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
358
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
158
359
|
})
|
|
159
360
|
|
|
160
361
|
MakeThisBetter.init({
|
|
161
|
-
projectKey: '
|
|
362
|
+
projectKey: 'acme',
|
|
162
363
|
apiUrl: 'https://api.example.com/api/v1',
|
|
163
364
|
})
|
|
164
365
|
|
|
@@ -171,6 +372,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
171
372
|
textarea.value = 'Anonymous feedback'
|
|
172
373
|
textarea.dispatchEvent(new Event('input'))
|
|
173
374
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
375
|
+
await confirmSubmission(shadow)
|
|
174
376
|
|
|
175
377
|
await vi.waitFor(() => {
|
|
176
378
|
expect(shadow.querySelector('.mtb-success-title')).not.toBeNull()
|
|
@@ -192,18 +394,17 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
192
394
|
patchCalls.push({ url: String(url), init: init! })
|
|
193
395
|
return new Response(null, { status: 204 })
|
|
194
396
|
}
|
|
195
|
-
return
|
|
196
|
-
id: '
|
|
197
|
-
status: '
|
|
198
|
-
project_id: '
|
|
199
|
-
ai_clarify_available: false,
|
|
397
|
+
return sessionFlowResponse(url, init, {
|
|
398
|
+
id: 'FB-1',
|
|
399
|
+
status: 'received',
|
|
400
|
+
project_id: 'acme',
|
|
200
401
|
board_url: 'https://acme.example.com',
|
|
201
402
|
identity_token: 'tok_anon',
|
|
202
|
-
})
|
|
403
|
+
})
|
|
203
404
|
})
|
|
204
405
|
|
|
205
406
|
MakeThisBetter.init({
|
|
206
|
-
projectKey: '
|
|
407
|
+
projectKey: 'acme',
|
|
207
408
|
apiUrl: 'https://api.example.com/api/v1',
|
|
208
409
|
})
|
|
209
410
|
|
|
@@ -216,6 +417,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
216
417
|
textarea.value = 'Anonymous feedback'
|
|
217
418
|
textarea.dispatchEvent(new Event('input'))
|
|
218
419
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
420
|
+
await confirmSubmission(shadow)
|
|
219
421
|
|
|
220
422
|
await vi.waitFor(() => {
|
|
221
423
|
expect(shadow.querySelector('.mtb-email-input')).not.toBeNull()
|
|
@@ -229,7 +431,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
229
431
|
expect(patchCalls.length).toBe(1)
|
|
230
432
|
})
|
|
231
433
|
|
|
232
|
-
expect(patchCalls[0].url).toBe('https://api.example.com/api/v1/widget/feedbacks/
|
|
434
|
+
expect(patchCalls[0].url).toBe('https://api.example.com/api/v1/widget/feedbacks/FB-1/reporter')
|
|
233
435
|
const headers = patchCalls[0].init.headers as Record<string, string>
|
|
234
436
|
expect(headers['X-Identity-Token']).toBe('tok_anon')
|
|
235
437
|
expect(JSON.parse(String(patchCalls[0].init.body))).toEqual({ reporter: { email: 'anon@example.com' } })
|
|
@@ -248,20 +450,19 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
248
450
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
249
451
|
|
|
250
452
|
let capturedBody: FormData | null = null
|
|
251
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
453
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
252
454
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
253
|
-
return
|
|
254
|
-
id: '
|
|
255
|
-
status: '
|
|
256
|
-
project_id: '
|
|
257
|
-
ai_clarify_available: false,
|
|
455
|
+
return sessionFlowResponse(url, init, {
|
|
456
|
+
id: 'FB-2',
|
|
457
|
+
status: 'received',
|
|
458
|
+
project_id: 'acme',
|
|
258
459
|
board_url: 'https://acme.example.com',
|
|
259
460
|
identity_token: 'tok_anon',
|
|
260
|
-
})
|
|
461
|
+
})
|
|
261
462
|
})
|
|
262
463
|
|
|
263
464
|
MakeThisBetter.init({
|
|
264
|
-
projectKey: '
|
|
465
|
+
projectKey: 'acme',
|
|
265
466
|
apiUrl: 'https://api.example.com/api/v1',
|
|
266
467
|
})
|
|
267
468
|
|
|
@@ -274,6 +475,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
274
475
|
textarea.value = 'Second feedback'
|
|
275
476
|
textarea.dispatchEvent(new Event('input'))
|
|
276
477
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
478
|
+
await confirmSubmission(shadow)
|
|
277
479
|
|
|
278
480
|
await vi.waitFor(() => {
|
|
279
481
|
expect(shadow.querySelector('.mtb-success-title')).not.toBeNull()
|
|
@@ -302,7 +504,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
302
504
|
})
|
|
303
505
|
|
|
304
506
|
MakeThisBetter.init({
|
|
305
|
-
projectKey: '
|
|
507
|
+
projectKey: 'acme',
|
|
306
508
|
apiUrl: 'https://api.example.com/api/v1',
|
|
307
509
|
})
|
|
308
510
|
|
|
@@ -333,7 +535,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
333
535
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
334
536
|
|
|
335
537
|
MakeThisBetter.init({
|
|
336
|
-
projectKey: '
|
|
538
|
+
projectKey: 'acme',
|
|
337
539
|
apiUrl: 'https://api.example.com/api/v1',
|
|
338
540
|
})
|
|
339
541
|
|
|
@@ -355,7 +557,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
355
557
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
356
558
|
|
|
357
559
|
MakeThisBetter.init({
|
|
358
|
-
projectKey: '
|
|
560
|
+
projectKey: 'acme',
|
|
359
561
|
apiUrl: 'https://api.example.com/api/v1',
|
|
360
562
|
user: { id: 'user_1' },
|
|
361
563
|
})
|
|
@@ -379,13 +581,13 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
379
581
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
380
582
|
|
|
381
583
|
let capturedBody: FormData | null = null
|
|
382
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
584
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
383
585
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
384
|
-
return
|
|
586
|
+
return sessionFlowResponse(url, init, { id: 'FB-3', status: 'received', project_id: 'acme' })
|
|
385
587
|
})
|
|
386
588
|
|
|
387
589
|
MakeThisBetter.init({
|
|
388
|
-
projectKey: '
|
|
590
|
+
projectKey: 'acme',
|
|
389
591
|
apiUrl: 'https://api.example.com/api/v1',
|
|
390
592
|
user: { id: 'user_1', email: 'host@example.com' },
|
|
391
593
|
})
|
|
@@ -424,19 +626,19 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
424
626
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
425
627
|
|
|
426
628
|
let capturedBody: FormData | null = null
|
|
427
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async (
|
|
629
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
428
630
|
if (init?.body instanceof FormData) capturedBody = init.body
|
|
429
|
-
return
|
|
631
|
+
return sessionFlowResponse(url, init, { id: 'FB-4', status: 'received', project_id: 'acme' })
|
|
430
632
|
})
|
|
431
633
|
|
|
432
634
|
MakeThisBetter.init({
|
|
433
|
-
projectKey: '
|
|
635
|
+
projectKey: 'acme',
|
|
434
636
|
apiUrl: 'https://api.example.com/api/v1',
|
|
435
637
|
user: { id: 'user_1' },
|
|
436
638
|
})
|
|
437
639
|
MakeThisBetter.destroy()
|
|
438
640
|
MakeThisBetter.init({
|
|
439
|
-
projectKey: '
|
|
641
|
+
projectKey: 'acme',
|
|
440
642
|
apiUrl: 'https://api.example.com/api/v1',
|
|
441
643
|
})
|
|
442
644
|
|
|
@@ -466,18 +668,17 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
466
668
|
document.body.appendChild(target)
|
|
467
669
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
468
670
|
|
|
469
|
-
vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
470
|
-
return
|
|
471
|
-
id: '
|
|
472
|
-
status: '
|
|
473
|
-
project_id: '
|
|
474
|
-
ai_clarify_available: false,
|
|
671
|
+
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
672
|
+
return sessionFlowResponse(url, init, {
|
|
673
|
+
id: 'FB-1',
|
|
674
|
+
status: 'received',
|
|
675
|
+
project_id: 'acme',
|
|
475
676
|
board_url: 'https://acme.example.com',
|
|
476
|
-
})
|
|
677
|
+
})
|
|
477
678
|
})
|
|
478
679
|
|
|
479
680
|
MakeThisBetter.init({
|
|
480
|
-
projectKey: '
|
|
681
|
+
projectKey: 'acme',
|
|
481
682
|
apiUrl: 'https://api.example.com/api/v1',
|
|
482
683
|
user: { id: 'user_1' },
|
|
483
684
|
userToken: 'host.signed.jwt',
|
|
@@ -492,6 +693,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
492
693
|
textarea.value = 'Host feedback'
|
|
493
694
|
textarea.dispatchEvent(new Event('input'))
|
|
494
695
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
696
|
+
await confirmSubmission(shadow)
|
|
495
697
|
|
|
496
698
|
await vi.waitFor(() => {
|
|
497
699
|
expect(shadow.querySelector('.mtb-view-feedback-link')).not.toBeNull()
|
|
@@ -504,7 +706,7 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
504
706
|
})
|
|
505
707
|
})
|
|
506
708
|
|
|
507
|
-
it('
|
|
709
|
+
it('requires Send feedback confirmation when AI clarification is unavailable', async () => {
|
|
508
710
|
const target = document.createElement('button')
|
|
509
711
|
target.id = 'export-btn'
|
|
510
712
|
target.textContent = 'Export PDF'
|
|
@@ -512,12 +714,12 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
512
714
|
|
|
513
715
|
document.elementsFromPoint = vi.fn(() => [target])
|
|
514
716
|
|
|
515
|
-
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async () => {
|
|
516
|
-
return
|
|
717
|
+
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url, init) => {
|
|
718
|
+
return sessionFlowResponse(url, init, { id: 'FB-1', status: 'received', project_id: 'acme' })
|
|
517
719
|
})
|
|
518
720
|
|
|
519
721
|
MakeThisBetter.init({
|
|
520
|
-
projectKey: '
|
|
722
|
+
projectKey: 'acme',
|
|
521
723
|
apiUrl: 'https://api.example.com/api/v1',
|
|
522
724
|
})
|
|
523
725
|
|
|
@@ -534,14 +736,75 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
534
736
|
shadow.querySelector<HTMLButtonElement>('.mtb-submit-btn')!.click()
|
|
535
737
|
|
|
536
738
|
await vi.waitFor(() => {
|
|
537
|
-
expect(shadow.querySelector('.mtb-
|
|
739
|
+
expect(shadow.querySelector('.mtb-clarify-summary')).not.toBeNull()
|
|
538
740
|
}, { timeout: 5000 })
|
|
741
|
+
expect(shadow.querySelector('.mtb-success-title')).toBeNull()
|
|
742
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(false)
|
|
743
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-clarify-send-feedback')!.click()
|
|
744
|
+
|
|
745
|
+
await vi.waitFor(() => {
|
|
746
|
+
expect(shadow.querySelector('.mtb-success-title')?.textContent).toBe("Thanks! We've received your feedback.")
|
|
747
|
+
})
|
|
539
748
|
|
|
540
749
|
expect(shadow.querySelector('.mtb-success-msg')?.textContent).toBe(
|
|
541
|
-
"
|
|
750
|
+
"The team will take it from here. You'll hear back when it's resolved."
|
|
542
751
|
)
|
|
543
752
|
expect(shadow.querySelector('.mtb-clarify')).toBeNull()
|
|
544
|
-
expect(fetchSpy).
|
|
753
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).endsWith('/feedback'))).toBe(true)
|
|
754
|
+
})
|
|
755
|
+
|
|
756
|
+
it('never leaves an orphaned dim scrim when a pin popup is followed by a recording popup', async () => {
|
|
757
|
+
const target = document.createElement('button')
|
|
758
|
+
target.id = 'export-btn'
|
|
759
|
+
target.textContent = 'Export PDF'
|
|
760
|
+
document.body.appendChild(target)
|
|
761
|
+
document.elementsFromPoint = vi.fn(() => [target])
|
|
762
|
+
|
|
763
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
764
|
+
|
|
765
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
766
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
767
|
+
|
|
768
|
+
// Open a pin popup — this creates the first dim scrim.
|
|
769
|
+
const overlay = shadow.querySelector<HTMLDivElement>('.mtb-overlay')!
|
|
770
|
+
overlay.dispatchEvent(new MouseEvent('mousedown', { clientX: 20, clientY: 30, bubbles: true }))
|
|
771
|
+
overlay.dispatchEvent(new MouseEvent('mouseup', { clientX: 20, clientY: 30, bubbles: true }))
|
|
772
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(1)
|
|
773
|
+
|
|
774
|
+
// Switch to Record while the popup is still open.
|
|
775
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!.click()
|
|
776
|
+
|
|
777
|
+
// Stop the recording — this opens the recording popup.
|
|
778
|
+
await vi.waitFor(() => {
|
|
779
|
+
expect(shadow.querySelector('.mtb-record-stop')).not.toBeNull()
|
|
780
|
+
})
|
|
781
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-record-stop')!.click()
|
|
782
|
+
|
|
783
|
+
await vi.waitFor(() => {
|
|
784
|
+
expect(shadow.querySelector('.mtb-popup')).not.toBeNull()
|
|
785
|
+
})
|
|
786
|
+
|
|
787
|
+
// Exactly one dim scrim must remain — the first one is not orphaned.
|
|
788
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(1)
|
|
789
|
+
|
|
790
|
+
// Dismissing the widget clears every scrim, keeping the host page interactive.
|
|
791
|
+
shadow.querySelector<HTMLDivElement>('.mtb-dim')!.click()
|
|
792
|
+
expect(shadow.querySelectorAll('.mtb-dim').length).toBe(0)
|
|
793
|
+
})
|
|
794
|
+
|
|
795
|
+
it('keeps one recording session when Replay is clicked twice', async () => {
|
|
796
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
797
|
+
|
|
798
|
+
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
799
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-tab')!.click()
|
|
800
|
+
const replay = shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!
|
|
801
|
+
|
|
802
|
+
replay.click()
|
|
803
|
+
replay.click()
|
|
804
|
+
|
|
805
|
+
await vi.waitFor(() => {
|
|
806
|
+
expect(shadow.querySelectorAll('.mtb-record-bar')).toHaveLength(1)
|
|
807
|
+
})
|
|
545
808
|
})
|
|
546
809
|
|
|
547
810
|
it('does not start a new feedback while the current one is being clarified', async () => {
|
|
@@ -553,17 +816,21 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
553
816
|
|
|
554
817
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (url: RequestInfo | URL, init?: RequestInit) => {
|
|
555
818
|
const href = typeof url === 'string' ? url : url.toString()
|
|
556
|
-
if (href.includes('/
|
|
819
|
+
if (href.includes('/clarification')) {
|
|
557
820
|
// Keep the conversation open (done:false) so the card stays mounted.
|
|
558
821
|
return new Response(
|
|
559
|
-
JSON.stringify({
|
|
822
|
+
JSON.stringify({
|
|
823
|
+
clarification: { status: 'active', messages: [{ role: 'assistant', content: 'What broke?' }], done: false },
|
|
824
|
+
}),
|
|
560
825
|
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
|
561
826
|
)
|
|
562
827
|
}
|
|
563
|
-
return new Response(JSON.stringify({
|
|
828
|
+
return new Response(JSON.stringify({
|
|
829
|
+
submission_session: { id: 'submission_1', token: 'secret', ai_clarify_available: true },
|
|
830
|
+
}), { status: 201 })
|
|
564
831
|
})
|
|
565
832
|
|
|
566
|
-
MakeThisBetter.init({ projectKey: '
|
|
833
|
+
MakeThisBetter.init({ projectKey: 'acme', apiUrl: 'https://api.example.com/api/v1' })
|
|
567
834
|
|
|
568
835
|
const shadow = document.getElementById('mtb-widget-host')!.shadowRoot!
|
|
569
836
|
const tab = shadow.querySelector<HTMLButtonElement>('.mtb-tab')!
|
|
@@ -582,6 +849,9 @@ describe('MakeThisBetter widget flow', () => {
|
|
|
582
849
|
await vi.waitFor(() => {
|
|
583
850
|
expect(shadow.querySelector('.mtb-clarify')).not.toBeNull()
|
|
584
851
|
}, { timeout: 5000 })
|
|
852
|
+
expect(shadow.querySelector('.mtb-toolbar')).not.toBeNull()
|
|
853
|
+
shadow.querySelector<HTMLButtonElement>('.mtb-toolbar-mode-record')!.click()
|
|
854
|
+
expect(shadow.querySelector('.mtb-record-bar')).toBeNull()
|
|
585
855
|
|
|
586
856
|
// Clicking the tab now must NOT open a fresh annotation session.
|
|
587
857
|
tab.click()
|