import { mount } from "@vue/test-utils";
import { describe, it, expect, vi, beforeEach } from "vitest";
import ChangelogModal from "@/components/ChangelogModal.vue";
import { createVuetify } from "vuetify";
const vuetify = createVuetify();
describe("ChangelogModal.vue", () => {
let axiosMock;
beforeEach(() => {
axiosMock = {
get: vi.fn(),
post: vi.fn(),
};
window.axios = axiosMock;
});
const mountChangelogModal = (props = {}) => {
return mount(ChangelogModal, {
props,
global: {
mocks: {
$t: (key, def) => def || key,
$route: {
meta: {
isPage: props.isPage || false,
},
},
},
stubs: {
"v-dialog": {
template: '
',
props: ["modelValue"],
},
"v-toolbar": {
template: '
',
},
"v-toolbar-title": {
template: '
',
},
"v-spacer": {
template: '',
},
"v-btn": {
template: '',
},
"v-icon": {
template: '',
},
"v-chip": {
template: '',
},
"v-card": {
template: '
',
},
"v-card-text": {
template: '
',
},
"v-card-actions": {
template: '
',
},
"v-divider": {
template: '
',
},
"v-checkbox": {
template: '',
},
"v-progress-circular": {
template: '',
},
},
},
});
};
it("displays logo in modal version", async () => {
axiosMock.get.mockResolvedValue({
data: {
html: "Test
",
version: "4.0.0",
},
});
const wrapper = mountChangelogModal();
await wrapper.vm.show();
await wrapper.vm.$nextTick();
const img = wrapper.find("img");
expect(img.exists()).toBe(true);
expect(img.attributes("src")).toContain("favicon-512x512.png");
});
it("displays logo in page version", async () => {
axiosMock.get.mockResolvedValue({
data: {
html: "Test
",
version: "4.0.0",
},
});
const wrapper = mountChangelogModal({ isPage: true });
// Page version calls fetchChangelog on mount
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
const img = wrapper.find("img");
expect(img.exists()).toBe(true);
expect(img.attributes("src")).toContain("favicon-512x512.png");
});
it("has hover classes on close button", async () => {
axiosMock.get.mockResolvedValue({
data: {
html: "Test
",
version: "4.0.0",
},
});
const wrapper = mountChangelogModal();
await wrapper.vm.show();
await wrapper.vm.$nextTick();
const closeBtn = wrapper.find("button.v-btn");
expect(closeBtn.exists()).toBe(true);
expect(closeBtn.attributes("class")).toContain("dark:hover:bg-white/10");
expect(closeBtn.attributes("class")).toContain("hover:bg-black/5");
});
});