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.
* Creates 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 authored and AoNoOokami committed Nov 3, 2020
1 parent 95b124b commit 9247147
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 111 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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/// <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');
});

beforeEach('Add description if needed', function() {
// Preserve authentication information between the tests
Cypress.Cookies.preserveOnce('session');
});

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

it('Logout', function() {
// 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();
// Check that the user is logged out
cy.get('body').should('contain','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,76 @@
/// <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() {
// Login as librarian (Leonard)
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
});

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 course', function() {
let course = this.collections.course;
// Go to collection list
cy.get('#user-services-menu').click();
cy.get('#collections-menu').click();
// Click add button
cy.get('#search-add-button').click();
// Fill in the form
cy.fillCollectionEditor(course);
// Check the course
cy.checkCollection(course);
});

it('Edit a collection to change it as an exhibition', function() {
let exhibition = this.collections.exhibition;
// Go to editor
cy.get('#detail-edit-button').click();
// Fill in the form
cy.fillCollectionEditor(exhibition);
// Check the exhibition
cy.checkCollection(exhibition);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,19 @@ before(function () {
describe('Document editor', function() {
before('Login as a professional and create an item', function() {
this.spock = this.users.librarians.spock;
//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);
});

after('Clean data: remove document', function() {
// Delete record
cy.deleteRecordFromDetailView();
cy.logout();
});

it('Creates a document with only essential fields', function() {
// 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 Down
Loading

0 comments on commit 9247147

Please sign in to comment.