97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import { beforeEach, describe, it, expect } from "vitest";
|
|
import { enUS } from "date-fns/locale";
|
|
import { routes } from "@/router";
|
|
import { createRouter, createWebHistory, Router } from "vue-router";
|
|
import { config, mount } from "@vue/test-utils";
|
|
import { Oruga } from "@oruga-ui/oruga-next";
|
|
import flushPromises from "flush-promises";
|
|
import { getMockClient } from "../../mocks/client";
|
|
import { htmlRemoveId } from "../../common";
|
|
import DiscussionComment from "@/components/Discussion/DiscussionComment.vue";
|
|
import { IPerson } from "@/types/actor";
|
|
import { IComment } from "@/types/comment.model";
|
|
import { ActorType } from "@/types/enums";
|
|
import { reactive } from "vue";
|
|
|
|
config.global.plugins.push(Oruga);
|
|
|
|
let router: Router;
|
|
|
|
beforeEach(async () => {
|
|
router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: routes,
|
|
});
|
|
|
|
// await router.isReady();
|
|
});
|
|
|
|
const baseActorAvatar = {
|
|
id: "",
|
|
name: "",
|
|
alt: "",
|
|
metadata: {},
|
|
url: "https://social.tcit.fr/system/accounts/avatars/000/000/001/original/a28c50ce5f2b13fd.jpg",
|
|
};
|
|
|
|
const baseActor: IPerson = {
|
|
name: "Thomas Citharel",
|
|
preferredUsername: "tcit",
|
|
avatar: baseActorAvatar,
|
|
domain: null,
|
|
url: "",
|
|
summary: "",
|
|
suspended: false,
|
|
type: ActorType.PERSON,
|
|
id: "598",
|
|
};
|
|
|
|
const comment = reactive<IComment>({
|
|
text: "Hello there",
|
|
publishedAt: new Date().toString(),
|
|
actor: baseActor,
|
|
});
|
|
|
|
const deletedComment = reactive<IComment>({
|
|
...comment,
|
|
actor: null,
|
|
deletedAt: new Date().toString(),
|
|
});
|
|
|
|
const generateWrapper = (props: any) => {
|
|
const global_data = getMockClient([]);
|
|
global_data.provide.dateFnsLocale = enUS;
|
|
global_data.plugins = [router];
|
|
return mount(DiscussionComment, {
|
|
props: props,
|
|
global: {
|
|
...global_data,
|
|
stubs: {
|
|
RouterLink: false,
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
describe("DiscussionComment", () => {
|
|
it("Show Basic", async () => {
|
|
const wrapper = generateWrapper({
|
|
modelValue: comment,
|
|
currentActor: baseActor,
|
|
});
|
|
await wrapper.vm.$nextTick();
|
|
await flushPromises();
|
|
expect(htmlRemoveId(wrapper.html())).toMatchSnapshot();
|
|
});
|
|
|
|
it("Show Deleted comment", async () => {
|
|
const wrapper = generateWrapper({
|
|
modelValue: deletedComment,
|
|
currentActor: baseActor,
|
|
});
|
|
await wrapper.vm.$nextTick();
|
|
await flushPromises();
|
|
expect(htmlRemoveId(wrapper.html())).toMatchSnapshot();
|
|
});
|
|
});
|