Correct commentTree failure unit-test - issue #1776
This commit is contained in:
@@ -1,23 +1,72 @@
|
||||
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
||||
import { CURRENT_USER_LOCATION_CLIENT } from "@/graphql/location";
|
||||
import { CURRENT_USER_CLIENT } from "@/graphql/user";
|
||||
import { ICurrentUserRole } from "@/types/enums";
|
||||
import {
|
||||
ApolloCache,
|
||||
NormalizedCacheObject,
|
||||
Resolver,
|
||||
type Resolvers,
|
||||
} from "@apollo/client";
|
||||
|
||||
export const defaultResolvers = {
|
||||
Query: {
|
||||
currentUser: (): Record<string, any> => ({
|
||||
email: "user@mail.com",
|
||||
export const fakeCurrentUserData: Resolver = (): Record<string, any> => {
|
||||
return {
|
||||
__typename: "CurrentUser",
|
||||
id: "2",
|
||||
email: "user@mail.com",
|
||||
role: ICurrentUserRole.USER,
|
||||
isLoggedIn: true,
|
||||
__typename: "CurrentUser",
|
||||
}),
|
||||
currentActor: (): Record<string, any> => ({
|
||||
};
|
||||
};
|
||||
|
||||
export const fakeCurrentActorData: Resolver = (): Record<string, any> => {
|
||||
return {
|
||||
__typename: "CurrentActor",
|
||||
id: "67",
|
||||
preferredUsername: "someone",
|
||||
name: "Personne",
|
||||
avatar: null,
|
||||
__typename: "CurrentActor",
|
||||
}),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export function defaultResolvers(
|
||||
cache: ApolloCache<NormalizedCacheObject>
|
||||
): Resolvers {
|
||||
cache?.writeQuery({
|
||||
query: CURRENT_USER_CLIENT,
|
||||
data: {
|
||||
currentUser: fakeCurrentUserData(),
|
||||
},
|
||||
});
|
||||
|
||||
cache?.writeQuery({
|
||||
query: CURRENT_ACTOR_CLIENT,
|
||||
data: {
|
||||
currentActor: fakeCurrentActorData(),
|
||||
},
|
||||
});
|
||||
|
||||
cache?.writeQuery({
|
||||
query: CURRENT_USER_LOCATION_CLIENT,
|
||||
data: {
|
||||
currentUserLocation: {
|
||||
lat: null,
|
||||
lon: null,
|
||||
accuracy: null,
|
||||
isIPLocation: null,
|
||||
name: null,
|
||||
picture: null,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
Query: {
|
||||
currentUser: fakeCurrentUserData,
|
||||
currentActor: fakeCurrentActorData,
|
||||
},
|
||||
} satisfies Resolvers;
|
||||
}
|
||||
|
||||
export const nullMock = {
|
||||
data: {},
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { CommentModeration } from "@/types/enums";
|
||||
import { IEvent } from "@/types/event.model";
|
||||
import {
|
||||
currentActorClientMock,
|
||||
eventCommentThreadsMock,
|
||||
eventNoCommentThreadsMock,
|
||||
newCommentForEventMock,
|
||||
@@ -28,7 +27,8 @@ import { InMemoryCache } from "@apollo/client/cache";
|
||||
import { createRouter, createWebHistory, Router } from "vue-router";
|
||||
import { routes } from "@/router";
|
||||
import { dialogPlugin } from "@/plugins/dialog";
|
||||
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
||||
import { IDENTITIES } from "@/graphql/actor";
|
||||
import { defaultIdentityMock } from "../../mocks/auth";
|
||||
|
||||
config.global.plugins.push(Oruga);
|
||||
config.global.plugins.push(notifierPlugin);
|
||||
@@ -53,7 +53,7 @@ describe("CommentTree", () => {
|
||||
|
||||
mockClient = createMockClient({
|
||||
cache,
|
||||
resolvers: defaultResolvers,
|
||||
resolvers: defaultResolvers(cache),
|
||||
});
|
||||
|
||||
requestHandlers = {
|
||||
@@ -63,9 +63,7 @@ describe("CommentTree", () => {
|
||||
createCommentForEventMutationHandler: vi
|
||||
.fn()
|
||||
.mockResolvedValue(newCommentForEventResponse),
|
||||
getCurrentActorClientHandler: vi
|
||||
.fn()
|
||||
.mockResolvedValue(currentActorClientMock),
|
||||
identityHandler: vi.fn().mockResolvedValue(defaultIdentityMock),
|
||||
...handlers,
|
||||
};
|
||||
|
||||
@@ -77,10 +75,7 @@ describe("CommentTree", () => {
|
||||
CREATE_COMMENT_FROM_EVENT,
|
||||
requestHandlers.createCommentForEventMutationHandler
|
||||
);
|
||||
mockClient.setRequestHandler(
|
||||
CURRENT_ACTOR_CLIENT,
|
||||
requestHandlers.getCurrentActorClientHandler
|
||||
);
|
||||
mockClient.setRequestHandler(IDENTITIES, requestHandlers.identityHandler);
|
||||
wrapper = shallowMount(CommentTree, {
|
||||
props: {
|
||||
event: { ...eventData },
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`CommentTree > renders a comment tree with comments 1`] = `
|
||||
"<div data-v-5d0380ab="">
|
||||
<form data-v-5d0380ab="" class="mt-2">
|
||||
<!--v-if-->
|
||||
<article data-v-5d0380ab="" class="flex flex-wrap items-start gap-2">
|
||||
<figure data-v-5d0380ab="" class="">
|
||||
<identity-picker-wrapper-stub data-v-5d0380ab="" modelvalue="[object Object]" inline="false" masked="false"></identity-picker-wrapper-stub>
|
||||
</figure>
|
||||
<div data-v-5d0380ab="" class="flex-1">
|
||||
<div data-v-5d0380ab="" class="flex flex-col gap-2">
|
||||
<div data-v-5d0380ab="" class="editor-wrapper">
|
||||
<editor-stub data-v-5d0380ab="" currentactor="[object Object]" mode="comment" modelvalue="" aria-label="Comment body" placeholder="Write a new comment"></editor-stub>
|
||||
<!--v-if-->
|
||||
</div>
|
||||
<!--v-if-->
|
||||
</div>
|
||||
</div>
|
||||
<div data-v-5d0380ab="" class="">
|
||||
<o-button-stub data-v-5d0380ab="" tag="button" variant="primary" iconleft="send" rounded="false" expanded="false" disabled="false" outlined="false" loading="false" inverted="false" nativetype="submit" role="button" iconboth="false"></o-button-stub>
|
||||
</div>
|
||||
</article>
|
||||
</form>
|
||||
<transition-group-stub data-v-5d0380ab="" tag="div" name="comment-empty-list" appear="false" persisted="false" css="true" class="mt-2">
|
||||
<transition-group-stub data-v-5d0380ab="" name="comment-list" tag="ul" appear="false" persisted="false" css="true" class="comment-list">
|
||||
<event-comment-stub data-v-5d0380ab="" comment="[object Object]" event="[object Object]" currentactor="[object Object]" rootcomment="true" readonly="false" class="root-comment my-2"></event-comment-stub>
|
||||
<event-comment-stub data-v-5d0380ab="" comment="[object Object]" event="[object Object]" currentactor="[object Object]" rootcomment="true" readonly="false" class="root-comment my-2"></event-comment-stub>
|
||||
</transition-group-stub>
|
||||
</transition-group-stub>
|
||||
</div>"
|
||||
`;
|
||||
|
||||
exports[`CommentTree > renders a loading comment tree 1`] = `
|
||||
"<div data-v-5d0380ab="">
|
||||
<!--v-if-->
|
||||
@@ -9,7 +40,26 @@ exports[`CommentTree > renders a loading comment tree 1`] = `
|
||||
|
||||
exports[`CommentTree > renders an empty comment tree 1`] = `
|
||||
"<div data-v-5d0380ab="">
|
||||
<form data-v-5d0380ab="" class="mt-2">
|
||||
<!--v-if-->
|
||||
<article data-v-5d0380ab="" class="flex flex-wrap items-start gap-2">
|
||||
<figure data-v-5d0380ab="" class="">
|
||||
<identity-picker-wrapper-stub data-v-5d0380ab="" modelvalue="[object Object]" inline="false" masked="false"></identity-picker-wrapper-stub>
|
||||
</figure>
|
||||
<div data-v-5d0380ab="" class="flex-1">
|
||||
<div data-v-5d0380ab="" class="flex flex-col gap-2">
|
||||
<div data-v-5d0380ab="" class="editor-wrapper">
|
||||
<editor-stub data-v-5d0380ab="" currentactor="[object Object]" mode="comment" modelvalue="" aria-label="Comment body" placeholder="Write a new comment"></editor-stub>
|
||||
<!--v-if-->
|
||||
</div>
|
||||
<!--v-if-->
|
||||
</div>
|
||||
</div>
|
||||
<div data-v-5d0380ab="" class="">
|
||||
<o-button-stub data-v-5d0380ab="" tag="button" variant="primary" iconleft="send" rounded="false" expanded="false" disabled="false" outlined="false" loading="false" inverted="false" nativetype="submit" role="button" iconboth="false"></o-button-stub>
|
||||
</div>
|
||||
</article>
|
||||
</form>
|
||||
<transition-group-stub data-v-5d0380ab="" tag="div" name="comment-empty-list" appear="false" persisted="false" css="true" class="mt-2">
|
||||
<empty-content-stub data-v-5d0380ab="" icon="comment" descriptionclasses="" inline="true" center="false"></empty-content-stub>
|
||||
</transition-group-stub>
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("ParticipationWithoutAccount", () => {
|
||||
) => {
|
||||
mockClient = createMockClient({
|
||||
cache,
|
||||
resolvers: defaultResolvers,
|
||||
resolvers: defaultResolvers(cache),
|
||||
});
|
||||
requestHandlers = {
|
||||
anonymousActorIdQueryHandler: vi
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { fakeCurrentActorData } from "../common";
|
||||
|
||||
export const loginMock = {
|
||||
email: "some@email.tld",
|
||||
password: "somepassword",
|
||||
@@ -42,3 +44,13 @@ export const nullIdentityMock = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const defaultIdentityMock = {
|
||||
data: {
|
||||
loggedUser: {
|
||||
__typename: "loggedUser",
|
||||
id: 1,
|
||||
actors: [fakeCurrentActorData()],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -51,19 +51,6 @@ export const joinEventResponseMock = {
|
||||
},
|
||||
};
|
||||
|
||||
export const currentActorClientMock = {
|
||||
data: {
|
||||
actor: {
|
||||
__typename: "Person",
|
||||
preferredUsername: "some_actor",
|
||||
name: "Some actor",
|
||||
avatar: null,
|
||||
domain: null,
|
||||
id: "1",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const joinEventMock = {
|
||||
eventId: "1",
|
||||
actorId: "1",
|
||||
|
||||
Reference in New Issue
Block a user