Skip to content

Commit f855a2f

Browse files
committed
test: cover identify signer state reset
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0ef4b07 commit f855a2f

1 file changed

Lines changed: 43 additions & 27 deletions

File tree

src/tests/components/Request/IdentifySigner.spec.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import IdentifySigner from '../../../components/Request/IdentifySigner.vue'
1111
import { useFilesStore } from '../../../store/files.js'
1212
import type { IdentifyAccountRecord } from '../../../types'
1313

14+
const signerSelectStub = {
15+
name: 'SignerSelect',
16+
props: ['placeholder', 'method'],
17+
template: '<div class="signer-select-stub" />',
18+
}
19+
1420
vi.mock('@nextcloud/dialogs', () => ({
1521
showError: vi.fn(),
1622
}))
@@ -54,11 +60,12 @@ type IdentifySignerVm = {
5460
description: string
5561
enableCustomMessage: boolean
5662
identify: string
57-
signer: IdentifyAccountRecord | null
5863
identifyMethod?: IdentifyAccountRecord['method']
5964
acceptsEmailNotifications?: boolean
6065
identifyMethodLabel: string
61-
updateSigner: (signer: IdentifyAccountRecord | null) => void
66+
resetNameValidation: () => void
67+
resetSelectedSignerState: () => void
68+
applySelectedSigner: (signer: IdentifyAccountRecord | null) => void
6269
saveSigner: () => Promise<void>
6370
onNameChange: () => void
6471
onToggleCustomMessage: (checked: boolean) => void
@@ -124,7 +131,7 @@ describe('IdentifySigner rules', () => {
124131
NcNoteCard: true,
125132
NcTextArea: true,
126133
NcTextField: true,
127-
SignerSelect: true,
134+
SignerSelect: signerSelectStub,
128135
},
129136
mocks: {
130137
t: (_app: string, text: string) => text,
@@ -205,14 +212,6 @@ describe('IdentifySigner rules', () => {
205212
it('shows custom message for email method', () => {
206213
wrapper.vm.identifyMethod = 'email'
207214
wrapper.vm.identify = 'john@example.com'
208-
wrapper.vm.signer = {
209-
identify: 'john@example.com',
210-
isNoUser: true,
211-
shareType: 4,
212-
subname: 'john@example.com',
213-
displayName: 'John Doe',
214-
method: 'email',
215-
}
216215

217216
expect(wrapper.vm.showCustomMessage).toBe(true)
218217
})
@@ -284,26 +283,43 @@ describe('IdentifySigner rules', () => {
284283
method: 'email',
285284
} satisfies IdentifyAccountRecord
286285

287-
wrapper.vm.updateSigner(newSigner)
286+
wrapper.vm.applySelectedSigner(newSigner)
288287

289-
expect(wrapper.vm.signer).toEqual(newSigner)
290288
expect(wrapper.vm.identify).toBe('john@example.com')
291289
expect(wrapper.vm.displayName).toBe('John Doe')
292290
})
293291

294-
it('clears signer when updateSigner called with null', () => {
295-
wrapper.vm.signer = {
296-
identify: 'test@example.com',
297-
isNoUser: true,
298-
shareType: 4,
299-
displayName: 'Test',
300-
subname: 'test@example.com',
301-
}
292+
it('clears selected signer state when selection is removed', () => {
293+
wrapper.vm.displayName = 'Test'
294+
wrapper.vm.description = 'Keep me'
295+
wrapper.vm.enableCustomMessage = true
302296
wrapper.vm.identify = 'test@example.com'
297+
wrapper.vm.identifyMethod = 'email'
298+
299+
wrapper.vm.applySelectedSigner(null)
300+
301+
expect(wrapper.vm.displayName).toBe('')
302+
expect(wrapper.vm.description).toBe('')
303+
expect(wrapper.vm.enableCustomMessage).toBe(false)
304+
expect(wrapper.vm.identify).toBe('')
305+
expect(wrapper.vm.identifyMethod).toBeUndefined()
306+
})
303307

304-
wrapper.vm.updateSigner(null)
308+
it('clears stale name validation when selecting a signer', () => {
309+
wrapper.vm.displayName = 'Jo'
310+
wrapper.vm.onNameChange()
305311

306-
expect(wrapper.vm.signer).toBe(null)
312+
wrapper.vm.applySelectedSigner({
313+
identify: 'john@example.com',
314+
isNoUser: true,
315+
shareType: 4,
316+
displayName: 'John Doe',
317+
subname: 'john@example.com',
318+
method: 'email',
319+
})
320+
321+
expect(wrapper.vm.nameHaveError).toBe(false)
322+
expect(wrapper.vm.nameHelperText).toBe('')
307323
})
308324

309325
it('disables custom message for account without email notifications', () => {
@@ -320,7 +336,7 @@ describe('IdentifySigner rules', () => {
320336
acceptsEmailNotifications: false,
321337
} satisfies IdentifyAccountRecord
322338

323-
wrapper.vm.updateSigner(accountSigner)
339+
wrapper.vm.applySelectedSigner(accountSigner)
324340

325341
expect(wrapper.vm.enableCustomMessage).toBe(false)
326342
expect(wrapper.vm.description).toBe('')
@@ -340,7 +356,7 @@ describe('IdentifySigner rules', () => {
340356
acceptsEmailNotifications: true,
341357
} satisfies IdentifyAccountRecord
342358

343-
wrapper.vm.updateSigner(accountSigner)
359+
wrapper.vm.applySelectedSigner(accountSigner)
344360

345361
expect(wrapper.vm.enableCustomMessage).toBe(true)
346362
expect(wrapper.vm.description).toBe('Test message')
@@ -467,7 +483,7 @@ describe('IdentifySigner rules', () => {
467483
expect(wrapper.vm.displayName).toBe('')
468484
expect(wrapper.vm.description).toBe('')
469485
expect(wrapper.vm.identify).toBe('')
470-
expect(wrapper.vm.signer).toBe(null)
486+
expect(wrapper.vm.identifyMethod).toBeUndefined()
471487
})
472488

473489
it('closes signer form after successful save', async () => {
@@ -579,7 +595,7 @@ describe('IdentifySigner rules', () => {
579595
})
580596

581597
it('returns empty string when no method selected', () => {
582-
wrapper.vm.signer = {}
598+
wrapper.vm.identifyMethod = undefined
583599

584600
const label = wrapper.vm.identifyMethodLabel
585601

0 commit comments

Comments
 (0)