forked from City-of-Helsinki/varaamo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial cypress configs and tests (#247)
- Loading branch information
Showing
21 changed files
with
4,749 additions
and
817 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ node_modules | |
npm-debug.log | ||
yarn-error.log | ||
/.idea | ||
cypress/videos | ||
cypress/screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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ä.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.