summaryrefslogtreecommitdiff
path: root/cypress/e2e/event.cy.ts
blob: eeaa62911bf8eee167577d5f2f289f0e08309b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import eventData from "../fixtures/eventData.json";
import crypto from "crypto";

describe("Events", () => {
    beforeEach(() => {
        cy.visit("/new");
        cy.get("#showNewEventFormButton").click();

        cy.get("#eventName").type(eventData.eventName);
        cy.get("#eventLocation").type(eventData.eventLocation);
        // These are datetime-local inputs
        cy.get("#eventStart").type(eventData.eventStart);
        cy.get("#eventEnd").type(eventData.eventEnd);

        cy.get("select#timezone + span.select2").click();
        cy.get(".select2-results__option")
            .contains(eventData.timezone)
            .click({ force: true });

        cy.get("#eventDescription").type(eventData.eventDescription);
        cy.get("#eventURL").type(eventData.eventURL);

        cy.get("#hostName").type(eventData.hostName);
        cy.get("#creatorEmail").type(eventData.creatorEmail);

        if (eventData.interactionCheckbox) {
            cy.get("#interactionCheckbox").check();
        }

        if (eventData.joinCheckbox) {
            cy.get("#joinCheckbox").check();
        }

        if (eventData.maxAttendeesCheckbox) {
            cy.get("#maxAttendeesCheckbox").check();
            cy.get("#maxAttendees").type(eventData.maxAttendees.toString());
        }

        // Submit the form
        cy.get("#newEventFormSubmit").click();

        // Wait for the new page to load
        cy.url({ timeout: 10000 }).should("not.include", "/new");

        // Get the new event ID from the URL
        cy.url().then((url) => {
            const [eventID, editToken] = url.split("/").pop().split("?");
            cy.wrap(eventID).as("eventID");
            cy.wrap(editToken).as("editToken");
        });
    });
    it("creates a new event", function () {
        // Check that all the data is correct
        cy.get(".p-name").should("have.text", eventData.eventName);
        cy.get(".p-location").should("have.text", eventData.eventLocation);
        cy.get(".p-summary").should("contain.text", eventData.eventDescription);
        cy.get("#hosted-by").should(
            "contain.text",
            `Hosted by ${eventData.hostName}`,
        );
        cy.get("#attendees-alert").should("contain.text", "10 spots remaining");
        cy.get(".dt-duration").should(
            "contain.text",
            "Tuesday 1 January 2030 from 12:00 am to 1:00 am (EST)",
        );
    });

    it("allows you to attend an event - visible in public list", function () {
        cy.get("button#attendEvent").click();
        cy.get("#attendeeName").type("Test Attendee");
        cy.get("#attendeeNumber").focus().clear();
        cy.get("#attendeeNumber").type("2");
        cy.get("form#attendEventForm").submit();
        cy.get("#attendees-alert").should("contain.text", "8 spots remaining");
        cy.get(".attendeesList").should(
            "contain.text",
            "Test Attendee (2 people)",
        );
    });

    it("allows you to attend an event - hidden from public list", function () {
        cy.get("button#attendEvent").click();
        cy.get("#attendeeName").type("Test Attendee");
        cy.get("#attendeeNumber").focus().clear();
        cy.get("#attendeeNumber").type("2");
        cy.get("#attendeeVisible").uncheck();
        cy.get("form#attendEventForm").submit();
        cy.get("#attendees-alert").should("contain.text", "8 spots remaining");
        cy.get(".attendeesList").should(
            "contain.text",
            "Test Attendee (2 people) (hidden from public list)",
        );
    });

    it("allows you to comment on an event", function () {
        cy.get("#commentAuthor").type("Test Author");
        cy.get("#commentContent").type("Test Comment");
        cy.get("#postComment").click();
        cy.get(".comment").should("contain.text", "Test Author");
        cy.get(".comment").should("contain.text", "Test Comment");
    });

    it("displays the ActivityPub featured post", function () {
        cy.log(this.eventID);

        cy.request({
            url: `/${this.eventID}/featured`,
            headers: {
                Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
            },
        }).then((response) => {
            expect(response.body).to.have.property("@context");
            expect(response.body).to.have.property("id");
            expect(response.body).to.have.property("type");
            expect(response.body).to.have.property("orderedItems");
            expect(response.body.orderedItems)
                .to.be.an("array")
                .and.to.have.lengthOf(1);
            const featuredPost = response.body.orderedItems[0];
            expect(featuredPost).to.have.property("@context");
            expect(featuredPost).to.have.property("id");
            expect(featuredPost).to.have.property("type");
            expect(featuredPost).to.have.property("name");
            expect(featuredPost).to.have.property("content");
            expect(featuredPost).to.have.property("attributedTo");
        });
    });

    it("responds correctly to ActivityPub webfinger requests", function () {
        cy.request({
            url: `/.well-known/webfinger?resource=acct:${
                this.eventID
            }@${Cypress.env("CYPRESS_DOMAIN")}`,
            headers: {
                Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
            },
        }).then((response) => {
            expect(response.body).to.have.property("subject");
            expect(response.body).to.have.property("links");
            expect(response.body.links)
                .to.be.an("array")
                .and.to.have.lengthOf(1);
            const link = response.body.links[0];
            expect(link).to.have.property("rel");
            expect(link).to.have.property("type");
            expect(link).to.have.property("href");
        });
    });

    it("edits an event", function () {
        cy.get("#editEvent").click();

        // The edit form is the same as the new form, so we can just re-use the same selectors
        // but we need to clear the fields first
        cy.get("#editEventForm #eventName").focus().clear();
        cy.get("#editEventForm #eventLocation").focus().clear();
        cy.get("#editEventForm #eventStart").focus().clear();
        cy.get("#editEventForm #eventEnd").focus().clear();
        cy.get("#editEventForm #eventDescription").focus().clear();
        cy.get("#editEventForm #eventURL").focus().clear();
        cy.get("#editEventForm #hostName").focus().clear();
        cy.get("#editEventForm #creatorEmail").focus().clear();
        cy.get("#editEventForm #maxAttendees").focus().clear();

        cy.get("#editEventForm #eventName").type("Edited Event Name");
        cy.get("#editEventForm #eventLocation").type("Edited Event Location");
        // These are datetime-local inputs
        cy.get("#editEventForm #eventStart").type("2030-12-01T00:00");
        cy.get("#editEventForm #eventEnd").type("2030-12-01T01:00");

        cy.get("#editEventForm select#timezone + span.select2").click();
        cy.get(".select2-results__option")
            .contains("Australia/Sydney")
            .click({ force: true });

        cy.get("#editEventForm #eventDescription").type(
            "Edited Event Description",
        );
        cy.get("#editEventForm #eventURL").type("https://edited.example.com");
        cy.get("#editEventForm #hostName").type("Edited Name");
        cy.get("#editEventForm #creatorEmail").type("edited@example.com");

        cy.get("#editEventForm #maxAttendeesCheckbox").uncheck();

        cy.get("#editEventForm #interactionCheckbox").uncheck();

        cy.get("#editEventForm #joinCheckbox").uncheck();

        // Submit the form
        cy.get("#editEventForm").submit();

        // Wait for the modal to not be visible
        cy.get("#editModal").should("not.be.visible");

        // Check that all the data is correct
        cy.get(".p-name").should("have.text", "Edited Event Name");
        cy.get(".p-location").should("have.text", "Edited Event Location");
        cy.get(".p-summary").should("contain.text", "Edited Event Description");
        cy.get("#hosted-by").should("contain.text", "Hosted by Edited Name");
        cy.get(".dt-duration").should(
            "contain.text",
            "Sunday 1 December 2030 from 12:00 am to 1:00 am",
        );
        cy.get(".dt-duration")
            .invoke("text")
            .should("match", /AE(D|S)T/);
        // Check that the comment form is not visible
        cy.get("#postComment").should("not.exist");
        // Check that the attendee form is not visible
        cy.get("#attendEvent").should("not.exist");
    });

    it("sets a group for an event", function () {
        // For this we need to create a group first. This will load the group edit token
        // into our localStorage, and will then appear in the group select dropdown.
        // We then go back to the event page, edit the event, and set the group.
        cy.createGroup({
            eventGroupName: "Test Group",
            eventGroupDescription: "Test Group Description",
            eventGroupURL: "https://example.com",
            hostName: "Test Host",
            creatorEmail: "test@example.com",
        });

        cy.visit(`/${this.eventID}`);
        cy.url().should("include", this.editToken);

        cy.get("#editEvent").click();
        cy.get("#editEventForm #eventGroupCheckbox").check();
        cy.get("select#eventGroupSelect + span.select2").click();
        cy.get(".select2-results__option")
            .contains("Test Group")
            .click({ force: true });
        cy.get("#editEventForm").submit();

        cy.get("#editModal").should("not.be.visible");

        cy.get("#event-group").should("contain.text", "Test Group");
    });

    it("removes you from the event with a one-click unattend link", function () {
        cy.get("button#attendEvent").click();
        cy.get("#attendeeName").type("Test Attendee");
        cy.get("#attendeeNumber").focus().clear();
        cy.get("#attendeeNumber").type("2");
        cy.get("#removalPassword")
            .invoke("val")
            .then((removalPassword) => {
                cy.wrap(removalPassword).as("removalPassword");
                cy.log(this.removalPassword);
                cy.get("form#attendEventForm").submit();
                cy.get("#attendees-alert").should(
                    "contain.text",
                    "8 spots remaining",
                );
                cy.get(".attendeesList").should(
                    "contain.text",
                    "Test Attendee (2 people)",
                );
                const removalPasswordHash = crypto
                    .createHash("sha256")
                    .update(removalPassword)
                    .digest("hex");
                const unattendLink = `http://localhost:3000/event/${this.eventID}/unattend/${removalPasswordHash}`;
                cy.visit(unattendLink);
                cy.get("#event__message").should(
                    "contain.text",
                    "You have been removed from this event.",
                );
                cy.get("#attendees-alert").should(
                    "contain.text",
                    "10 spots remaining",
                );
                cy.get("#eventAttendees").should(
                    "contain.text",
                    "No attendees yet!",
                );
            });
    });
    describe("Query string editing tokens", function () {
        it("given a valid editing token is in the URL, should add it to localStorage", function () {
            cy.visit(`/${this.eventID}?${this.editToken}`).then(() => {
                expect(localStorage.getItem("editTokens")).to.include(
                    this.editToken.split("=")[1],
                );
            });
        });

        it("given an invalid editing token is in the URL, should delete it from the URL", function () {
            cy.visit(`/${this.eventID}?e=invalid`).then(() => {
                expect(localStorage.getItem("editTokens")).to.not.include(
                    "invalid",
                );
            });
        });

        it("given a valid editing token in localStorage, should add it to the URL", function () {
            cy.visit(`/${this.eventID}`).then(() => {
                cy.url().should("include", this.editToken);
            });
        });

        it("given an invalid editing token in localStorage, should remove it from localStorage", function () {
            cy.clearAllLocalStorage();
            localStorage.setItem("editTokens", "invalid");
            cy.visit(`/${this.eventID}`).then(() => {
                expect(localStorage.getItem("editTokens")).to.not.include(
                    "invalid",
                );
            });
        });
    });
});