|
1 | 1 | // SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors |
2 | 2 | // SPDX-License-Identifier: AGPL-3.0-or-later |
3 | 3 |
|
4 | | -import { afterEach, describe, expect, it, vi } from 'vitest' |
5 | | -import { mount } from '@vue/test-utils' |
6 | | -import { defineComponent, nextTick } from 'vue' |
7 | | -import AdminSupportBanner from '../../../components/AdminSupportBanner.vue' |
| 4 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 5 | +import { mount } from "@vue/test-utils"; |
| 6 | +import { defineComponent, nextTick } from "vue"; |
| 7 | +import AdminSupportBanner from "../../../components/AdminSupportBanner.vue"; |
8 | 8 |
|
9 | | -vi.mock('@nextcloud/l10n', () => ({ |
10 | | - t: (_app: string, text: string, parameters?: Record<string, string>) => { |
11 | | - if (parameters === undefined) { |
12 | | - return `tr:${text}` |
13 | | - } |
| 9 | +vi.mock("@nextcloud/l10n", () => ({ |
| 10 | + t: (_app: string, text: string, parameters?: Record<string, string>) => { |
| 11 | + if (parameters === undefined) { |
| 12 | + return `tr:${text}`; |
| 13 | + } |
14 | 14 |
|
15 | | - return Object.entries(parameters).reduce((translated, [key, value]) => translated.replace(`{${key}}`, value), `tr:${text}`) |
16 | | - }, |
17 | | -})) |
| 15 | + return Object.entries(parameters).reduce( |
| 16 | + (translated, [key, value]) => translated.replace(`{${key}}`, value), |
| 17 | + `tr:${text}`, |
| 18 | + ); |
| 19 | + }, |
| 20 | +})); |
18 | 21 |
|
19 | | -vi.mock('@nextcloud/vue', () => ({ |
20 | | - NcButton: defineComponent({ |
21 | | - name: 'NcButton', |
22 | | - emits: ['click'], |
23 | | - template: '<button type="button" v-bind="$attrs" @click="$emit(\'click\', $event)"><slot /></button>', |
24 | | - }), |
25 | | - NcNoteCard: defineComponent({ |
26 | | - name: 'NcNoteCard', |
27 | | - template: '<div><slot /></div>', |
28 | | - }), |
29 | | -})) |
| 22 | +vi.mock("@nextcloud/vue", () => ({ |
| 23 | + NcButton: defineComponent({ |
| 24 | + name: "NcButton", |
| 25 | + emits: ["click"], |
| 26 | + template: |
| 27 | + '<button type="button" v-bind="$attrs" @click="$emit(\'click\', $event)"><slot /></button>', |
| 28 | + }), |
| 29 | + NcNoteCard: defineComponent({ |
| 30 | + name: "NcNoteCard", |
| 31 | + template: "<div><slot /></div>", |
| 32 | + }), |
| 33 | +})); |
30 | 34 |
|
31 | 35 | afterEach(() => { |
32 | | - window.localStorage.clear() |
33 | | - vi.restoreAllMocks() |
34 | | -}) |
| 36 | + window.localStorage.clear(); |
| 37 | + vi.restoreAllMocks(); |
| 38 | +}); |
35 | 39 |
|
36 | | -describe('AdminSupportBanner', () => { |
37 | | - it('renders translated copy and actions', () => { |
38 | | - const wrapper = mount(AdminSupportBanner) |
| 40 | +describe("AdminSupportBanner", () => { |
| 41 | + it("renders translated banner copy", () => { |
| 42 | + const wrapper = mount(AdminSupportBanner); |
39 | 43 |
|
40 | | - expect(wrapper.text()).toContain('tr:Help keep Profile Fields sustainable.') |
41 | | - expect(wrapper.text()).toContain('tr:Sponsor LibreSign') |
42 | | - expect(wrapper.text()).toContain('tr:Maybe later') |
43 | | - expect(wrapper.text()).toContain('tr:Give Profile Fields a star on GitHub') |
44 | | - }) |
| 44 | + expect(wrapper.text()).toContain( |
| 45 | + "tr:Help keep Profile Fields sustainable.", |
| 46 | + ); |
| 47 | + expect(wrapper.text()).toContain( |
| 48 | + "tr:Profile Fields is open source under the AGPL license and maintained by the LibreCode team, creators of LibreSign.", |
| 49 | + ); |
| 50 | + expect(wrapper.text()).toContain( |
| 51 | + "tr:If your organization depends on it, please help us sustain its development and maintenance.", |
| 52 | + ); |
| 53 | + expect(wrapper.text()).toContain("tr:Sponsor LibreSign"); |
| 54 | + expect(wrapper.text()).toContain("tr:Maybe later"); |
| 55 | + expect(wrapper.text()).toContain("tr:Give Profile Fields a ⭐ on GitHub"); |
| 56 | + expect(wrapper.text()).toContain( |
| 57 | + "tr:Contact us for support or custom development", |
| 58 | + ); |
| 59 | + }); |
45 | 60 |
|
46 | | - it('opens sponsor page when sponsor button is clicked', async() => { |
47 | | - const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null) |
48 | | - const wrapper = mount(AdminSupportBanner) |
| 61 | + it("opens sponsor page when sponsor button is clicked", async () => { |
| 62 | + const openSpy = vi.spyOn(window, "open").mockImplementation(() => null); |
| 63 | + const wrapper = mount(AdminSupportBanner); |
49 | 64 |
|
50 | | - await wrapper.get('button').trigger('click') |
| 65 | + await wrapper.get("button").trigger("click"); |
51 | 66 |
|
52 | | - expect(openSpy).toHaveBeenCalledWith('https://github.com/sponsors/LibreCodeCoop', '_blank', 'noopener,noreferrer') |
53 | | - }) |
| 67 | + expect(openSpy).toHaveBeenCalledWith( |
| 68 | + "https://github.com/sponsors/LibreCodeCoop", |
| 69 | + "_blank", |
| 70 | + "noopener,noreferrer", |
| 71 | + ); |
| 72 | + }); |
54 | 73 |
|
55 | | - it('hides itself after dismiss and persists state', async() => { |
56 | | - const wrapper = mount(AdminSupportBanner) |
| 74 | + it("hides itself after dismiss and persists state", async () => { |
| 75 | + const wrapper = mount(AdminSupportBanner); |
57 | 76 |
|
58 | | - const buttons = wrapper.findAll('button') |
59 | | - await buttons[1].trigger('click') |
| 77 | + const buttons = wrapper.findAll("button"); |
| 78 | + await buttons[1].trigger("click"); |
60 | 79 |
|
61 | | - expect(wrapper.find('[data-testid="profile-fields-admin-support-banner"]').exists()).toBe(false) |
62 | | - expect(window.localStorage.getItem('profile_fields_support_banner_dismissed')).toBe('1') |
63 | | - }) |
| 80 | + expect( |
| 81 | + wrapper |
| 82 | + .find('[data-testid="profile-fields-admin-support-banner"]') |
| 83 | + .exists(), |
| 84 | + ).toBe(false); |
| 85 | + expect( |
| 86 | + window.localStorage.getItem("profile_fields_support_banner_dismissed"), |
| 87 | + ).toBe("1"); |
| 88 | + }); |
64 | 89 |
|
65 | | - it('starts hidden when dismissal key is already persisted', () => { |
66 | | - window.localStorage.setItem('profile_fields_support_banner_dismissed', '1') |
| 90 | + it("starts hidden when dismissal key is already persisted", () => { |
| 91 | + window.localStorage.setItem("profile_fields_support_banner_dismissed", "1"); |
67 | 92 |
|
68 | | - const wrapper = mount(AdminSupportBanner) |
69 | | - return nextTick().then(() => { |
70 | | - expect(wrapper.find('[data-testid="profile-fields-admin-support-banner"]').exists()).toBe(false) |
71 | | - }) |
72 | | - }) |
73 | | -}) |
| 93 | + const wrapper = mount(AdminSupportBanner); |
| 94 | + return nextTick().then(() => { |
| 95 | + expect( |
| 96 | + wrapper |
| 97 | + .find('[data-testid="profile-fields-admin-support-banner"]') |
| 98 | + .exists(), |
| 99 | + ).toBe(false); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments