2020-12-02 11:19:39 +01:00
|
|
|
import { config, createLocalVue, mount } from "@vue/test-utils";
|
|
|
|
import PostListItem from "@/components/Post/PostListItem.vue";
|
|
|
|
import Buefy from "buefy";
|
|
|
|
import VueRouter from "vue-router";
|
|
|
|
import { routes } from "@/router";
|
2021-06-04 20:24:43 +02:00
|
|
|
import { enUS } from "date-fns/locale";
|
2021-11-02 19:47:54 +01:00
|
|
|
import { formatDateTimeString } from "@/filters/datetime";
|
|
|
|
import { i18n } from "@/utils/i18n";
|
2020-12-02 11:19:39 +01:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Buefy);
|
|
|
|
localVue.use(VueRouter);
|
2021-06-04 20:24:43 +02:00
|
|
|
localVue.use((vue) => {
|
|
|
|
vue.prototype.$dateFnsLocale = enUS;
|
|
|
|
});
|
2020-12-02 11:19:39 +01:00
|
|
|
const router = new VueRouter({ routes, mode: "history" });
|
|
|
|
config.mocks.$t = (key: string): string => key;
|
|
|
|
|
|
|
|
const postData = {
|
|
|
|
id: "1",
|
|
|
|
slug: "my-blog-post-some-uuid",
|
|
|
|
title: "My Blog Post",
|
|
|
|
body: "My content",
|
|
|
|
insertedAt: "2020-12-02T09:01:20.873Z",
|
2021-11-02 19:47:54 +01:00
|
|
|
tags: [],
|
2020-12-02 11:19:39 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 19:47:54 +01:00
|
|
|
const generateWrapper = (
|
|
|
|
customPostData: Record<string, unknown> = {},
|
|
|
|
customProps: Record<string, unknown> = {}
|
|
|
|
) => {
|
2020-12-02 11:19:39 +01:00
|
|
|
return mount(PostListItem, {
|
|
|
|
localVue,
|
|
|
|
router,
|
2021-11-02 19:47:54 +01:00
|
|
|
i18n,
|
2020-12-02 11:19:39 +01:00
|
|
|
propsData: {
|
|
|
|
post: { ...postData, ...customPostData },
|
2021-11-02 19:47:54 +01:00
|
|
|
...customProps,
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
formatDateTimeString,
|
2020-12-02 11:19:39 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("PostListItem", () => {
|
|
|
|
it("renders post list item with basic informations", () => {
|
|
|
|
const wrapper = generateWrapper();
|
|
|
|
|
2021-11-02 19:47:54 +01:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2020-12-02 11:19:39 +01:00
|
|
|
|
|
|
|
expect(
|
|
|
|
wrapper.find("a.post-minimalist-card-wrapper").attributes("href")
|
|
|
|
).toBe(`/p/${postData.slug}`);
|
|
|
|
|
2021-11-02 19:47:54 +01:00
|
|
|
expect(wrapper.find(".post-minimalist-title").text()).toBe(postData.title);
|
|
|
|
|
|
|
|
expect(wrapper.find(".post-publication-date").text()).toBe("Dec 2, 2020");
|
|
|
|
|
|
|
|
expect(wrapper.find(".post-publisher").exists()).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders post list item with tags", () => {
|
|
|
|
const wrapper = generateWrapper({
|
|
|
|
tags: [{ slug: "a-tag", title: "A tag" }],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
expect(wrapper.find(".tags").text()).toContain("A tag");
|
|
|
|
|
|
|
|
expect(wrapper.find(".post-publisher").exists()).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders post list item with publisher name", () => {
|
|
|
|
const wrapper = generateWrapper(
|
|
|
|
{ author: { name: "An author" } },
|
|
|
|
{ isCurrentActorMember: true }
|
2020-12-02 11:19:39 +01:00
|
|
|
);
|
2021-11-02 19:47:54 +01:00
|
|
|
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
expect(wrapper.find(".post-publisher").exists()).toBeTruthy();
|
|
|
|
expect(wrapper.find(".post-publisher").text()).toContain("An author");
|
2020-12-02 11:19:39 +01:00
|
|
|
});
|
|
|
|
});
|