Skip to content

Commit

Permalink
Added initial cypress configs and tests (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanttuA authored May 31, 2023
1 parent 3c3a5fc commit 8ad0de9
Show file tree
Hide file tree
Showing 21 changed files with 4,749 additions and 817 deletions.
96 changes: 49 additions & 47 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,104 +1,107 @@
{
"extends": "airbnb",

"env": {
"browser": true,
"node": true,
"jest": true
"jest": true,
"cypress/globals": true
},

"globals": {
"SETTINGS": true
},

"parser": "babel-eslint",

"plugins": ["import", "react"],

"plugins": [
"import",
"react",
"cypress"
],
"settings": {
"import/resolver": {
"webpack": {
"config": "./config/webpack.common.js"
}
}
},

"rules": {

"class-methods-use-this": "off",

"import/no-extraneous-dependencies": "off",

"import/order": [
"warn",
{
"groups": [
"builtin",
"external",
["internal", "parent", "sibling", "index"]
[
"internal",
"parent",
"sibling",
"index"
]
],
"newlines-between": "always"
}
],

"no-debugger": "warn",

"no-unused-vars": "warn",

"import/prefer-default-export": "off",

"new-cap": ["error", { "capIsNew": false, "newIsCap": true }],

"no-underscore-dangle": ["error", { "allow": ["_paq"] }],

"new-cap": [
"error",
{
"capIsNew": false,
"newIsCap": true
}
],
"no-underscore-dangle": [
"error",
{
"allow": [
"_paq"
]
}
],
"no-unused-expressions": "off",

"no-use-before-define": ["error", "nofunc"],

"no-use-before-define": [
"error",
"nofunc"
],
"react/forbid-prop-types": "off",

"react/jsx-filename-extension": "off",

"react/jsx-sort-props": ["error", { "ignoreCase": true }],

"react/jsx-sort-props": [
"error",
{
"ignoreCase": true
}
],
"react/no-string-refs": "off",

"react/no-unused-prop-types": ["error", { "skipShapeProps": true }],

"react/no-unused-prop-types": [
"error",
{
"skipShapeProps": true
}
],
"react/prefer-stateless-function": "off",

"linebreak-style": 0,

"no-restricted-globals": ["error", "history"],

"no-restricted-globals": [
"error",
"history"
],
"prefer-destructuring": "off",

"react/destructuring-assignment": "off",

"react/require-default-props": "off",

"jsx-a11y/click-events-have-key-events": "off",

"jsx-a11y/anchor-is-valid": "off",

"jsx-a11y/label-has-for": "off",

"jsx-a11y/no-static-element-interactions": "off",

"jsx-a11y/no-noninteractive-tabindex": "off",

"react/no-array-index-key": "off",

"comma-dangle": "off",

"arrow-parens": "off",
"function-paren-newline": "off",
"prefer-object-spread": "off",
"default-param-last": "off",
"function-call-argument-newline": "off",
"no-restricted-exports": "off",
"no-multiple-empty-lines": "off",

"react/function-component-definition": "off",
"react/jsx-curly-newline": "off",
"react/jsx-no-constructed-context-values": "off",
Expand All @@ -118,8 +121,7 @@
"react/sort-comp": "off",
"react/prop-types": "off",
"react/jsx-indent": "warn",

"import/no-import-module-exports": "off",
"jsx-a11y/control-has-associated-label": "off"
}
}
}
44 changes: 44 additions & 0 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Cypress Tests

on:
push:
branches:
- master
- develop
pull_request:
branches:
- '**'

jobs:
cypress-run:
runs-on: ubuntu-22.04
strategy:
matrix:
node: [18]
steps:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: node -v

- name: Checkout
uses: actions/checkout@v2

- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb -y
- name: create env file
run: |
touch .env
echo PORT=3000 >> .env
cat .env
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install-command: npm ci --silent
build: npm run build
start: npm run start:production
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_modules
npm-debug.log
yarn-error.log
/.idea
cypress/videos
cypress/screenshots
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
44 changes: 44 additions & 0 deletions cypress/e2e/home-page.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// <reference types="cypress" />

describe('home page', () => {
beforeEach(() => {
Cypress.config('defaultCommandTimeout', 20000);
cy.fixture('purpose.json').as('purpose');
cy.intercept('GET', '**/purpose/', { fixture: 'purpose.json' }).as('getPurpose');
});

it('should have the correct headings', () => {
cy.visit('localhost:3000');
cy.get('.app-HomePage__content h1').should('have.text', 'Varaamo');
cy.get('.app-HomePage__content h2').should('have.text', 'Turun vuokrattavat tilat, laitteet ja asiantuntijapalvelut varattavana');
});

it('should have the correct header navigation links', () => {
cy.visit('localhost:3000');
cy.get('.navbar-header a').contains('Varaamo');
cy.get('.navbar-nav a').contains('Haku');
cy.get('.navbar-nav a').contains('Lisää tietoa');
});

it('should have search box and search button', () => {
cy.visit('localhost:3000');
cy.get('.app-HomeSearchBox input').should('be.visible');
cy.get('.app-HomeSearchBox button').should('be.visible').should('have.text', 'Hae');
});

it('should have the correct purpose banners', () => {
cy.visit('localhost:3000');
cy.wait('@getPurpose');
cy.get('.app-HomePageContent__banner').should('have.length', 2);
cy.get('.app-HomePageContent__banner h3').first().should('have.text', 'Kokoustila');
cy.get('.app-HomePageContent__banner h3').last().should('have.text', 'Testikäyttötarkoitus');
});

it('should have the correct footer navigation links', () => {
cy.visit('localhost:3000');
cy.get('footer a').should('have.length', 3);
cy.get('footer a').first().should('have.text', 'www.turku.fi');
cy.get('footer a').eq(1).should('have.text', 'Saavutettavuusseloste');
cy.get('footer a').last().should('have.text', 'Palautteesi voit lähettää täältä.');
});
});
109 changes: 109 additions & 0 deletions cypress/e2e/make-reservation.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/// <reference types="cypress" />

const {
generateOpeningHrs, getTomorrowDate, formatDateTime
} = require('../utils/scripts');
const userOidc = require('../fixtures/oidc_user.json');
const userData = require('../fixtures/user.json');
const reservationOffice = require('../fixtures/reservation_office.json');


describe('make reservations', () => {
beforeEach(() => {
cy.fixture('purpose.json').as('purpose');
cy.fixture('resource_office_search.json').as('resourceSearch');
cy.fixture('resource_office_detail.json').as('resourceDetail');
cy.fixture('unit.json').as('unit');
});

// eslint-disable-next-line func-names
it('normal reservation can be made', function () {
cy.intercept('GET', '**/purpose/', { fixture: 'purpose.json' }).as('getPurpose');
cy.intercept('GET', '**/unit/*', { fixture: 'unit.json' }).as('getUnit');
cy.intercept('GET', '**/resource/*', { fixture: 'resource_office_search.json' }).as('getResource');
cy.intercept('GET', '**/user/*', { fixture: 'user.json' }).as('getUser');

// start in home page
cy.visit('localhost:3000');
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
});

cy.wait('@getPurpose');
cy.get('input[type="text"]').should('be.visible').type('toimisto{enter}');

// search page
cy.wait('@getUnit');
cy.wait('@getResource');
cy.get('.app-ResourceCard__content a').should('be.visible').should('have.length', 1).should('have.text', 'Toimisto 1bKirjasto')
.click();

// resource page
const updatedDetail = { ...this.resourceDetail, opening_hours: generateOpeningHrs() };
cy.intercept('GET', `**/resource/${updatedDetail.id}/*`, updatedDetail).as('getResourceDetail');
cy.get('h1').should('be.visible').should('have.text', updatedDetail.name.fi);
cy.get('#reservation-panel h2').should('be.visible').should('have.text', 'Ajanvaraus');

cy.get('#dateField').should('be.visible').clear();
const tomorrowDate = getTomorrowDate();
cy.get('#dateField').should('be.visible').type(`${tomorrowDate}{enter}`);

cy.get('.app-TimeSlots--date--selected button').first().click();
cy.get('.reservation-calendar__reserve-button').should('be.visible').should('have.text', 'Tee varaus').click();

// reservation page
cy.get('h1').should('be.visible').should('have.text', 'Uusi varaus');
cy.get('.app-ReservationPage__phase-index').should('have.length', 2);
cy.get('.app-ReservationPage__phase-title').should('have.length', 2);
cy.get('.app-ReservationPage__phase-index').first().should('be.visible').should('have.text', '1');
cy.get('.app-ReservationPage__phase-index').last().should('be.visible').should('have.text', '2');
cy.get('.app-ReservationPage__phase-title').first().should('be.visible').should('have.text', 'Varauksen lisätiedot');
cy.get('.app-ReservationPage__phase-title').last().should('be.visible').should('have.text', 'Valmis');
cy.get('h3').should('be.visible').contains('Varaajan tiedot');
cy.get('#reserverName').should('be.visible').should('have.value', userData.display_name);
cy.get('#reserverPhoneNumber').should('be.visible').type('0401234567');
cy.get('#reserverEmailAddress').should('be.visible').should('have.value', userData.email);
cy.get('#universalData').select(1);
cy.get('#reservationExtraQuestions').should('be.visible').type('This is a test reservation');
cy.get('.terms-checkbox-field input').should('be.visible').click();

const { begin, end } = formatDateTime(tomorrowDate, '08:00', '08:30');
const updatedReservation = { ...reservationOffice, begin, end };
cy.intercept('POST', '**/reservation/', { body: updatedReservation }).as('postReservation');

cy.get('.form-controls button').contains('Tallenna').should('be.visible').click();
cy.wait('@postReservation');

// reservation success page
cy.get('h2.app-ReservationPage__header').should('be.visible').should('have.text', 'Varaus onnistui');
cy.get('h2#reservationDetails').should('be.visible').should('have.text', 'Varauksen lisätiedot');
cy.get('.app-ReservationConfirmation__field').first().should('be.visible')
.should('have.text', `Varaaja / vuokraaja${userData.display_name}`);

cy.intercept('GET', '**/reservation/*', {
body: {
count: 1, next: null, previous: null, results: [updatedReservation]
}
}).as('getReservations');
cy.get('button').contains('Palaa omiin varauksiin').click();

// my reservations page
cy.wait('@getReservations');
cy.get('h1').should('be.visible').should('have.text', 'Omat varaukset');
cy.get('li.reservation').should('have.length', 1).contains(this.resourceDetail.name.fi);
});
});
Loading

0 comments on commit 8ad0de9

Please sign in to comment.