Fix JS unit tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-08-02 19:26:23 +02:00
parent 8c480af4bd
commit 0c749742ab
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
6 changed files with 35 additions and 16 deletions

View File

@ -20,7 +20,6 @@ import {
newCommentForEventResponse,
} from "../../mocks/event";
import flushPromises from "flush-promises";
import { InMemoryCache } from "@apollo/client/core";
import { defaultResolvers } from "../../common";
const localVue = createLocalVue();
localVue.use(Buefy);
@ -39,11 +38,9 @@ describe("CommentTree", () => {
let mockClient: MockApolloClient | null;
let apolloProvider;
let requestHandlers: Record<string, RequestHandler>;
const cache = new InMemoryCache({ addTypename: false });
const generateWrapper = (handlers = {}, baseData = {}) => {
mockClient = createMockClient({
cache,
resolvers: defaultResolvers,
});
@ -84,6 +81,21 @@ describe("CommentTree", () => {
});
};
afterEach(() => {
mockClient = null;
requestHandlers = {};
apolloProvider = null;
wrapper.destroy();
});
it("renders a loading comment tree", async () => {
generateWrapper();
expect(wrapper.find(".loading").text()).toBe("Loading comments…");
expect(wrapper.html()).toMatchSnapshot();
});
it("renders a comment tree with comments", async () => {
generateWrapper();
@ -144,12 +156,11 @@ describe("CommentTree", () => {
.fn()
.mockResolvedValue(eventNoCommentThreadsMock),
});
expect(requestHandlers.eventCommentThreadsQueryHandler).toHaveBeenCalled();
expect(wrapper.exists()).toBe(true);
expect(wrapper.find(".loading").text()).toBe("Loading comments…");
await flushPromises();
expect(
requestHandlers.eventCommentThreadsQueryHandler
).toHaveBeenCalledWith({ eventUUID: eventData.uuid });
expect(wrapper.find(".no-comments").text()).toBe("No comments yet");
expect(wrapper.html()).toMatchSnapshot();

View File

@ -33,6 +33,15 @@ exports[`CommentTree renders a comment tree with comments 1`] = `
</div>
`;
exports[`CommentTree renders a loading comment tree 1`] = `
<div>
<!---->
<p class="loading has-text-centered">
Loading comments…
</p>
</div>
`;
exports[`CommentTree renders an empty comment tree 1`] = `
<div>
<form class="new-comment">

View File

@ -229,11 +229,7 @@ describe("ParticipationWithoutAccount", () => {
eventData.participantStats.notConfirmed + 1
);
}
// lots of things to await
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await flushPromises();
expect(wrapper.find("form").exists()).toBeFalsy();
expect(wrapper.find("h1.title").text()).toBe(
"Request for participation confirmation sent"

View File

@ -76,8 +76,7 @@ describe("Reset page", () => {
token: "some-token",
});
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await flushPromises();
expect(wrapper.find("article.message.is-danger").text()).toContain(
"The token you provided is invalid"

View File

@ -115,13 +115,14 @@ describe("Render login form", () => {
expect(requestHandlers.loginMutationHandler).toHaveBeenCalledWith({
...loginMock,
});
await wrapper.vm.$nextTick();
await wrapper.vm.$nextTick();
await flushPromises();
const currentUser = mockClient?.cache.readQuery<{
currentUser: ICurrentUser;
}>({
query: CURRENT_USER_CLIENT,
})?.currentUser;
await flushPromises();
expect(currentUser?.email).toBe("some@email.tld");
expect(currentUser?.id).toBe("1");
expect(jest.isMockFunction(wrapper.vm.$router.push)).toBe(true);

View File

@ -108,6 +108,7 @@ export const eventCommentThreadsMock = {
summary: "I am the senate",
},
deletedAt: null,
insertedAt: "2020-12-03T09:02:00Z",
isAnnouncement: false,
},
{
@ -137,6 +138,7 @@ export const eventCommentThreadsMock = {
summary: "I am the senate",
},
deletedAt: null,
insertedAt: "2020-12-03T11:02:00Z",
isAnnouncement: false,
},
],
@ -180,6 +182,7 @@ export const newCommentForEventResponse: DataMock = {
summary: "I am the senate",
},
deletedAt: null,
insertedAt: "2020-12-03T13:02:00Z",
isAnnouncement: false,
},
},