Skip to content

Commit f624079

Browse files
Alicia Zanggerzannkukai
Alicia Zangger
authored andcommitted
cypress: create test for collections
* 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]>
1 parent ad490a6 commit f624079

File tree

14 files changed

+413
-111
lines changed

14 files changed

+413
-111
lines changed

Diff for: tests/e2e/cypress/cypress/fixtures/collections.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"course": {
3+
"collection_id": "CRS 1",
4+
"title": "Course number 1",
5+
"collection_type": "course",
6+
"teachers": [
7+
{
8+
"name": "Pr. Smith, John"
9+
}
10+
],
11+
"libraries": [
12+
{
13+
"$ref": "https://ils.rero.ch/api/libraries/22"
14+
}
15+
],
16+
"description": "List of items for course 1",
17+
"subjects": [
18+
{
19+
"name": "Anne Nonyme"
20+
},
21+
{
22+
"name": "geographic"
23+
}
24+
],
25+
"start_date": "2020-09-01",
26+
"end_date": "2020-12-31",
27+
"organisation": {
28+
"$ref": "https://ils.rero.ch/api/organisations/4"
29+
},
30+
"published": true
31+
},
32+
"exhibition": {
33+
"collection_id": "Expo 1",
34+
"title": "Expo \u2013 The Number 1",
35+
"collection_type": "exhibition",
36+
"description": "List of items for the exhibition",
37+
"start_date": "2020-10-01",
38+
"end_date": "2021-06-30",
39+
"organisation": {
40+
"$ref": "https://ils.rero.ch/api/organisations/4"
41+
},
42+
"published": true
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/// <reference types="Cypress" />
2+
/*
3+
4+
RERO ILS
5+
Copyright (C) 2020 RERO
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Affero General Public License as published by
9+
the Free Software Foundation, version 3 of the License.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
*/
20+
21+
before(function () {
22+
cy.fixture('users').then(function (userData) {
23+
this.users = userData;
24+
});
25+
cy.fixture('common').then(function (commonData) {
26+
this.common = commonData;
27+
});
28+
});
29+
30+
describe('Login and logout', function() {
31+
before('Go to frontpage', function() {
32+
cy.visit('/lang/en');
33+
});
34+
35+
beforeEach('Add description if needed', function() {
36+
// Preserve authentication information between the tests
37+
Cypress.Cookies.preserveOnce('session');
38+
});
39+
40+
after('Logout', function() {
41+
cy.logout();
42+
});
43+
44+
it('Login as a librarian', function() {
45+
// Login
46+
cy.get('#my-account-menu').click();
47+
cy.wait(1000);
48+
cy.get('#login-menu').click();
49+
// Fill the form and submit
50+
cy.get('#email').type(this.users.librarians.leonard.email);
51+
cy.get('#password').type(this.common.uniquePwd);
52+
cy.get('form[name="login_user_form"]').submit();
53+
// Check that the user is logged
54+
cy.get('#my-account-menu').should('contain', this.users.librarians.leonard.initials);
55+
// Check professional interface access
56+
cy.visit('/professional');
57+
cy.get('body').should('contain','RERO ILS administration');
58+
});
59+
60+
it('Logout', function() {
61+
// Click on username
62+
cy.get('#my-account-menu').click()
63+
// Wait for the menu to open
64+
cy.wait(1000)
65+
// Click on logout
66+
cy.get('#logout-menu').click();
67+
// Check that the user is logged out
68+
cy.get('body').should('contain','My account');
69+
});
70+
71+
it('Login as a patron', function() {
72+
cy.get('#my-account-menu').click();
73+
cy.wait(1000);
74+
cy.get('#login-menu').click();
75+
// Fill the form
76+
cy.get('#email').type(this.users.patrons.james.email);
77+
cy.get('#password').type(this.common.uniquePwd);
78+
cy.get('form[name="login_user_form"]').submit();
79+
// Check that the user is logged
80+
cy.get('#my-account-menu').should('contain', this.users.patrons.james.initials);
81+
});
82+
});

Diff for: tests/e2e/cypress/cypress/integration/circulation/scenario-a.spec.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,11 @@ describe('Circulation scenario A: standard loan', function() {
4646
before('Login as a professional and create a document and an item', function() {
4747
// Create server to watch api requests
4848
cy.server();
49-
// Open app on frontpage
50-
cy.visit('');
51-
// Check language and force to english
52-
cy.setLanguageToEnglish();
5349
// Login as librarian (Leonard)
5450
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
5551
// Create a document
5652
// Go to document editor
57-
cy.goToMenu('create-bibliographic-record-menu-frontpage');
53+
cy.visit('/professional/records/documents/new');
5854
// Populate form with simple record
5955
cy.populateSimpleRecord(this.documents.book);
6056
//Save record
@@ -69,7 +65,7 @@ describe('Circulation scenario A: standard loan', function() {
6965
});
7066

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

115112
// The item should be marked as available in user profile view
116113
// Go to patrons list
117-
cy.goToMenu('users-menu-frontpage')
114+
cy.get('#user-services-menu').click();
115+
cy.get('#users-menu').click();
118116
// Go to James patron profile
119117
cy.get('#' + this.users.patrons.james.barcode + '-loans').click()
120118
// Click on tab called "To pick up"
@@ -129,7 +127,8 @@ describe('Circulation scenario A: standard loan', function() {
129127
*/
130128
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
131129
// Go to circulation search bar
132-
cy.goToMenu('circulation-menu-frontpage');
130+
cy.get('#user-services-menu').click();
131+
cy.get('#circulation-menu').click();
133132
// Checkout
134133
cy.scanPatronBarcodeThenItemBarcode(this.users.patrons.james, this.itemBarcode);
135134
// Item barcode should be present
@@ -143,13 +142,13 @@ describe('Circulation scenario A: standard loan', function() {
143142
*/
144143
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
145144
// Go to circulation search bar
146-
cy.goToMenu('circulation-menu-frontpage');
145+
cy.get('#user-services-menu').click();
146+
cy.get('#circulation-menu').click();
147147
// Checkin
148148
cy.scanItemBarcode(this.itemBarcode);
149149
// CHeck that the item was checked in and that it is on shelf
150150
cy.get('#item-' + this.itemBarcode).should('contain', this.itemBarcode);
151151
cy.get('#item-' + this.itemBarcode).should('contain', 'on shelf');
152152
cy.get('#item-' + this.itemBarcode).should('contain', 'checked in');
153-
cy.logout();
154153
});
155154
});

Diff for: tests/e2e/cypress/cypress/integration/circulation/scenario-b.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,11 @@ describe('Circulation scenario B: standard loan with transit', function() {
4646
* 6. The item is received at owning library and goes on shelf.
4747
*/
4848
before('Login as a professional and create a document and an item', function() {
49-
// Open app on frontpage
50-
cy.visit('');
51-
// Check language and force to english
52-
cy.setLanguageToEnglish();
5349
// Login as librarian (Leonard)
5450
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
5551
// Create a document
5652
// Go to document editor
57-
cy.goToMenu('create-bibliographic-record-menu-frontpage');
53+
cy.visit('/professional/records/documents/new');
5854
// Populate form with simple record
5955
cy.populateSimpleRecord(this.documents.book);
6056
//Save record
@@ -69,7 +65,7 @@ describe('Circulation scenario B: standard loan with transit', function() {
6965
});
7066

7167
after('Clean data: remove item and document', function() {
72-
// TODO: find a way to preserve cookies (auth) and server after a test
68+
cy.logout();
7369
cy.server();
7470
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
7571
// Go to document detail view and remove item
@@ -106,7 +102,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
106102
// Login as librarian (Leonard)
107103
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
108104
// Go to requests list
109-
cy.goToMenu('requests-menu-frontpage')
105+
cy.get('#user-services-menu').click();
106+
cy.get('#requests-menu').click();
110107
// Check that the document is present
111108
cy.get('table').should('contain', this.itemBarcode);
112109
// Enter the barcode and validate
@@ -122,7 +119,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
122119
// Login as librarian
123120
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
124121
// Go to checkin view
125-
cy.goToMenu('circulation-menu-frontpage');
122+
cy.get('#user-services-menu').click();
123+
cy.get('#circulation-menu').click();
126124
// Enter item barcode for receive
127125
cy.get('#search').type(this.itemBarcode).type('{enter}');
128126
// Check that the item has been received
@@ -135,7 +133,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
135133
// Login as librarian
136134
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
137135
// Go to checkin view
138-
cy.goToMenu('circulation-menu-frontpage');
136+
cy.get('#user-services-menu').click();
137+
cy.get('#circulation-menu').click();
139138
// Checkout
140139
cy.scanPatronBarcodeThenItemBarcode(james, this.itemBarcode)
141140
// Check that the checkout has been done
@@ -148,7 +147,8 @@ describe('Circulation scenario B: standard loan with transit', function() {
148147
// Login as librarian
149148
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
150149
// Go to checkin view
151-
cy.goToMenu('circulation-menu-frontpage');
150+
cy.get('#user-services-menu').click();
151+
cy.get('#circulation-menu').click();
152152
// Checkin
153153
cy.scanItemBarcode(this.itemBarcode);
154154
// Check that the checkin has been done
@@ -164,14 +164,14 @@ describe('Circulation scenario B: standard loan with transit', function() {
164164
// Login as librarian
165165
cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd);
166166
// Go to checkin view
167-
cy.goToMenu('circulation-menu-frontpage');
167+
cy.get('#user-services-menu').click();
168+
cy.get('#circulation-menu').click();
168169
// Receive
169170
cy.scanItemBarcode(this.itemBarcode);
170171
// Check that the item has been received
171172
cy.get('#item-' + this.itemBarcode + ' [name="action-done"]').should('contain', 'receive');
172173
// Check that the item is on shelf
173174
cy.get('#item-' + this.itemBarcode + ' [name="circ-info"] [name="status"]')
174175
.should('contain', 'on shelf');
175-
cy.logout();
176176
});
177177
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/// <reference types="Cypress" />
2+
/*
3+
4+
RERO ILS
5+
Copyright (C) 2020 RERO
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Affero General Public License as published by
9+
the Free Software Foundation, version 3 of the License.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
*/
20+
21+
before(function () {
22+
cy.fixture('users').then(function (userData) {
23+
this.users = userData;
24+
});
25+
cy.fixture('common').then(function (commonData) {
26+
this.common = commonData;
27+
});
28+
cy.fixture('collections').then(function (collections) {
29+
this.collections = collections;
30+
});
31+
});
32+
33+
describe('Collections', function() {
34+
/**
35+
* DESCRIPTION
36+
*
37+
*/
38+
before('Login as a professional', function() {
39+
// Login as librarian (Leonard)
40+
cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd);
41+
});
42+
43+
beforeEach(() => {
44+
Cypress.Cookies.preserveOnce('session');
45+
});
46+
47+
after('Clean data: remove collection', function() {
48+
// Delete collection and confirm
49+
cy.get('#detail-delete-button').click();
50+
cy.get('#modal-confirm-button').click();
51+
cy.logout();
52+
});
53+
54+
it('Create a course', function() {
55+
let course = this.collections.course;
56+
// Go to collection list
57+
cy.get('#user-services-menu').click();
58+
cy.get('#collections-menu').click();
59+
// Click add button
60+
cy.get('#search-add-button').click();
61+
// Fill in the form
62+
cy.fillCollectionEditor(course);
63+
// Check the course
64+
cy.checkCollection(course);
65+
});
66+
67+
it('Edit a collection to change it as an exhibition', function() {
68+
let exhibition = this.collections.exhibition;
69+
// Go to editor
70+
cy.get('#detail-edit-button').click();
71+
// Fill in the form
72+
cy.fillCollectionEditor(exhibition);
73+
// Check the exhibition
74+
cy.checkCollection(exhibition);
75+
});
76+
});

Diff for: tests/e2e/cypress/cypress/integration/editor/document/create-simple-document.spec.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,19 @@ before(function () {
3232
describe('Document editor', function() {
3333
before('Login as a professional and create an item', function() {
3434
this.spock = this.users.librarians.spock;
35-
//Open app on frontpage
36-
cy.visit('');
37-
// Check language and force to english
38-
cy.setLanguageToEnglish();
3935
// Login as librarian
4036
cy.adminLogin(this.spock.email, this.common.uniquePwd);
4137
});
4238

4339
after('Clean data: remove document', function() {
4440
// Delete record
4541
cy.deleteRecordFromDetailView();
42+
cy.logout();
4643
});
4744

4845
it('Creates a document with only essential fields', function() {
4946
// Go to document editor
50-
cy.goToMenu('create-bibliographic-record-menu-frontpage');
47+
cy.visit('/professional/records/documents/new');
5148
// Populate form with simple record
5249
cy.populateSimpleRecord(this.documents.book);
5350
//Save record

0 commit comments

Comments
 (0)