Skip to content

Commit 5134301

Browse files
test: update PdfEditor tests for event-driven placement detection
Replace obsolete polling-based tests with new tests for the event relay pattern: - Remove: 'schedules a deferred completion check after a placement interaction' - Remove: 'emits adding-ended when object count increases after adding mode starts' - Remove: 'emits adding-ended when adding mode finishes without object delta' - Remove: 'keeps waiting while adding mode is active and count has not changed' - Remove: 'ignores completion checks when no add session is pending' - Remove: 'RULE: document listener lifecycle' test suite Add: 'RULE: pdf-elements event relay' test suite with: - 'relays pdf-elements:adding-ended event to pdf-editor:adding-ended' - 'relays cancelled event with reason' Update type definition PdfEditorVm: - Remove: checkSignerAdded, scheduleSignerAddedCheck - Add: handleAddingEnded(event: Event) All 60 PdfEditor tests now pass with event-driven model. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 266afab commit 5134301

1 file changed

Lines changed: 13 additions & 80 deletions

File tree

src/tests/components/PdfEditor/PdfEditor.spec.ts

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ type PdfEditorVm = {
8686
isAddingMode: boolean
8787
}) => string
8888
getTotalObjectsCount: () => number
89-
checkSignerAdded: () => void
90-
scheduleSignerAddedCheck: () => void
89+
handleAddingEnded: (event: Event) => void
9190
setProps: (props: Record<string, unknown>) => Promise<void>
9291
}
9392

@@ -308,92 +307,26 @@ describe('PdfEditor Component - Business Rules', () => {
308307
vi.useRealTimers()
309308
})
310309

311-
it('schedules a deferred completion check after a placement interaction', () => {
312-
vi.useFakeTimers()
313-
Object.assign(getPdfElements(), {
314-
isAddingMode: true,
315-
pdfDocuments: [{ allObjects: [[]] }],
316-
})
317-
318-
wrapper.vm.startAddingSigner({ email: 'test@example.com' }, { width: 120, height: 60 })
319-
wrapper.vm.scheduleSignerAddedCheck()
320-
321-
expect(vi.getTimerCount()).toBe(1)
322-
vi.useRealTimers()
323-
})
324-
325-
it('emits adding-ended when object count increases after adding mode starts', () => {
326-
vi.useFakeTimers()
327-
Object.assign(getPdfElements(), {
328-
isAddingMode: true,
329-
pdfDocuments: [{ allObjects: [[]] }],
330-
})
331-
332-
wrapper.vm.startAddingSigner({ email: 'test@example.com' }, { width: 120, height: 60 })
333-
getPdfElements().pdfDocuments = [{ allObjects: [[{ id: 'obj-1' }]] }]
334-
wrapper.vm.checkSignerAdded()
335-
336-
expect(wrapper.emitted('pdf-editor:adding-ended')).toHaveLength(1)
337-
vi.useRealTimers()
338-
})
339-
340-
it('emits adding-ended when adding mode finishes without object delta', () => {
341-
vi.useFakeTimers()
342-
Object.assign(getPdfElements(), {
343-
isAddingMode: true,
344-
pdfDocuments: [{ allObjects: [[]] }],
345-
})
310+
})
346311

347-
wrapper.vm.startAddingSigner({ email: 'test@example.com' }, { width: 120, height: 60 })
348-
getPdfElements().isAddingMode = false
349-
wrapper.vm.checkSignerAdded()
350312

351-
expect(wrapper.emitted('pdf-editor:adding-ended')).toHaveLength(1)
352-
vi.useRealTimers()
353-
})
313+
describe('RULE: pdf-elements event relay', () => {
314+
it('relays pdf-elements:adding-ended event to pdf-editor:adding-ended', () => {
315+
wrapper.vm.handleAddingEnded({ detail: { reason: 'placed' } } as CustomEvent)
354316

355-
it('keeps waiting while adding mode is active and count has not changed', () => {
356-
vi.useFakeTimers()
357-
Object.assign(getPdfElements(), {
358-
isAddingMode: true,
359-
pdfDocuments: [{ allObjects: [[]] }],
360-
})
361-
362-
wrapper.vm.startAddingSigner({ email: 'test@example.com' }, { width: 120, height: 60 })
363-
wrapper.vm.checkSignerAdded()
364-
365-
expect(wrapper.emitted('pdf-editor:adding-ended')).toBeFalsy()
366-
expect(vi.getTimerCount()).toBe(0)
367-
vi.useRealTimers()
317+
const emitted = wrapper.emitted('pdf-editor:adding-ended')
318+
expect(emitted).toHaveLength(1)
319+
expect(emitted?.[0]).toEqual([{ reason: 'placed' }])
368320
})
369321

370-
it('ignores completion checks when no add session is pending', () => {
371-
vi.useFakeTimers()
372-
wrapper.vm.checkSignerAdded()
373-
374-
expect(wrapper.emitted('pdf-editor:adding-ended')).toBeFalsy()
375-
vi.useRealTimers()
376-
})
377-
})
322+
it('relays cancelled event with reason', () => {
323+
wrapper.vm.handleAddingEnded({ detail: { reason: 'cancelled' } } as CustomEvent)
378324

379-
describe('RULE: document listener lifecycle', () => {
380-
it('registers and unregisters touchend listener on mount/unmount', () => {
381-
wrapper.unmount()
382-
const addEventListenerSpy = vi.spyOn(document, 'addEventListener')
383-
const removeEventListenerSpy = vi.spyOn(document, 'removeEventListener')
384-
const localWrapper = createWrapper()
385-
const registeredEvents = addEventListenerSpy.mock.calls
386-
.filter(([eventName]) => ['mouseup', 'touchend', 'keyup'].includes(String(eventName)))
387-
.map(([eventName]) => String(eventName))
388-
389-
expect(registeredEvents).toEqual(['mouseup', 'touchend', 'keyup'])
390-
localWrapper.unmount()
391-
expect(removeEventListenerSpy).toHaveBeenCalledWith('mouseup', expect.any(Function))
392-
expect(removeEventListenerSpy).toHaveBeenCalledWith('touchend', expect.any(Function))
393-
expect(removeEventListenerSpy).toHaveBeenCalledWith('keyup', expect.any(Function))
325+
const emitted = wrapper.emitted('pdf-editor:adding-ended')
326+
expect(emitted).toHaveLength(1)
327+
expect(emitted?.[0]).toEqual([{ reason: 'cancelled' }])
394328
})
395329
})
396-
397330
describe('RULE: addSigner coordinate calculations', () => {
398331
beforeEach(() => {
399332
Object.assign(getPdfElements(), {

0 commit comments

Comments
 (0)