Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign up to event #104

Merged
merged 25 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
451c9bd
Add sign-up functionality for event
kristofferlarberg Mar 25, 2021
6c32cd1
Refactor fetch functions, change name for DELETE function
kristofferlarberg Mar 30, 2021
786eaf8
Remove undefined from prop types and move non-null assertion to org p…
kristofferlarberg Mar 30, 2021
b19d8df
Remove eslint-disable from EventList
kristofferlarberg Mar 30, 2021
82da026
Update cache when response PUT/DELETE and conditionally render signup…
kristofferlarberg Apr 1, 2021
2a336c8
Refactor functionality and general structure for conditional sign-up …
kristofferlarberg Apr 12, 2021
c85776c
Add login procedure in button test
kristofferlarberg Apr 14, 2021
c83f3fe
Remove unnecessary spies
kristofferlarberg Apr 14, 2021
db23b2c
Refactor useMutation functionality to reusable hook
kristofferlarberg Apr 15, 2021
f75a42e
Make small changes in integration and component tests for events page…
kristofferlarberg Apr 16, 2021
cdd458a
Include eventResponses in useOnEventResponse
kristofferlarberg Apr 16, 2021
3dea616
Add TODO
kristofferlarberg Apr 16, 2021
7d82701
Apply useEventResponses on event page
kristofferlarberg Apr 16, 2021
748c496
Add space before block
kristofferlarberg Apr 16, 2021
2f21830
Merge branch 'main' into issue-93/sign-up-to-event
kristofferlarberg Apr 16, 2021
6e5a17d
Make integration-tests for events/event pages less flaky
kristofferlarberg Apr 16, 2021
2ee9245
Merge branch 'issue-93/sign-up-to-event' of https://github.com/zetkin…
kristofferlarberg Apr 16, 2021
01a5889
Add user attribute to context
kristofferlarberg Apr 19, 2021
0949317
Refactor events/event page related fetch functions and conditionally …
kristofferlarberg Apr 19, 2021
8970016
Adjust integration tests for sign-up button
kristofferlarberg Apr 19, 2021
3e94a79
Move user attribute to after reqWithSession, remove else stement for …
kristofferlarberg Apr 20, 2021
876a5b1
Make defaultFetch shared module, remove fetch injection in put- and d…
kristofferlarberg Apr 20, 2021
79a4b05
Extract user data object as ctx.user and reuse with augmentProps
kristofferlarberg Apr 20, 2021
6423f59
Refactor back putEventResponse and deleteEventResponse to not returni…
kristofferlarberg Apr 21, 2021
8f02e54
Add type assertion to user object, remove augmentProps function
kristofferlarberg Apr 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions cypress/fixtures/dummyEventResponses.json
@@ -0,0 +1,14 @@
{
"data": [
{
"action_id": 25,
"response_date": "2021-01-21T18:30:00+00:00",
"organization_id": 1,
"person": {
"name": "Dummy User",
"id": 2
},
"id": 2
}
]
}
63 changes: 57 additions & 6 deletions cypress/integration/org_event_page.spec.ts
@@ -1,28 +1,79 @@
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/22');
cy.visit('/o/1/events/25');
cy.get('[data-test="event-title"]').should('be.visible');
cy.get('[data-test="duration"]').should('be.visible');
cy.get('[data-test="location"]').should('be.visible');
});

it('contains clickable org name that leads to org page', () => {
cy.visit('/o/1/events/22');
cy.visit('/o/1/events/25');
cy.waitUntilReactRendered();
cy.findByText('My Organization').click();
cy.url().should('match', /\/o\/1$/);
});

it('contains clickable campaign name that leads to campaign page', () => {
cy.visit('/o/1/events/22');
cy.visit('/o/1/events/25');
cy.waitUntilReactRendered();
cy.findByText('Second campaign').click();
cy.url().should('match', /\/o\/1\/campaigns\/2$/);
});

it('contains a sign-up button', () => {
cy.visit('/o/1/events/22');
cy.findByText('Sign-up').should('be.visible');
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();
//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.request('put', 'http://localhost:8001/v1/orgs/1/actions/25/responses/2/_mocks/delete', {
response: {
status: 204,
},
});

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
59 changes: 57 additions & 2 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 @@ -49,6 +54,56 @@ describe('/o/[orgId]/events', () => {
cy.visit('/o/1/events');
cy.get('[data-test="no-events-placeholder"]').should('be.visible');
});

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(4)
.click();
//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.request('put', 'http://localhost:8001/v1/orgs/1/actions/25/responses/2/_mocks/delete', {
response: {
status: 204,
},
});

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.
});
});
});

// Hack to flag for typescript as module
Expand Down
1 change: 1 addition & 0 deletions cypress/integration/reocurring_functionality.spec.ts
@@ -1,4 +1,5 @@
describe('Reocurring functionality', () => {

it('contains a clickable org logo which leads to org page', () => {
cy.visit('/o/1/events');
cy.get('[data-test="org-avatar"]')
Expand Down
59 changes: 52 additions & 7 deletions src/components/EventList.spec.tsx
@@ -1,11 +1,13 @@
import EventList from './EventList';
import { mountWithProviders } from '../utils/testing';
import { ZetkinEvent } from '../interfaces/ZetkinEvent';
import { ZetkinEventResponse } from '../types/zetkin';
import { ZetkinOrganization } from '../interfaces/ZetkinOrganization';

describe('EventList', () => {
let dummyOrg : ZetkinOrganization;
let dummyEvents : ZetkinEvent[];
let dummyEventResponses : ZetkinEventResponse[];

beforeEach(()=> {
cy.fixture('dummyOrg.json')
Expand All @@ -16,11 +18,20 @@ describe('EventList', () => {
.then((data : {data: ZetkinEvent[]}) => {
dummyEvents = data.data;
});
cy.fixture('dummyEventResponses.json')
.then((data : {data: ZetkinEventResponse[]}) => {
dummyEventResponses = data.data;
});
});

it('contains data for each event', () => {
mountWithProviders(
<EventList events={ dummyEvents } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ dummyEvents }
onEventResponse={ () => null }
org={ dummyOrg }
/>,
);

cy.get('[data-test="event"]').each((item) => {
Expand All @@ -36,8 +47,14 @@ describe('EventList', () => {

it('contains an activity title instead of missing event title', () => {
dummyEvents[0].title = undefined;

mountWithProviders(
<EventList events={ dummyEvents } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ dummyEvents }
onEventResponse={ () => null }
org={ dummyOrg }
/>,
);

cy.get('[data-test="event"]')
Expand All @@ -46,33 +63,61 @@ describe('EventList', () => {
});

it('contains a sign-up button for each event', () => {
const spyOnSubmit = cy.spy();

mountWithProviders(
<EventList events={ dummyEvents } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ dummyEvents }
onEventResponse={ spyOnSubmit }
org={ dummyOrg }
/>,
);

cy.contains('misc.eventList.signup');
cy.findByText('misc.eventList.signup')
.eq(0)
.click()
.then(() => {
expect(spyOnSubmit).to.be.calledOnce;
richardolsson marked this conversation as resolved.
Show resolved Hide resolved
});
});

it('contains a button for more info on each event', () => {
mountWithProviders(
<EventList events={ dummyEvents } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ dummyEvents }
onEventResponse={ () => null }
org={ dummyOrg }
/>,
);

cy.contains('misc.eventList.moreInfo');
});

it('shows a placeholder when the list is empty', () => {
dummyEvents = [];

mountWithProviders(
<EventList events={ dummyEvents } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ dummyEvents }
onEventResponse={ () => null }
org={ dummyOrg }
/>,
);

cy.contains('misc.eventList.placeholder');
});

it('shows a placeholder when the list is undefined', () => {
mountWithProviders(
<EventList events={ undefined } org={ dummyOrg }/>,
<EventList
eventResponses={ dummyEventResponses }
events={ undefined }
onEventResponse={ () => null }
org={ dummyOrg }
/>,
);

cy.contains('misc.eventList.placeholder');
Expand Down