|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { describe, expect, it, vi } from 'vitest' |
| 7 | + |
| 8 | +vi.mock('@nextcloud/l10n', () => ({ |
| 9 | + t: (_app: string, text: string) => text, |
| 10 | + getLanguage: () => 'en', |
| 11 | +})) |
| 12 | + |
| 13 | +vi.mock('@nextcloud/initial-state', () => ({ |
| 14 | + loadState: (_app: string, _key: string, fallback: unknown) => fallback, |
| 15 | +})) |
| 16 | + |
| 17 | +import { signatureFooterRealDefinition } from '../../../../views/Settings/PolicyWorkbench/settings/signature-footer/realDefinition' |
| 18 | + |
| 19 | +describe('signatureFooterRealDefinition.resolveEditorProps', () => { |
| 20 | + it('falls back to base inheritedTemplate when policy inheritedValue has no custom footer template', () => { |
| 21 | + const baseEditorProps = { |
| 22 | + inheritedTemplate: 'SYSTEM_DEFAULT_TEMPLATE', |
| 23 | + } |
| 24 | + const policy = { |
| 25 | + inheritedValue: '{"enabled":true,"writeQrcodeOnFooter":true,"validationSite":"","customizeFooterTemplate":false,"footerTemplate":"","previewWidth":595,"previewHeight":100,"previewZoom":100}', |
| 26 | + } as unknown as Parameters<NonNullable<typeof signatureFooterRealDefinition.resolveEditorProps>>[0] |
| 27 | + |
| 28 | + const resolved = signatureFooterRealDefinition.resolveEditorProps?.(policy, baseEditorProps) |
| 29 | + |
| 30 | + // When the inherited level has no custom template, the system-level default from loadState must be preserved |
| 31 | + expect(resolved).toMatchObject({ |
| 32 | + inheritedTemplate: 'SYSTEM_DEFAULT_TEMPLATE', |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + it('uses inherited policy footer template when non-empty and overrides base', () => { |
| 37 | + const baseEditorProps = { |
| 38 | + inheritedTemplate: 'SYSTEM_DEFAULT_TEMPLATE', |
| 39 | + } |
| 40 | + const policy = { |
| 41 | + inheritedValue: '{"enabled":true,"writeQrcodeOnFooter":true,"validationSite":"","customizeFooterTemplate":true,"footerTemplate":"ADMIN_CUSTOM_TEMPLATE","previewWidth":595,"previewHeight":100,"previewZoom":100}', |
| 42 | + } as unknown as Parameters<NonNullable<typeof signatureFooterRealDefinition.resolveEditorProps>>[0] |
| 43 | + |
| 44 | + const resolved = signatureFooterRealDefinition.resolveEditorProps?.(policy, baseEditorProps) |
| 45 | + |
| 46 | + // When the inherited level has a real custom template, that takes precedence over the system default |
| 47 | + expect(resolved).toMatchObject({ |
| 48 | + inheritedTemplate: 'ADMIN_CUSTOM_TEMPLATE', |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + it('keeps base inheritedTemplate when policy exists but has no inheritedValue property', () => { |
| 53 | + const baseEditorProps = { |
| 54 | + inheritedTemplate: 'BASE_TEMPLATE', |
| 55 | + } |
| 56 | + const policy = { |
| 57 | + effectiveValue: 'parallel', |
| 58 | + } as unknown as Parameters<NonNullable<typeof signatureFooterRealDefinition.resolveEditorProps>>[0] |
| 59 | + |
| 60 | + const resolved = signatureFooterRealDefinition.resolveEditorProps?.(policy, baseEditorProps) |
| 61 | + |
| 62 | + // Policy without inheritedValue property → do not override base |
| 63 | + expect(resolved).toMatchObject({ |
| 64 | + inheritedTemplate: 'BASE_TEMPLATE', |
| 65 | + }) |
| 66 | + }) |
| 67 | + |
| 68 | + it('keeps base inheritedTemplate when policy is null', () => { |
| 69 | + const baseEditorProps = { |
| 70 | + inheritedTemplate: 'BASE_TEMPLATE', |
| 71 | + } |
| 72 | + |
| 73 | + const resolved = signatureFooterRealDefinition.resolveEditorProps?.(null, baseEditorProps) |
| 74 | + |
| 75 | + expect(resolved).toEqual({ |
| 76 | + inheritedTemplate: 'BASE_TEMPLATE', |
| 77 | + }) |
| 78 | + }) |
| 79 | +}) |
0 commit comments