Skip to content

Commit 352d559

Browse files
committed
test: cover manage password signature init
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent b27dc32 commit 352d559

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/tests/views/Account/partials/ManagePassword.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { VueWrapper } from '@vue/test-utils'
99

1010
const loadStateMock = vi.fn()
1111
const hasSignatureFileMock = vi.fn()
12+
const initializeHasSignatureFileMock = vi.fn()
1213

1314
vi.mock('@nextcloud/initial-state', () => ({
1415
loadState: (...args: unknown[]) => loadStateMock(...args),
@@ -18,6 +19,7 @@ vi.mock('../../../../store/signMethods.js', () => ({
1819
useSignMethodsStore: () => ({
1920
hasSignatureFile: () => hasSignatureFileMock(),
2021
setHasSignatureFile: vi.fn(),
22+
initializeHasSignatureFile: (...args: unknown[]) => initializeHasSignatureFileMock(...args),
2123
showModal: vi.fn(),
2224
}),
2325
}))
@@ -59,6 +61,31 @@ describe('ManagePassword', () => {
5961
beforeEach(() => {
6062
loadStateMock.mockReset()
6163
hasSignatureFileMock.mockReset()
64+
initializeHasSignatureFileMock.mockReset()
65+
})
66+
67+
it('initializes signature file state from config without forcing remount behavior', () => {
68+
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
69+
if (key === 'certificate_engine') return 'openssl'
70+
if (key === 'config') return { hasSignatureFile: true }
71+
return fallback
72+
})
73+
hasSignatureFileMock.mockReturnValue(true)
74+
75+
mount(ManagePassword, {
76+
global: {
77+
stubs: {
78+
NcButton: { template: '<button><slot /><slot name="icon" /></button>' },
79+
NcIconSvgWrapper: { name: 'NcIconSvgWrapper', props: ['path'], template: '<i class="icon" :data-path="path" />' },
80+
CreatePassword: true,
81+
ReadCertificate: true,
82+
ResetPassword: true,
83+
UploadCertificate: true,
84+
},
85+
},
86+
})
87+
88+
expect(initializeHasSignatureFileMock).toHaveBeenCalledWith(true)
6289
})
6390

6491
it('registers icon wrapper and exposes mdi icon paths used in template', async () => {

0 commit comments

Comments
 (0)