2022-07-12 10:55:28 +02:00
import { config , mount , VueWrapper } from "@vue/test-utils" ;
2020-12-04 15:12:00 +01:00
import ParticipationSection from "@/components/Participation/ParticipationSection.vue" ;
2022-07-12 10:55:28 +02:00
import { createRouter , createWebHistory , Router } from "vue-router" ;
2020-12-04 15:12:00 +01:00
import { routes } from "@/router" ;
2020-12-04 16:44:37 +01:00
import { CommentModeration , EventJoinOptions } from "@/types/enums" ;
2021-05-12 18:10:07 +02:00
import { InMemoryCache } from "@apollo/client/cache" ;
2023-05-26 17:35:52 +02:00
import { beforeEach , describe , expect , it } from "vitest" ;
2022-07-12 10:55:28 +02:00
import Oruga from "@oruga-ui/oruga-next" ;
import FloatingVue from "floating-vue" ;
2020-12-04 15:12:00 +01:00
2022-07-12 10:55:28 +02:00
config . global . plugins . push ( Oruga ) ;
config . global . plugins . push ( FloatingVue ) ;
2020-12-04 15:12:00 +01:00
2022-07-12 10:55:28 +02:00
let router : Router ;
beforeEach ( async ( ) = > {
router = createRouter ( {
history : createWebHistory ( ) ,
routes : routes ,
} ) ;
// await router.isReady();
} ) ;
2020-12-04 15:12:00 +01:00
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" , ( ) = > {
2022-07-12 10:55:28 +02:00
let wrapper : VueWrapper ;
2020-12-04 15:12:00 +01:00
2023-05-26 17:35:52 +02:00
const generateWrapper = ( customProps : Record < string , unknown > = { } ) = > {
2020-12-04 15:12:00 +01:00
wrapper = mount ( ParticipationSection , {
2021-06-04 20:24:43 +02:00
stubs : {
ParticipationButton : true ,
} ,
2022-07-12 10:55:28 +02:00
props : {
2020-12-04 15:12:00 +01:00
participation : null ,
event : eventData ,
anonymousParticipation : null ,
2022-07-12 10:55:28 +02:00
currentActor : { id : "5" } ,
identities : [ ] ,
anonymousParticipationConfig : {
allowed : true ,
} ,
2020-12-04 15:12:00 +01:00
. . . customProps ,
} ,
2022-07-12 10:55:28 +02:00
global : {
plugins : [ router ] ,
2020-12-04 15:12:00 +01:00
} ,
} ) ;
} ;
it ( "renders the participation section with minimal data" , async ( ) = > {
generateWrapper ( ) ;
await wrapper . vm . $nextTick ( ) ;
expect ( wrapper . exists ( ) ) . toBe ( true ) ;
expect ( wrapper . find ( ".event-participation" ) . exists ( ) ) . toBeTruthy ( ) ;
2021-06-04 20:24:43 +02: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 15:12:00 +01:00
2021-06-04 20:24:43 +02:00
// expect(participationButton.text()).toBe("Participate");
2020-12-04 15:12:00 +01:00
} ) ;
it ( "renders the participation section with existing confimed anonymous participation" , async ( ) = > {
2022-07-12 10:55:28 +02:00
generateWrapper ( { anonymousParticipation : true } ) ;
2020-12-04 15:12:00 +01:00
expect ( wrapper . find ( ".event-participation > small" ) . text ( ) ) . toContain (
"You are participating in this event anonymously"
) ;
const cancelAnonymousParticipationButton = wrapper . find (
2022-07-12 10:55:28 +02:00
".event-participation > button.o-btn--text"
2020-12-04 15:12:00 +01:00
) ;
expect ( cancelAnonymousParticipationButton . text ( ) ) . toBe (
"Cancel anonymous participation"
) ;
2020-12-04 16:44:37 +01:00
2022-08-26 16:08:58 +02:00
wrapper . find ( ".event-participation small span" ) . trigger ( "click" ) ;
2020-12-04 16:44:37 +01:00
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 ( ) = > {
2022-07-12 10:55:28 +02:00
generateWrapper ( {
anonymousParticipation : true ,
event : { . . . eventData , joinOptions : EventJoinOptions.RESTRICTED } ,
} ) ;
2020-12-04 16:44:37 +01:00
expect ( wrapper . find ( ".event-participation > small" ) . text ( ) ) . toContain (
"You are participating in this event anonymously"
) ;
const cancelAnonymousParticipationButton = wrapper . find (
2022-07-12 10:55:28 +02:00
".event-participation > button.o-btn--text"
2020-12-04 16:44:37 +01:00
) ;
expect ( cancelAnonymousParticipationButton . text ( ) ) . toBe (
"Cancel anonymous participation"
) ;
2022-08-26 16:08:58 +02:00
wrapper . find ( ".event-participation small span" ) . trigger ( "click" ) ;
2020-12-04 16:44:37 +01:00
await wrapper . vm . $nextTick ( ) ;
const modal = wrapper . findComponent ( {
ref : "anonymous-participation-modal" ,
} ) ;
expect ( modal . isVisible ( ) ) . toBeTruthy ( ) ;
2022-07-12 10:55:28 +02:00
expect ( modal . find ( ".o-notification--primary" ) . text ( ) ) . toBe (
2020-12-04 16:53:55 +01: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 16:44:37 +01:00
) ;
2020-12-04 15:12:00 +01: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 ( ) = > {
2022-07-12 10:55:28 +02:00
generateWrapper ( { anonymousParticipation : false } ) ;
2020-12-04 15:12:00 +01:00
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 ( ) = > {
2022-07-12 10:55:28 +02:00
generateWrapper ( {
event : {
. . . eventData ,
beginsOn : "2020-12-02T10:52:56Z" ,
endsOn : "2020-12-03T10:52:56Z" ,
} ,
} ) ;
2020-12-04 15:12:00 +01:00
expect ( wrapper . find ( ".event-participation" ) . exists ( ) ) . toBeFalsy ( ) ;
2022-07-12 10:55:28 +02:00
expect ( wrapper . find ( "button.o-btn--primary" ) . text ( ) ) . toBe (
2020-12-04 15:12:00 +01:00
"Event already passed"
) ;
} ) ;
} ) ;