2022-07-12 10:55:28 +02:00
|
|
|
import { config, mount } from "@vue/test-utils";
|
2020-12-09 09:56:35 +01:00
|
|
|
import GroupSection from "@/components/Group/GroupSection.vue";
|
|
|
|
import RouteName from "@/router/name";
|
|
|
|
import { routes } from "@/router";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { describe, it, expect, beforeEach } from "vitest";
|
|
|
|
import { createRouter, createWebHistory, Router } from "vue-router";
|
|
|
|
import Oruga from "@oruga-ui/oruga-next";
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
config.global.plugins.push(Oruga);
|
|
|
|
|
|
|
|
let router: Router;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
router = createRouter({
|
|
|
|
history: createWebHistory(),
|
|
|
|
routes: routes,
|
|
|
|
});
|
|
|
|
|
|
|
|
// await router.isReady();
|
|
|
|
});
|
2020-12-09 09:56:35 +01:00
|
|
|
|
|
|
|
const groupPreferredUsername = "my_group";
|
|
|
|
const groupDomain = "remotedomain.net";
|
|
|
|
const groupUsername = `${groupPreferredUsername}@${groupDomain}`;
|
|
|
|
|
|
|
|
const defaultSlotText = "A list of elements";
|
2021-08-05 11:01:40 +02:00
|
|
|
const createSlotButtonText = "+ Create a post";
|
2020-12-09 09:56:35 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
title?: string;
|
|
|
|
icon?: string;
|
|
|
|
privateSection?: boolean;
|
2022-07-12 10:55:28 +02:00
|
|
|
route?: { name: string; params: { preferredUsername: string } };
|
2020-12-09 09:56:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const baseProps: Props = {
|
|
|
|
title: "My group section",
|
|
|
|
icon: "bullhorn",
|
|
|
|
route: {
|
|
|
|
name: RouteName.POSTS,
|
|
|
|
params: {
|
|
|
|
preferredUsername: groupUsername,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const generateWrapper = (customProps: Props = {}) => {
|
|
|
|
return mount(GroupSection, {
|
2022-07-12 10:55:28 +02:00
|
|
|
props: { ...baseProps, ...customProps },
|
2020-12-09 09:56:35 +01:00
|
|
|
slots: {
|
|
|
|
default: `<div>${defaultSlotText}</div>`,
|
2022-07-12 10:55:28 +02:00
|
|
|
create: `<router-link :to="{
|
|
|
|
name: 'POST_CREATE',
|
|
|
|
params: {
|
|
|
|
preferredUsername: '${groupUsername}'
|
|
|
|
}
|
|
|
|
}"
|
|
|
|
class="btn-primary">${createSlotButtonText}</router-link>`,
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
plugins: [router],
|
2020-12-09 09:56:35 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("GroupSection", () => {
|
|
|
|
it("renders group section with basic informations", () => {
|
2022-07-12 10:55:28 +02:00
|
|
|
const wrapper = generateWrapper();
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
expect(wrapper.find("i.mdi").classes(`mdi-${baseProps.icon}`)).toBe(true);
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
expect(wrapper.find("h2").text()).toBe(baseProps.title);
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
expect(wrapper.find("a").attributes("href")).toBe(`/@${groupUsername}/p`);
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
// expect(wrapper.find(".group-section-title").classes("privateSection")).toBe(
|
|
|
|
// true
|
|
|
|
// );
|
2020-12-09 09:56:35 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
expect(wrapper.find("section > div.flex-1").text()).toBe(defaultSlotText);
|
|
|
|
expect(wrapper.find(".flex.justify-end.p-2 a").text()).toBe(
|
|
|
|
createSlotButtonText
|
|
|
|
);
|
|
|
|
expect(wrapper.find(".flex.justify-end.p-2 a").attributes("href")).toBe(
|
2020-12-09 09:56:35 +01:00
|
|
|
`/@${groupUsername}/p/new`
|
|
|
|
);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders public group section", () => {
|
|
|
|
const wrapper = generateWrapper({ privateSection: false });
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
// expect(wrapper.find(".group-section-title").classes("privateSection")).toBe(
|
|
|
|
// false
|
|
|
|
// );
|
2020-12-09 09:56:35 +01:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|