Skip to content

Commit

Permalink
Added cypress tests for overnight calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
SanttuA committed May 31, 2024
1 parent 065b842 commit 87904a5
Show file tree
Hide file tree
Showing 4 changed files with 498 additions and 0 deletions.
166 changes: 166 additions & 0 deletions cypress/e2e/overnight-resource-page.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* eslint-disable camelcase */
/// <reference types="cypress" />
const userOidc = require('../fixtures/oidc_user.json');
const userData = require('../fixtures/user.json');
const { getReservationBeginEnd, getClosedDate } = require('../utils/scripts');

describe('Overnight calendar', () => {
beforeEach(() => {
cy.fixture('resource_overnight_detail.json').as('resourceDetail');
cy.fixture('reservation_overnight.json').as('reservationOvernight');
});

function handleCommonInit(resource, skipCookiebot = false) {
cy.intercept('GET', '**/user/*', { fixture: 'user.json' }).as('getUser');

// start in resource page
cy.visit(`localhost:3000/resources/${resource.id}`);

if (!skipCookiebot) {
cy.get('#CybotCookiebotDialogBodyButtonDecline').click();
}

// force user login data
cy.window().then((win) => {
// eslint-disable-next-line no-param-reassign
win.INITIAL_STATE = {
data: {
users: {
'123b6480-a639-62ab-1234-111ac567j19c': userData
}
}
};
});
cy.window().its('store').invoke('dispatch', {
type: 'redux-oidc/USER_FOUND',
payload: userOidc
});
}

function getUpdatedResource(resourceFixt, reservationFixt) {
const beginEndA = getReservationBeginEnd('13D13:00:00', '14D07:00:00');
const beginEndB = getReservationBeginEnd('17D13:00:00', '19D07:00:00');
const reservationA = { ...reservationFixt, ...beginEndA };
const reservationB = { ...reservationFixt, ...beginEndB };
const closedDate = getClosedDate('23');
const resource = {
...resourceFixt,
reservations: [reservationA, reservationB],
openingHours: [closedDate]
};
return resource;
}

// eslint-disable-next-line func-names
it('is displayed on resource page', function () {
cy.intercept('GET', '**/resource/*/*', { fixture: 'resource_overnight_detail.json' }).as('getResource');
const resource = this.resourceDetail;
handleCommonInit(resource);
cy.get('h1').should('be.visible').should('have.text', resource.name.fi);
cy.get('.overnight-calendar').scrollIntoView().should('be.visible');
cy.get('button').contains('Nykyinen kuukausi').should('be.visible');
cy.contains('Vapaa').should('be.visible');
cy.contains('Ei valittavissa').should('be.visible');
cy.contains('Varattu').should('be.visible');
cy.contains('Oma valinta').should('be.visible');
});

// eslint-disable-next-line func-names
it('selects start and end', function () {
const resource = getUpdatedResource(this.resourceDetail, this.reservationOvernight);
cy.intercept('GET', `**/resource/${resource.id}/*`, resource).as('getResourceDetail');
handleCommonInit(resource);
cy.get('.overnight-calendar').scrollIntoView().should('be.visible');
cy.get('.DayPicker-NavButton--next').click();
cy.get('.DayPicker-Day').contains('10').click();
cy.get('.DayPicker-Day').contains('12').click();
cy.contains('Valittu aika').should('be.visible');
cy.get('button').contains('Tee varaus').should('be.visible');
});

// eslint-disable-next-line func-names
it('doesnt allow over max time reservations', function () {
const resource = {
...getUpdatedResource(this.resourceDetail, this.reservationOvernight),
reservations: []
};
cy.intercept('GET', `**/resource/${resource.id}/*`, resource).as('getResourceDetail');
handleCommonInit(resource);
cy.get('.overnight-calendar').scrollIntoView().should('be.visible');
cy.get('.DayPicker-NavButton--next').click();

cy.get('.DayPicker-Day').contains('11').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('11');
cy.get('.DayPicker-Day').contains('17').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.contains('Valittu aika ylittää maksimipituuden').should('be.visible');
cy.get('button').contains('Tee varaus').should('be.disabled');
});

const testCases = [
{ overnight_start_time: '13:00:00', overnight_end_time: '07:00:00' },
{ overnight_start_time: '12:00:00', overnight_end_time: '12:00:00' },
{ overnight_start_time: '10:00:00', overnight_end_time: '07:00:00' },
];

// eslint-disable-next-line func-names
it('handles select logic correctly', function () {
testCases.forEach(({ overnight_start_time, overnight_end_time }, index) => {
const resource = { ...this.resourceDetail, overnight_start_time, overnight_end_time };
const updatedResource = getUpdatedResource(resource, this.reservationOvernight);
cy.intercept('GET', `**/resource/${updatedResource.id}/*`, updatedResource).as('getResourceDetail');
handleCommonInit(updatedResource, index > 0);
cy.get('.overnight-calendar').scrollIntoView().should('be.visible');
cy.get('.DayPicker-NavButton--next').click();

cy.get('.DayPicker-Day').contains('10').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('10');
cy.get('.DayPicker-Day').contains('10').click();
cy.get('.DayPicker-Day--selected').should('have.length', 0);

cy.get('.DayPicker-Day').contains('10').click();
cy.get('.DayPicker-Day').contains('12').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.get('.DayPicker-Day').contains('11').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('11');
cy.get('.DayPicker-Day').contains('13').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.get('.DayPicker-Day').contains('14').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('14');
cy.get('.DayPicker-Day').contains('17').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.get('.DayPicker-Day').contains('19').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('19');
cy.get('.DayPicker-Day').contains('22').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.get('.DayPicker-Day').contains('24').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('24');
cy.get('.DayPicker-Day').contains('25').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2);

cy.get('.DayPicker-Day').contains('13').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2).contains('24');
cy.get('.DayPicker-Day').contains('22').click();
cy.get('.DayPicker-Day--selected').should('have.length', 2).contains('24');

cy.get('.DayPicker-Day').contains('12').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('12');
cy.get('.DayPicker-Day').contains('15').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('12');
cy.get('.DayPicker-Day').contains('14').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('12');

cy.get('.DayPicker-Day').contains('12').click();
cy.get('.DayPicker-Day--selected').should('have.length', 0);
cy.get('.DayPicker-Day').contains('15').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('15');
cy.get('.DayPicker-Day').contains('13').click();
cy.get('.DayPicker-Day--selected').should('have.length', 1).contains('15');
});
});
});
69 changes: 69 additions & 0 deletions cypress/fixtures/reservation_overnight.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"url": "https://respa.fi/v1/reservation/123/",
"id": 123,
"resource": "axwhvvq4er3a",
"begin": "2023-06-20T13:00:00+03:00",
"end": "2023-06-21T07:00:00+03:00",
"is_own": false,
"state": "confirmed",
"need_manual_confirmation": false,
"require_assistance": false,
"require_workstation": false,
"staff_event": false,
"user_permissions": {
"can_modify": true,
"can_delete": true
},
"preferred_language": "fi",
"type": "normal",
"has_arrived": false,
"takes_place_virtually": false,
"virtual_address": "",
"universal_data": {
"type": "select",
"selected_option": "1",
"field": {
"id": 1,
"description": "Valitse mihin järjestykseen toivot tilan pöytien asetettavan",
"label": "Pöytien järjestys",
"options": [
{
"id": 1,
"text": "Kolme riviä"
},
{
"id": 2,
"text": "Pöydät U-muotoisesti"
},
{
"id": 3,
"text": "Kahtena neliösaarekkeena"
}
]
}
},
"reserver_name": "Test Tester",
"reserver_phone_number": "0401234567",
"reserver_address_street": "",
"reserver_address_zip": "",
"reserver_address_city": "",
"company": "",
"event_description": "",
"event_subject": "",
"reserver_id": "",
"number_of_participants": 1,
"participants": "",
"reserver_email_address": "[email protected]",
"host_name": "",
"reservation_extra_questions": "This is a test reservation",
"home_municipality": null,
"billing_first_name": "",
"billing_last_name": "",
"billing_phone_number": "",
"billing_email_address": "",
"billing_address_street": "",
"billing_address_zip": "",
"billing_address_city": "",
"order": null,
"has_catering_order": false
}
Loading

0 comments on commit 87904a5

Please sign in to comment.