-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements Cypress to about template create and utilisation. Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
- Loading branch information
Showing
6 changed files
with
188 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"templateA": { | ||
"name": "Cypress template", | ||
"document": { | ||
"type": "sound", | ||
"title": { | ||
"mainTitle": "Template title" | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
83 changes: 83 additions & 0 deletions
83
tests/e2e/cypress/cypress/integration/templates/templates-test.spec.js
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,83 @@ | ||
/// <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('templates').then(function (templateData) { | ||
this.templates = templateData; | ||
}) | ||
cy.server(); | ||
cy.route({method: 'GET', url:'/api/templates/?q=*'}).as('api_template_search') | ||
cy.route({method: 'GET', url:'**/professional/records/document**)'}).as('document_editor') | ||
cy.route({method: 'POST', url:'/api/templates/'}).as('api_template_create') | ||
}) | ||
|
||
describe('Templates: Create and use template for a document', function() { | ||
|
||
before('Setting defaults', function() { | ||
cy.visit('') | ||
cy.setLanguageToEnglish() | ||
}) | ||
|
||
beforeEach('Login as admin and clean templates', function() { | ||
const template = this.templates.templateA | ||
cy.apiLogout() | ||
cy.apiLogin(this.users.librarians.spock, this.common.uniquePwd) | ||
cy.apiDeleteResources('templates', 'name:"'+template.name+'"') | ||
}) | ||
|
||
after('Logout user', function() { | ||
cy.apiLogout() | ||
}) | ||
|
||
it('Create a new template and use it in the editor', function() { | ||
const template = this.templates.templateA | ||
|
||
cy.visit('/professional/records/documents/new') | ||
cy.wait(2000) | ||
cy.get('ng-core-editor #type').select(template.document.type) | ||
cy.get('#title-0-mainTitle-0-value').type(template.document.title.mainTitle, {force: true}) | ||
cy.get('#editor-save-button-split').click() | ||
cy.get('#editor-save-button-dropdown-split') | ||
.find('li a.dropdown-item:nth-child(1)') // TODO: Find a better way to retrieve the correct link to click | ||
.click() | ||
cy.get('.modal-content #name').type(template.name) | ||
cy.get('.modal-content button:submit').click() | ||
cy.wait('@api_template_create') | ||
cy.url().should('include', 'records/templates/detail') | ||
|
||
cy.visit('/professional/records/documents/new') | ||
cy.wait(2000) | ||
cy.get('#editor-load-template-button').click() | ||
cy.wait('@api_template_search') | ||
cy.get('.modal-content #template').select(template.name) | ||
cy.get('.modal-content button:submit').click() | ||
|
||
cy.url(5000).should('include', '?source=templates&pid=') | ||
cy.get('ng-core-editor #type').invoke('val').should('eq', template.document.type) | ||
cy.get('#title-0-mainTitle-0-value').invoke('val').should('eq', template.document.title.mainTitle) | ||
cy.log('Template loaded successfully !') | ||
}) | ||
}) |
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,75 @@ | ||
/* | ||
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/>. | ||
*/ | ||
|
||
/** API call to logout method ============================================== */ | ||
Cypress.Commands.add('apiLogout', () => { | ||
cy.request({ | ||
method: 'GET', | ||
url: '/signout/', | ||
followRedirect: false | ||
}) | ||
}) | ||
|
||
/** API call to login method ================================================== | ||
* :param user - object: a user object from the 'users' fixtures file | ||
* :param password - string: the password to log in | ||
*/ | ||
Cypress.Commands.add('apiLogin', (user, password) => { | ||
cy.request('/signin') | ||
.its('body') | ||
.then(body => { | ||
const $html = Cypress.$(body) | ||
const csrf_token = $html.find('input[name=csrf_token]').val() | ||
cy.log(csrf_token) | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: '/signin/', | ||
followRedirect: false, | ||
body: { | ||
'email': user.email, | ||
'password': password, | ||
'csrf_token': csrf_token | ||
} | ||
}).then(response => { | ||
cy.visit('/') | ||
cy.get('#logout-menu') // raise an error if not found | ||
}) | ||
}) | ||
}) | ||
|
||
|
||
/** API call to delete items ================================================== | ||
* Delete resource items based on a query | ||
* :param resourceName - string: the resource type | ||
* :param query - string: criteria to find items to delete | ||
*/ | ||
Cypress.Commands.add('apiDeleteResources', (resourceName, query) => { | ||
const q = encodeURI('/api/'+resourceName+'/?q='+query) | ||
cy.request(q).its('body.hits.hits', {timeout:2000}).then(hits => { | ||
hits.forEach(hit => { | ||
const pid = hit.metadata.pid | ||
cy.request({ | ||
method: 'DELETE', | ||
url: '/api/'+resourceName+'/'+pid | ||
}) | ||
cy.log('Template#'+pid+' deleted') | ||
}) | ||
}) | ||
}) |
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