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