Skip to content

Commit 2d8e4c9

Browse files
test: cover pdf editor worker ordering
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 8865548 commit 2d8e4c9

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { mount } from '@vue/test-utils'
88
import type { VueWrapper } from '@vue/test-utils'
99
import PdfEditor from '../../../components/PdfEditor/PdfEditor.vue'
1010

11+
const ensurePdfWorkerMock = vi.fn()
12+
const pdfElementsWorkerReadyStates: boolean[] = []
13+
let workerConfiguredBeforeMount = false
14+
1115
type SignerRecord = {
1216
displayName?: string
1317
email?: string
@@ -94,6 +98,7 @@ vi.mock('@libresign/pdf-elements', () => ({
9498
name: 'PDFElements',
9599
template: '<div class="pdf-elements-mock"></div>',
96100
setup(_props: unknown, { expose }: { expose: (methods: any) => void }) {
101+
pdfElementsWorkerReadyStates.push(workerConfiguredBeforeMount)
97102
const methods = {
98103
startAddingElement: vi.fn(),
99104
cancelAdding: vi.fn(),
@@ -112,7 +117,10 @@ vi.mock('@libresign/pdf-elements', () => ({
112117
}))
113118

114119
vi.mock('../../../helpers/pdfWorker.js', () => ({
115-
ensurePdfWorker: vi.fn(),
120+
ensurePdfWorker: vi.fn(() => {
121+
workerConfiguredBeforeMount = true
122+
return ensurePdfWorkerMock()
123+
}),
116124
}))
117125

118126
describe('PdfEditor Component - Business Rules', () => {
@@ -140,10 +148,19 @@ describe('PdfEditor Component - Business Rules', () => {
140148
}
141149

142150
beforeEach(() => {
151+
workerConfiguredBeforeMount = false
152+
pdfElementsWorkerReadyStates.length = 0
143153
vi.clearAllMocks()
144154
wrapper = createWrapper()
145155
})
146156

157+
describe('RULE: worker initialization ordering', () => {
158+
it('configures the pdf worker before mounting PDFElements', () => {
159+
expect(ensurePdfWorkerMock).toHaveBeenCalledTimes(1)
160+
expect(pdfElementsWorkerReadyStates).toEqual([true])
161+
})
162+
})
163+
147164
describe('RULE: getSignerLabel with fallback chain', () => {
148165
it('returns displayName when available', () => {
149166
const signer = {

0 commit comments

Comments
 (0)