diff options
| author | Raphael Kabo <raphaelkabo@hey.com> | 2024-02-26 12:10:32 +0000 | 
|---|---|---|
| committer | Raphael Kabo <raphaelkabo@hey.com> | 2024-02-26 12:10:32 +0000 | 
| commit | 9e11c3667e027f805fca37b5dffe9d8a52303a14 (patch) | |
| tree | 58a2369cde40717bb6b34273566f3e31ab8c9932 | |
| parent | c93fd6e2d455ea4208f9e5ca6bfbd1c0e9fd1ad9 (diff) | |
testing: E2E tests for public and restricted events
| -rw-r--r-- | cypress/e2e/event.cy.ts | 24 | ||||
| -rw-r--r-- | cypress/e2e/group.cy.ts | 10 | ||||
| -rw-r--r-- | cypress/e2e/magicLink.cy.ts | 14 | ||||
| -rw-r--r-- | cypress/e2e/publicEvent.cy.ts | 75 | ||||
| -rw-r--r-- | cypress/e2e/publicGroup.cy.ts | 28 | ||||
| -rw-r--r-- | cypress/fixtures/eventData.json | 16 | ||||
| -rw-r--r-- | cypress/fixtures/example.json | 5 | ||||
| -rw-r--r-- | cypress/fixtures/groupData.json | 7 | ||||
| -rw-r--r-- | cypress/support/commands.ts | 23 | ||||
| -rw-r--r-- | cypress/tsconfig.json | 4 | 
10 files changed, 161 insertions, 45 deletions
diff --git a/cypress/e2e/event.cy.ts b/cypress/e2e/event.cy.ts index 8870164..c49c518 100644 --- a/cypress/e2e/event.cy.ts +++ b/cypress/e2e/event.cy.ts @@ -1,19 +1,4 @@ -const eventData = { -    eventName: "Your Event Name", -    eventLocation: "Event Location", -    timezone: "America/New York", -    eventDescription: "Event Description", -    eventURL: "https://example.com", -    hostName: "Your Name", -    creatorEmail: "test@example.com", -    eventGroupCheckbox: false, -    interactionCheckbox: true, -    joinCheckbox: true, -    maxAttendeesCheckbox: true, -    maxAttendees: 10, -    eventStart: "2030-01-01T00:00", -    eventEnd: "2030-01-01T01:00", -}; +import eventData from "../fixtures/eventData.json";  describe("Events", () => {      beforeEach(() => { @@ -37,13 +22,6 @@ describe("Events", () => {          cy.get("#hostName").type(eventData.hostName);          cy.get("#creatorEmail").type(eventData.creatorEmail); -        // Check checkboxes based on eventData -        if (eventData.eventGroupCheckbox) { -            cy.get("#eventGroupCheckbox").check(); -            cy.get("#eventGroupID").type(eventData.eventGroupID); -            cy.get("#eventGroupEditToken").type(eventData.eventGroupEditToken); -        } -          if (eventData.interactionCheckbox) {              cy.get("#interactionCheckbox").check();          } diff --git a/cypress/e2e/group.cy.ts b/cypress/e2e/group.cy.ts index 279cb6c..69c722a 100644 --- a/cypress/e2e/group.cy.ts +++ b/cypress/e2e/group.cy.ts @@ -1,14 +1,8 @@ -const groupData = { -    eventGroupName: "Test Group", -    eventGroupDescription: "Test Group Description", -    eventGroupURL: "https://example.com", -    hostName: "Test Host", -    creatorEmail: "test@example.com", -}; +import groupData from "../fixtures/groupData.json";  describe("Groups", () => {      beforeEach(() => { -        cy.createGroup(groupData); +        cy.createGroup(groupData, false);      });      it("creates a new group", function () {          cy.get("#eventGroupName").should("have.text", groupData.eventGroupName); diff --git a/cypress/e2e/magicLink.cy.ts b/cypress/e2e/magicLink.cy.ts new file mode 100644 index 0000000..5540415 --- /dev/null +++ b/cypress/e2e/magicLink.cy.ts @@ -0,0 +1,14 @@ +describe("Restricted Event Creation", () => { +    it("should redirect to the magic link form", () => { +        cy.setCookie( +            "cypressConfigOverride", +            JSON.stringify({ +                general: { +                    creator_email_addresses: ["test@test.com"], +                }, +            }), +        ); +        cy.visit("/new"); +        cy.get("h2").should("contain", "Request a link to create a new event"); +    }); +}); diff --git a/cypress/e2e/publicEvent.cy.ts b/cypress/e2e/publicEvent.cy.ts new file mode 100644 index 0000000..f110c02 --- /dev/null +++ b/cypress/e2e/publicEvent.cy.ts @@ -0,0 +1,75 @@ +import eventData from "../fixtures/eventData.json"; + +describe("Events", () => { +    beforeEach(() => { +        cy.setCookie( +            "cypressConfigOverride", +            JSON.stringify({ +                general: { +                    show_public_event_list: true, +                }, +            }), +        ); +        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); + +        // Check checkboxes based on eventData +        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()); +        } + +        cy.get("#publicEventCheckbox").check(); + +        // 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("should be visible in the public event list", function () { +        cy.setCookie( +            "cypressConfigOverride", +            JSON.stringify({ +                general: { +                    show_public_event_list: true, +                }, +            }), +        ); +        cy.visit("/"); +        cy.get("#upcomingEvents").should("contain", eventData.eventName); +    }); +}); diff --git a/cypress/e2e/publicGroup.cy.ts b/cypress/e2e/publicGroup.cy.ts new file mode 100644 index 0000000..4536195 --- /dev/null +++ b/cypress/e2e/publicGroup.cy.ts @@ -0,0 +1,28 @@ +import groupData from "../fixtures/groupData.json"; + +describe("Groups", () => { +    beforeEach(() => { +        cy.setCookie( +            "cypressConfigOverride", +            JSON.stringify({ +                general: { +                    show_public_event_list: true, +                }, +            }), +        ); +        cy.createGroup(groupData, true); +    }); +    it("should be visible in the public group list", function () { +        cy.setCookie( +            "cypressConfigOverride", +            JSON.stringify({ +                general: { +                    show_public_event_list: true, +                }, +            }), +        ); +        cy.visit("/"); +        cy.get("#groupsTab").click(); +        cy.get("#eventGroups").should("contain", groupData.eventGroupName); +    }); +}); diff --git a/cypress/fixtures/eventData.json b/cypress/fixtures/eventData.json new file mode 100644 index 0000000..a38ccf2 --- /dev/null +++ b/cypress/fixtures/eventData.json @@ -0,0 +1,16 @@ +{ +    "eventName": "Your Event Name", +    "eventLocation": "Event Location", +    "timezone": "America/New York", +    "eventDescription": "Event Description", +    "eventURL": "https://example.com", +    "hostName": "Your Name", +    "creatorEmail": "test@example.com", +    "eventGroupCheckbox": false, +    "interactionCheckbox": true, +    "joinCheckbox": true, +    "maxAttendeesCheckbox": true, +    "maxAttendees": 10, +    "eventStart": "2030-01-01T00:00", +    "eventEnd": "2030-01-01T01:00" +} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index 519902d..0000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -    "name": "Using fixtures to represent data", -    "email": "hello@cypress.io", -    "body": "Fixtures are a great way to mock data for responses to routes" -} diff --git a/cypress/fixtures/groupData.json b/cypress/fixtures/groupData.json new file mode 100644 index 0000000..907c3b2 --- /dev/null +++ b/cypress/fixtures/groupData.json @@ -0,0 +1,7 @@ +{ +    "eventGroupName": "Test Group", +    "eventGroupDescription": "Test Group Description", +    "eventGroupURL": "https://example.com", +    "hostName": "Test Host", +    "creatorEmail": "test@example.com" +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 7535103..eadcd20 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -38,17 +38,20 @@  declare namespace Cypress {      interface Chainable<Subject> { -        createGroup(groupData: { -            eventGroupName: string; -            eventGroupDescription: string; -            eventGroupURL: string; -            hostName: string; -            creatorEmail: string; -        }): Chainable<Subject>; +        createGroup( +            groupData: { +                eventGroupName: string; +                eventGroupDescription: string; +                eventGroupURL: string; +                hostName: string; +                creatorEmail: string; +            }, +            isPublic: boolean, +        ): Chainable<Subject>;      }  } -Cypress.Commands.add("createGroup", (groupData) => { +Cypress.Commands.add("createGroup", (groupData, isPublic) => {      cy.visit("/new");      cy.get("#showNewEventGroupFormButton").click(); @@ -59,6 +62,10 @@ Cypress.Commands.add("createGroup", (groupData) => {      cy.get("#eventGroupHostName").type(groupData.hostName);      cy.get("#eventGroupCreatorEmail").type(groupData.creatorEmail); +    if (isPublic) { +        cy.get("#publicGroupCheckbox").check(); +    } +      // Submit the form      cy.get("#newEventGroupForm").submit(); diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index dc61836..9a8b8a0 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,7 +2,9 @@      "compilerOptions": {          "target": "es5",          "lib": ["es5", "dom"], -        "types": ["cypress", "node"] +        "types": ["cypress", "node"], +        "resolveJsonModule": true, +        "esModuleInterop": true      },      "include": ["**/*.ts"]  }  | 
