Skip to content

Commit

Permalink
Adjust integration tests for sign-up button
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferlarberg committed Apr 19, 2021
1 parent 0949317 commit f896046
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 15 deletions.
3 changes: 2 additions & 1 deletion 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
Expand Down
46 changes: 41 additions & 5 deletions 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');
Expand All @@ -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.
});
});
});

Expand Down
49 changes: 40 additions & 9 deletions cypress/integration/org_events_page.spec.ts
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [],
Expand All @@ -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.
});
});
});

Expand Down

0 comments on commit f896046

Please sign in to comment.