2020-12-04 14:12:00 +00:00
import { config , createLocalVue , mount , Wrapper } from "@vue/test-utils" ;
import ParticipationSection from "@/components/Participation/ParticipationSection.vue" ;
import Buefy from "buefy" ;
import VueRouter from "vue-router" ;
import { routes } from "@/router" ;
2020-12-04 15:44:37 +00:00
import { CommentModeration , EventJoinOptions } from "@/types/enums" ;
2020-12-04 14:12:00 +00:00
import {
createMockClient ,
MockApolloClient ,
RequestHandler ,
} from "mock-apollo-client" ;
import { CONFIG } from "@/graphql/config" ;
2021-06-11 12:21:27 +00:00
import VueApollo from "@vue/apollo-option" ;
2020-12-04 14:12:00 +00:00
import { configMock } from "../../mocks/config" ;
2021-05-12 16:10:07 +00:00
import { InMemoryCache } from "@apollo/client/cache" ;
2021-06-04 18:24:43 +00:00
import { defaultResolvers } from "../../common" ;
2020-12-04 14:12:00 +00:00
const localVue = createLocalVue ( ) ;
localVue . use ( Buefy ) ;
localVue . use ( VueRouter ) ;
const router = new VueRouter ( { routes , mode : "history" } ) ;
config . mocks . $t = ( key : string ) : string = > key ;
const eventData = {
id : "1" ,
uuid : "e37910ea-fd5a-4756-7634-00971f3f4107" ,
options : {
commentModeration : CommentModeration.ALLOW_ALL ,
} ,
beginsOn : new Date ( "2089-12-04T09:21:25Z" ) ,
endsOn : new Date ( "2089-12-04T11:21:25Z" ) ,
} ;
describe ( "ParticipationSection" , ( ) = > {
let wrapper : Wrapper < Vue > ;
let mockClient : MockApolloClient ;
let apolloProvider ;
let requestHandlers : Record < string , RequestHandler > ;
const generateWrapper = (
handlers : Record < string , unknown > = { } ,
customProps : Record < string , unknown > = { } ,
baseData : Record < string , unknown > = { }
) = > {
2021-06-04 18:24:43 +00:00
const cache = new InMemoryCache ( { addTypename : false } ) ;
2020-12-04 14:12:00 +00:00
mockClient = createMockClient ( {
cache ,
2021-06-04 18:24:43 +00:00
resolvers : defaultResolvers ,
2020-12-04 14:12:00 +00:00
} ) ;
requestHandlers = {
configQueryHandler : jest.fn ( ) . mockResolvedValue ( configMock ) ,
. . . handlers ,
} ;
mockClient . setRequestHandler ( CONFIG , requestHandlers . configQueryHandler ) ;
apolloProvider = new VueApollo ( {
defaultClient : mockClient ,
} ) ;
wrapper = mount ( ParticipationSection , {
localVue ,
router ,
apolloProvider ,
2021-06-04 18:24:43 +00:00
stubs : {
ParticipationButton : true ,
} ,
2020-12-04 14:12:00 +00:00
propsData : {
participation : null ,
event : eventData ,
anonymousParticipation : null ,
. . . customProps ,
} ,
data() {
return {
. . . baseData ,
} ;
} ,
} ) ;
} ;
it ( "renders the participation section with minimal data" , async ( ) = > {
generateWrapper ( ) ;
await wrapper . vm . $nextTick ( ) ;
expect ( wrapper . exists ( ) ) . toBe ( true ) ;
expect ( requestHandlers . configQueryHandler ) . toHaveBeenCalled ( ) ;
expect ( wrapper . vm . $apollo . queries . config ) . toBeTruthy ( ) ;
expect ( wrapper . find ( ".event-participation" ) . exists ( ) ) . toBeTruthy ( ) ;
2021-06-04 18:24:43 +00:00
// TODO: Move to participation button test
// const participationButton = wrapper.find(
// ".event-participation .participation-button a.button.is-large.is-primary"
// );
// expect(participationButton.attributes("href")).toBe(
// `/events/${eventData.uuid}/participate/with-account`
// );
2020-12-04 14:12:00 +00:00
2021-06-04 18:24:43 +00:00
// expect(participationButton.text()).toBe("Participate");
2020-12-04 14:12:00 +00:00
} ) ;
it ( "renders the participation section with existing confimed anonymous participation" , async ( ) = > {
generateWrapper ( { } , { anonymousParticipation : true } ) ;
expect ( wrapper . find ( ".event-participation > small" ) . text ( ) ) . toContain (
"You are participating in this event anonymously"
) ;
const cancelAnonymousParticipationButton = wrapper . find (
".event-participation > button.button.is-text"
) ;
expect ( cancelAnonymousParticipationButton . text ( ) ) . toBe (
"Cancel anonymous participation"
) ;
2020-12-04 15:44:37 +00:00
wrapper . find ( ".event-participation small .is-clickable" ) . trigger ( "click" ) ;
expect (
wrapper
. findComponent ( { ref : "anonymous-participation-modal" } )
. isVisible ( )
) . toBeTruthy ( ) ;
cancelAnonymousParticipationButton . trigger ( "click" ) ;
await wrapper . vm . $nextTick ( ) ;
expect ( wrapper . emitted ( "cancel-anonymous-participation" ) ) . toBeTruthy ( ) ;
} ) ;
it ( "renders the participation section with existing confimed anonymous participation but event moderation" , async ( ) = > {
generateWrapper (
{ } ,
{
anonymousParticipation : true ,
event : { . . . eventData , joinOptions : EventJoinOptions.RESTRICTED } ,
}
) ;
expect ( wrapper . find ( ".event-participation > small" ) . text ( ) ) . toContain (
"You are participating in this event anonymously"
) ;
const cancelAnonymousParticipationButton = wrapper . find (
".event-participation > button.button.is-text"
) ;
expect ( cancelAnonymousParticipationButton . text ( ) ) . toBe (
"Cancel anonymous participation"
) ;
wrapper . find ( ".event-participation small .is-clickable" ) . trigger ( "click" ) ;
await wrapper . vm . $nextTick ( ) ;
const modal = wrapper . findComponent ( {
ref : "anonymous-participation-modal" ,
} ) ;
expect ( modal . isVisible ( ) ) . toBeTruthy ( ) ;
expect ( modal . find ( "article.notification.is-primary" ) . text ( ) ) . toBe (
2020-12-04 15:53:55 +00:00
"As the event organizer has chosen to manually validate participation requests, your participation will be really confirmed only once you receive an email stating it's being accepted."
2020-12-04 15:44:37 +00:00
) ;
2020-12-04 14:12:00 +00:00
cancelAnonymousParticipationButton . trigger ( "click" ) ;
await wrapper . vm . $nextTick ( ) ;
expect ( wrapper . emitted ( "cancel-anonymous-participation" ) ) . toBeTruthy ( ) ;
} ) ;
it ( "renders the participation section with existing unconfirmed anonymous participation" , async ( ) = > {
generateWrapper ( { } , { anonymousParticipation : false } ) ;
expect ( wrapper . find ( ".event-participation > small" ) . text ( ) ) . toContain (
"You are participating in this event anonymously but didn't confirm participation"
) ;
} ) ;
it ( "renders the participation section but the event is already passed" , async ( ) = > {
generateWrapper (
{ } ,
{
event : {
. . . eventData ,
beginsOn : "2020-12-02T10:52:56Z" ,
endsOn : "2020-12-03T10:52:56Z" ,
} ,
}
) ;
expect ( wrapper . find ( ".event-participation" ) . exists ( ) ) . toBeFalsy ( ) ;
expect ( wrapper . find ( "button.button.is-primary" ) . text ( ) ) . toBe (
"Event already passed"
) ;
} ) ;
} ) ;