diff --git a/cypress/fixtures/dummyEventResponses.json b/cypress/fixtures/dummyEventResponses.json index c38fe91332..ff73c36c20 100644 --- a/cypress/fixtures/dummyEventResponses.json +++ b/cypress/fixtures/dummyEventResponses.json @@ -1,8 +1,9 @@ { "data": [ { - "action_id": 22, + "action_id": 25, "response_date": "2021-01-21T18:30:00+00:00", + "organization_id": 1, "person": { "name": "Dummy User", "id": 2 diff --git a/cypress/integration/org_event_page.spec.ts b/cypress/integration/org_event_page.spec.ts index 8447ac8aa7..fa94f01d2a 100644 --- a/cypress/integration/org_event_page.spec.ts +++ b/cypress/integration/org_event_page.spec.ts @@ -1,4 +1,12 @@ describe('/o/[orgId]/events/[eventId]', () => { + beforeEach(() => { + cy.request('delete', 'http://localhost:8001/_mocks'); + }); + + after(() => { + cy.request('delete', 'http://localhost:8001/_mocks'); + }); + it('contains non-interactive event content', () => { cy.visit('/o/1/events/25'); cy.get('[data-test="event-title"]').should('be.visible'); @@ -20,18 +28,46 @@ describe('/o/[orgId]/events/[eventId]', () => { cy.url().should('match', /\/o\/1\/campaigns\/2$/); }); - it.only('contains a conditional sign-up button', () => { + it('shows a sign-up button if user is not signed up to the event', () => { + cy.request('put', 'http://localhost:8001/v1/users/me/action_responses/_mocks/get', { + response: { + data: { + data: [], + }, + }, + }); + cy.visit('/login'); cy.get('input[aria-label="E-mail address"]').type('testadmin@example.com'); cy.get('input[aria-label="Password"]').type('password'); cy.get('input[aria-label="Log in"]') .click(); + cy.visit('/o/1/events/25'); cy.waitUntilReactRendered(); - cy.findByText('Sign-up') - .click(); - cy.waitUntilReactRendered(); - cy.findByText('Undo sign-up'); + cy.findByText('Sign-up').click(); + //TODO: Verify that API request is done corrently. + }); + + it('shows an undo sign-up button if user is signed up to the event', () => { + cy.fixture('dummyEventResponses').then(json => { + cy.request('put', 'http://localhost:8001/v1/users/me/action_responses/_mocks/get', { + response: { + data: json, + }, + }); + + cy.visit('/login'); + cy.get('input[aria-label="E-mail address"]').type('testadmin@example.com'); + cy.get('input[aria-label="Password"]').type('password'); + cy.get('input[aria-label="Log in"]') + .click(); + + cy.visit('/o/1/events/25'); + cy.waitUntilReactRendered(); + cy.findByText('Undo sign-up').click(); + //TODO: Verify that API request is done corrently. + }); }); }); diff --git a/cypress/integration/org_events_page.spec.ts b/cypress/integration/org_events_page.spec.ts index 4bb0290268..574576b842 100644 --- a/cypress/integration/org_events_page.spec.ts +++ b/cypress/integration/org_events_page.spec.ts @@ -3,12 +3,17 @@ describe('/o/[orgId]/events', () => { cy.request('delete', 'http://localhost:8001/_mocks'); }); + after(() => { + cy.request('delete', 'http://localhost:8001/_mocks'); + }); + it('contains name of organization', () => { cy.visit('/o/1/events'); + cy.waitUntilReactRendered(); cy.contains('My Organization'); }); - it.only('contains events which are linked to event pages', () => { + it('contains events which are linked to event pages', () => { cy.request('put', 'http://localhost:8001/v1/orgs/1/campaigns/_mocks/get', { response: { data: { @@ -38,7 +43,7 @@ describe('/o/[orgId]/events', () => { }); it('contains a placeholder if there are no events', () => { - cy.request('put', 'http://localhost:8001/v1/orgs/1/campaigns/1/actions/_mocks/get', { + cy.request('put', 'http://localhost:8001/v1/orgs/1/campaigns/_mocks/get', { response: { data: { data: [], @@ -50,22 +55,48 @@ describe('/o/[orgId]/events', () => { cy.get('[data-test="no-events-placeholder"]').should('be.visible'); }); - it.only('shows sign up button if not signed up, and undo button when signed up', () => { + it('shows a sign-up button if user is not signed up to an event', () => { + cy.request('put', 'http://localhost:8001/v1/users/me/action_responses/_mocks/get', { + response: { + data: { + data: [], + }, + }, + }); + cy.visit('/login'); cy.get('input[aria-label="E-mail address"]').type('testadmin@example.com'); cy.get('input[aria-label="Password"]').type('password'); cy.get('input[aria-label="Log in"]') .click(); + cy.visit('/o/1/events'); cy.waitUntilReactRendered(); cy.get('[data-test="event-response-button"]') - .eq(5) - .contains('Sign-up') + .eq(4) .click(); - cy.waitUntilReactRendered(); - cy.get('[data-test="event-response-button"]') - .eq(5) - .contains('Undo sign-up'); + //TODO: Verify that API request is done corrently. + }); + + it('shows an undo sign-up button if user is signed up to an event', () => { + cy.fixture('dummyEventResponses').then(json => { + cy.request('put', 'http://localhost:8001/v1/users/me/action_responses/_mocks/get', { + response: { + data: json, + }, + }); + + cy.visit('/login'); + cy.get('input[aria-label="E-mail address"]').type('testadmin@example.com'); + cy.get('input[aria-label="Password"]').type('password'); + cy.get('input[aria-label="Log in"]') + .click(); + + cy.visit('/o/1/events'); + cy.waitUntilReactRendered(); + cy.findByText('Undo sign-up').click(); + //TODO: Verify that API request is done corrently. + }); }); });