Skip to content

Commit 745d2e6

Browse files
test(validation): mock show-confetti capability and add disabled scenario test
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4d10759 commit 745d2e6

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/tests/views/Validation.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { afterEach, describe, expect, it, beforeEach, vi } from 'vitest'
77
import { shallowMount } from '@vue/test-utils'
88
import axios from '@nextcloud/axios'
9+
import { getCapabilities } from '@nextcloud/capabilities'
910
import JSConfetti from 'js-confetti'
1011
import Validation from '../../views/Validation.vue'
1112

@@ -104,6 +105,17 @@ const mockRouter = {
104105
push: vi.fn(),
105106
}
106107

108+
// Mock capabilities - show-confetti enabled by default so existing tests pass
109+
vi.mock('@nextcloud/capabilities', () => ({
110+
getCapabilities: vi.fn(() => ({
111+
libresign: {
112+
config: {
113+
'show-confetti': true,
114+
},
115+
},
116+
})),
117+
}))
118+
107119
// Mock initial state
108120
vi.mock('@nextcloud/initial-state', () => ({
109121
loadState: vi.fn((app, key, defaultValue) => defaultValue),
@@ -654,6 +666,19 @@ describe('Validation.vue - Business Logic', () => {
654666
wrapper.vm.handleValidationSuccess({ status: SIGNED_STATUS, signers: [] })
655667
expect(mockAddConfetti).not.toHaveBeenCalled()
656668
})
669+
670+
it('does not fire confetti when show-confetti capability is disabled', async () => {
671+
vi.mocked(getCapabilities).mockReturnValueOnce({
672+
libresign: {
673+
config: {
674+
'show-confetti': false,
675+
},
676+
},
677+
} as ReturnType<typeof getCapabilities>)
678+
vi.spyOn(wrapper.vm, 'isAfterSigned', 'get').mockReturnValue(true)
679+
wrapper.vm.handleValidationSuccess({ status: SIGNED_STATUS, signers: [] })
680+
expect(mockAddConfetti).not.toHaveBeenCalled()
681+
})
657682
})
658683

659684
describe('handleSigningComplete method', () => {

0 commit comments

Comments
 (0)