Skip to content

Commit

Permalink
tests: add cypress tests for document creation
Browse files Browse the repository at this point in the history
* Add tests to check document creation field by field.
* Moves api requests commands in corresponding resource file.
* Improves some tests for easier maintenance.
* Fix broken tests.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger authored and AoNoOokami committed Feb 22, 2021
1 parent 2955915 commit 6392a25
Show file tree
Hide file tree
Showing 11 changed files with 541 additions and 73 deletions.
119 changes: 116 additions & 3 deletions tests/e2e/cypress/cypress/fixtures/documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"languageCode2": "eng",
"provisionActivity": {
"type": "Distribution",
"bfType": "bf:Distribution",
"publicationDate1": "2019",
"publicationDate2": "2020",
"statement":{
Expand All @@ -39,9 +40,121 @@
"name": "Plo, Isabelle"
}
},
"responsibilityStatement": {
"value": "Allen J Coombes",
"language": "arm-armn"
"responsibilityStatement": [
{
"value": "Georges Bohas",
"language": "ara-arab"
},
{
"value": "Christian Jacq"
},
{
"value": "Charlotte Le Van"
}
],
"format": "in-plano",
"extent": "136 p. 22 cm",
"dimensions": [
"29 cm"
],
"subjects": [
"Abgaberecht",
"Steuer"
],
"colorContent": [
{
"value": "polychrome",
"code": "rdacc:1003"
}
],
"abstracts": [
"La reine Ahotep a reconquis une grande partie du sud, au prix de la vie de ceux qu'elle aime."
],
"copyrightDate": [
"\u00a9 1999"
],
"duration": [
"231 Min."
],
"illustrativeContent": [
"illustrations"
],
"productionMethod": [
{
"value": "embossing",
"code": "rdapm:1018"
}
],
"translatedFrom": [
"French"
],
"titlesProper": [
"Babel."
]
},
"bookPublication": {
"type": "Book",
"title": {
"mainTitle": "Title test",
"language": "arm-armn",
"subTitle": "Other title",
"partNumber": "Part number",
"partName": "Part name"
},
"language1": "French",
"language2": "English",
"languageCode1": "fre",
"languageCode2": "eng",
"provisionActivity": {
"type": "Publication",
"bfType": "bf:Publication",
"publicationDate1": "2019",
"publicationDate2": "2020",
"statement":{
"place1": "Place1",
"place2": "Place2",
"agent": "Agent",
"date": "Date"
},
"note": "Provision activity note",
"place": "Afghanistan (af)"
},
"issuance": {
"mainType": "single unit",
"mainTypeCode": "rdami:1001",
"subtype": "Material unit",
"subtypeCode": "materialUnit"
},
"authors": {
"person":{
"search": "plo",
"name": "Plo, Isabelle"
}
},
"responsibilityStatement": [
{
"value": "Georges Bohas",
"language": "ara-arab"
}
]
},
"bookSimple": {
"type":[{
"main_type":"docmaintype_book",
"subtype":"docsubtype_other_book"
}],
"title": {
"mainTitle": "Title test"
},
"language1": "French",
"language2": "English",
"languageCode1": "fre",
"languageCode2": "eng",
"issuance": {
"mainType": "single unit",
"mainTypeCode": "rdami:1001",
"subtype": "Material unit",
"subtypeCode": "materialUnit"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ describe('Circulation scenario A: standard loan', function() {
// Search for the item
cy.goToPublicDocumentDetailView(documentPid);
// Request the item
cy.get('#item-request-' + itemPid + ' .btn').click();
cy.get('#item-' + itemPid + '-request-button').click();
// Select pickup location (force because menu can go over browser view)
cy.get('#pickup').select(this.items.starfleetStandardLoan.pickupName);
cy.get('#pickup-location-' + itemPid + ' .btn').click();
cy.get('#pickup-location-' + itemPid + '-confirm-button').click();
cy.wait('@itemRequest');
// Go to user profile, on requests-tab
cy.visit('/global/patrons/profile');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ describe('Circulation scenario B: standard loan with transit', function() {
// Search for the item
cy.goToPublicDocumentDetailView(documentPid);
// Request the item
cy.get('#item-request-' + itemPid + ' .btn').click();
cy.get('#item-' + itemPid + '-request-button').click();
// Select pickup location (force because menu can go over browser view)
cy.get('#pickup').select(this.items.starfleetStandardLoanWithTransit.pickupName);
cy.get('#pickup-location-' + itemPid + ' .btn').click(); cy.wait('@itemRequest');
cy.get('#pickup-location-' + itemPid + '-confirm-button').click();
cy.wait('@itemRequest');
// Go to user profile, directly on requests-tab
cy.visit('/global/patrons/profile');
cy.get('#requests-tab').click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/// <reference types="Cypress" />
/*
RERO ILS
Copyright (C) 2021 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('documents').then(function (documents) {
this.documents = documents;
});
cy.fixture('users').then(function (userData) {
this.users = userData;
});
cy.fixture('common').then(function (commonData) {
this.common = commonData;
});
})

describe('Create a document with provision activity', function() {
let documentPid;
let documentTitleSuffix = ' ' + cy.getCurrentDateAndHour();
before('Login as a professional and create a simple document', function() {
this.spock = this.users.librarians.spock;
// Login as librarian
cy.adminLogin(this.spock.email, this.common.uniquePwd);
cy.apiCreateDocument(this.documents.book, documentTitleSuffix);
cy.get('@getDocumentPid').then((pid) => {
documentPid = pid;
});
});

beforeEach('Preserve logged user', function() {
// Preserve authentication information between the tests
Cypress.Cookies.preserveOnce('session');
});

after('Clean data: remove document', function() {
// Delete document
cy.apiDeleteResources('documents', 'pid:"'+ documentPid + '"');
cy.logout();
cy.log('End of the test');
});

it('Add provision activity', function() {
cy.intercept('/api/permissions/documents/' + documentPid).as('getDocPermission');
// Go to document editor
cy.visit('/professional/records/documents/edit/' + documentPid);
cy.wait('@getDocPermission');
// Add date 2
cy.get('#provisionActivity-0').click();
cy.get('#dropdown-basic > :nth-child(2)').click();
cy.get('#provisionActivity-0-endDate').type(this.documents.book.provisionActivity.publicationDate2);
// Add places
cy.get('#provisionActivity-0-place-0-country').select(this.documents.book.provisionActivity.place);
// Add statements
cy.get('#provisionActivity-0-statement-0-type').select('Place');
cy.get('#provisionActivity-0-statement-0-label-0-value').clear();
cy.get('#provisionActivity-0-statement-0-label-0-value').type(this.documents.book.provisionActivity.statement.place);
cy.get('#provisionActivity-0-statement-1-type').select('agent');
cy.get('#provisionActivity-0-statement-1-label-0-value').clear();
cy.get('#provisionActivity-0-statement-1-label-0-value').type(this.documents.book.provisionActivity.statement.agent);
cy.get('#provisionActivity-0-statement-2-type').select('Date');
cy.get('#provisionActivity-0-statement-2-label-0-value').clear();
cy.get('#provisionActivity-0-statement-2-label-0-value').type(this.documents.book.provisionActivity.statement.date);
// Save
cy.get('#editor-save-button').click();

// Check document detail view
cy.checkDocumentEssentialFields(this.documents.book);
cy.get('#doc-publication-statement-0').should('contain', this.documents.book.provisionActivity.statement.place + ' : '
+ this.documents.book.provisionActivity.statement.agent + ', '
+ this.documents.book.provisionActivity.statement.date);
});

it('Change provision activity', function() {
cy.intercept('/api/permissions/documents/' + documentPid).as('getDocPermission');
// Go to document editor
cy.visit('/professional/records/documents/edit/' + documentPid);
cy.wait('@getDocPermission');
// Changes provision activity type to publication
cy.get('#provisionActivity-0-type').select(this.documents.bookPublication.provisionActivity.type);
// Change statements
cy.get('#provisionActivity-0-statement-0-label-0-value').clear();
cy.get('#provisionActivity-0-statement-0-label-0-value').type(this.documents.bookPublication.provisionActivity.statement.place1);
cy.get('#provisionActivity-0-statement-2-clone-button').click();
cy.get('#provisionActivity-0-statement-3-type').select('Place');
cy.get('#provisionActivity-0-statement-3-label-0-value').type(this.documents.bookPublication.provisionActivity.statement.place2);
// Save
cy.get('#editor-save-button').click();

// Check document detail view
cy.checkDocumentEssentialFields(this.documents.bookPublication);
cy.get('#doc-publication-statement-0').should('contain', this.documents.bookPublication.provisionActivity.statement.place1 + ' : '
+ this.documents.bookPublication.provisionActivity.statement.agent + ', '
+ this.documents.bookPublication.provisionActivity.statement.date + ' ; '
+ this.documents.bookPublication.provisionActivity.statement.place2);
});
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/// <reference types="Cypress" />
/*
RERO ILS
Copyright (C) 2021 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('documents').then(function (documents) {
this.documents = documents;
});
cy.fixture('users').then(function (userData) {
this.users = userData;
});
cy.fixture('common').then(function (commonData) {
this.common = commonData;
});
})

describe('Create a document with responsibility statement', function() {
let documentPid;
let documentTitleSuffix = ' ' + cy.getCurrentDateAndHour();
before('Login as a professional and create a simple document', function() {
this.spock = this.users.librarians.spock;
// Login as librarian
cy.adminLogin(this.spock.email, this.common.uniquePwd);
cy.apiCreateDocument(this.documents.book, documentTitleSuffix);
cy.get('@getDocumentPid').then((pid) => {
documentPid = pid;
});
});

beforeEach('Preserve logged user', function() {
// Preserve authentication information between the tests
Cypress.Cookies.preserveOnce('session');
});

after('Clean data: remove document', function() {
// Delete document
cy.apiDeleteResources('documents', 'pid:"'+ documentPid + '"');
cy.logout();
cy.log('End of the test');
});

it('Add responsibility statement', function() {
cy.intercept('/api/permissions/documents/' + documentPid).as('getDocPermission');
// Go to document editor
cy.visit('/professional/records/documents/edit/' + documentPid);
cy.wait('@getDocPermission');
// Remove provision activity statement
cy.get('#provisionActivity-0-statement-remove-button').click();
// Display responsibility statement and fill the fields
cy.get('#add-field-8').click();
cy.get('#responsibilityStatement-0-0').click();
cy.get('.dropdown-item').click();
cy.get('#responsibilityStatement-0-0-value').type(this.documents.book.responsibilityStatement[0].value);
cy.get('#responsibilityStatement-0-0-language').select(this.documents.book.responsibilityStatement[0].language);
// Add value (same level)
cy.get('#responsibilityStatement-0-0-clone-button').click();
cy.get('#responsibilityStatement-0-1-value').type(this.documents.book.responsibilityStatement[1].value);
// Add statement
cy.get('#responsibilityStatement-0-clone-button').click();
cy.get('#responsibilityStatement-1-0-value').type(this.documents.book.responsibilityStatement[2].value);

// Save
cy.get('#editor-save-button').click();

// Check document detail view
cy.checkDocumentEssentialFields(this.documents.book);
cy.get('.row > :nth-child(2)').should('contain', this.documents.book.responsibilityStatement[0].value);
cy.get('.row > :nth-child(4)').should('contain', this.documents.book.responsibilityStatement[1].value);
cy.get('.row > :nth-child(6)').should('contain', this.documents.book.responsibilityStatement[2].value);
});
})
Loading

0 comments on commit 6392a25

Please sign in to comment.