Skip to content

Commit

Permalink
cypress: create test for collections
Browse files Browse the repository at this point in the history
* Creates e2e tests for collections.
* Replaces 'goToMenu' custom command in order not to go to the frontpage
  each time we navigate in the app.
* Adds an empty template to re-use for test creation.
* Adds cookies preservation to keep authentication information between tests.
* Changes login and logout commands in order to use API calls instead of
UI actions.
* Adds a test for login and logout (UI actions).
* Allows language preservation in professional interface.
* Closes rero#1220.

Co-Authored-by: Alicia Zangger <[email protected]>
  • Loading branch information
Alicia Zangger committed Nov 2, 2020
1 parent 6e1e31e commit 3b2fb13
Show file tree
Hide file tree
Showing 15 changed files with 420 additions and 114 deletions.
44 changes: 44 additions & 0 deletions tests/e2e/cypress/cypress/fixtures/collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"course": {
"collection_id": "CRS 1",
"title": "Course number 1",
"collection_type": "course",
"teachers": [
{
"name": "Pr. Smith, John"
}
],
"libraries": [
{
"$ref": "https://ils.rero.ch/api/libraries/22"
}
],
"description": "List of items for course 1",
"subjects": [
{
"name": "Anne Nonyme"
},
{
"name": "geographic"
}
],
"start_date": "2020-09-01",
"end_date": "2020-12-31",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/4"
},
"published": true
},
"exhibition": {
"collection_id": "Expo 1",
"title": "Expo \u2013 The Number 1",
"collection_type": "exhibition",
"description": "List of items for the exhibition",
"start_date": "2020-10-01",
"end_date": "2021-06-30",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/4"
},
"published": true
}
}
12 changes: 8 additions & 4 deletions tests/e2e/cypress/cypress/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@
"email": "[email protected]",
"first_name": "James",
"last_name": "Kirk",
"barcode": "cypress-1"
"barcode": "cypress-1",
"initials": "JK"
},
"nyota": {
"email": "[email protected]",
"first_name": "Nyota",
"last_name": "Uhura",
"barcode": "cypress-2"
"barcode": "cypress-2",
"initials": "NU"
}
},
"librarians": {
"spock": {
"email": "[email protected]",
"first_name": "Spock",
"last_name": "Grayson",
"libraryPid": "23"
"libraryPid": "23",
"initials": "SG"
},
"leonard": {
"email": "[email protected]",
"first_name": "Leonard",
"last_name": "McCoy",
"libraryPid": "22"
"libraryPid": "22",
"initials": "LM"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/// <reference types="Cypress" />
/*
RERO ILS
Copyright (C) 2020 RERO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

before(function () {
cy.fixture('users').then(function (userData) {
this.users = userData;
});
cy.fixture('common').then(function (commonData) {
this.common = commonData;
});
});

describe('Login and logout', function() {
before('Go to frontpage', function() {
cy.visit('/lang/en');
});

after('Logout', function() {
cy.logout();
});

it('Login as a librarian', function() {
// Login
cy.get('#my-account-menu').click();
cy.wait(1000);
cy.get('#login-menu').click();
// Fill the form and submit
cy.get('#email').type(this.users.librarians.leonard.email);
cy.get('#password').type(this.common.uniquePwd);
cy.get('form[name="login_user_form"]').submit();
// Check that the user is logged
cy.get('#my-account-menu').should('contain', this.users.librarians.leonard.initials);
// Check professional interface access
cy.visit('/professional');
cy.get('body').should('contain','RERO ILS administration');

//Logout
// Click on username
cy.get('#my-account-menu').click()
// Wait for the menu to open
cy.wait(1000)
// Click on logout
cy.get('#logout-menu').click();
// Raise an error if something went wrong
cy.contains('My account');

});

it('Login as a patron', function() {
cy.get('#my-account-menu').click();
cy.wait(1000);
cy.get('#login-menu').click();
// Fill the form
cy.get('#email').type(this.users.patrons.james.email);
cy.get('#password').type(this.common.uniquePwd);
cy.get('form[name="login_user_form"]').submit();
// Check that the user is logged
cy.get('#my-account-menu').should('contain', this.users.patrons.james.initials);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ describe('Circulation scenario A: standard loan', function() {
before('Login as a professional and create a document and an item', function() {
// Create server to watch api requests
cy.server();
// Open app on frontpage
cy.visit('');
// Check language and force to english
cy.setLanguageToEnglish();
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Create a document
// Go to document editor
cy.goToMenu('create-bibliographic-record-menu-frontpage');
cy.visit('/professional/records/documents/new');
// Populate form with simple record
cy.populateSimpleRecord(this.documents.book);
//Save record
Expand All @@ -69,7 +65,7 @@ describe('Circulation scenario A: standard loan', function() {
});

after('Clean data: remove item and document', function() {
// TODO: find a way to preserve cookies (auth) and server after a test
cy.logout();
cy.server();
cy.route({method: 'DELETE', url: '/api/items/*'}).as('deleteItem');
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
Expand Down Expand Up @@ -106,15 +102,17 @@ describe('Circulation scenario A: standard loan', function() {
*/
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to requests list
cy.goToMenu('requests-menu-frontpage')
cy.get('#user-services-menu').click();
cy.get('#requests-menu').click();
// Check that the document is present
cy.get('table').should('contain', this.itemBarcode)
// Enter the barcode and validate
cy.get('#search').type(this.itemBarcode).type('{enter}')

// The item should be marked as available in user profile view
// Go to patrons list
cy.goToMenu('users-menu-frontpage')
cy.get('#user-services-menu').click();
cy.get('#users-menu').click();
// Go to James patron profile
cy.get('#' + this.users.patrons.james.barcode + '-loans').click()
// Click on tab called "To pick up"
Expand All @@ -129,7 +127,8 @@ describe('Circulation scenario A: standard loan', function() {
*/
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to circulation search bar
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Checkout
cy.scanPatronBarcodeThenItemBarcode(this.users.patrons.james, this.itemBarcode);
// Item barcode should be present
Expand All @@ -143,13 +142,13 @@ describe('Circulation scenario A: standard loan', function() {
*/
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to circulation search bar
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Checkin
cy.scanItemBarcode(this.itemBarcode);
// CHeck that the item was checked in and that it is on shelf
cy.get('#item-' + this.itemBarcode).should('contain', this.itemBarcode);
cy.get('#item-' + this.itemBarcode).should('contain', 'on shelf');
cy.get('#item-' + this.itemBarcode).should('contain', 'checked in');
cy.logout();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ describe('Circulation scenario B: standard loan with transit', function() {
* 6. The item is received at owning library and goes on shelf.
*/
before('Login as a professional and create a document and an item', function() {
// Open app on frontpage
cy.visit('');
// Check language and force to english
cy.setLanguageToEnglish();
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Create a document
// Go to document editor
cy.goToMenu('create-bibliographic-record-menu-frontpage');
cy.visit('/professional/records/documents/new');
// Populate form with simple record
cy.populateSimpleRecord(this.documents.book);
//Save record
Expand All @@ -69,7 +65,7 @@ describe('Circulation scenario B: standard loan with transit', function() {
});

after('Clean data: remove item and document', function() {
// TODO: find a way to preserve cookies (auth) and server after a test
cy.logout();
cy.server();
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to document detail view and remove item
Expand Down Expand Up @@ -106,7 +102,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to requests list
cy.goToMenu('requests-menu-frontpage')
cy.get('#user-services-menu').click();
cy.get('#requests-menu').click();
// Check that the document is present
cy.get('table').should('contain', this.itemBarcode);
// Enter the barcode and validate
Expand All @@ -122,7 +119,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
// Go to checkin view
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Enter item barcode for receive
cy.get('#search').type(this.itemBarcode).type('{enter}');
// Check that the item has been received
Expand All @@ -135,7 +133,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
// Go to checkin view
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Checkout
cy.scanPatronBarcodeThenItemBarcode(james, this.itemBarcode)
// Check that the checkout has been done
Expand All @@ -148,7 +147,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
// Go to checkin view
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Checkin
cy.scanItemBarcode(this.itemBarcode);
// Check that the checkin has been done
Expand All @@ -164,14 +164,14 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Login as librarian
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
// Go to checkin view
cy.goToMenu('circulation-menu-frontpage');
cy.get('#user-services-menu').click();
cy.get('#circulation-menu').click();
// Receive
cy.scanItemBarcode(this.itemBarcode);
// Check that the item has been received
cy.get('#item-' + this.itemBarcode + ' [name="action-done"]').should('contain', 'receive');
// Check that the item is on shelf
cy.get('#item-' + this.itemBarcode + ' [name="circ-info"] [name="status"]')
.should('contain', 'on shelf');
cy.logout();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/// <reference types="Cypress" />
/*
RERO ILS
Copyright (C) 2020 RERO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

before(function () {
cy.fixture('users').then(function (userData) {
this.users = userData;
});
cy.fixture('common').then(function (commonData) {
this.common = commonData;
});
cy.fixture('collections').then(function (collections) {
this.collections = collections;
});
});

describe('Collections', function() {
/**
* DESCRIPTION
*
*/
before('Login as a professional', function() {
Cypress.Cookies.debug(true);
this.spock = this.users.librarians.spock;
// Create server to watch api requests
cy.server();
// Open app on frontpage
cy.visit('');
// Check language and force to english
cy.setLanguageToEnglish();
// Login as librarian
cy.adminLogin(this.spock.email, this.common.uniquePwd);
// Create a course
cy.createCollection(this.collections.course);
// Check the course
cy.checkCollection(this.collections.course);
});

beforeEach(() => {
Cypress.Cookies.preserveOnce('session');
});

after('Clean data: remove collection', function() {
// Delete collection and confirm
cy.get('#detail-delete-button').click();
cy.get('#modal-confirm-button').click();
cy.logout();
});

it('Create a collection', function() {
// Create a course
cy.createCollection(this.collections.course);
// Check the course
cy.checkCollection(this.collections.course);
});

it('Edit a collection', function() {
// Edit a collection to change it as an exhibition
cy.editCollection(this.collections.exhibition);
// Check the exhibition
cy.checkCollection(this.collections.exhibition);
});
});
Loading

0 comments on commit 3b2fb13

Please sign in to comment.