Skip to content

Commit

Permalink
cypress: split commands.js in several files
Browse files Browse the repository at this point in the history
* Splits commands.js in several files for better readability.
* Adds circulation custom commands.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger committed Aug 12, 2020
1 parent 8f4782e commit a019cc3
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,8 @@ describe('Circulation checkout checkin', function() {
// Go to Circulation
cy.goToMenu('circulation-menu-frontpage')

// Enter a patron barcode
cy.get('#search', {timeout: timeOut})
.type(patronBarcode)
.type('{enter}')

// Assert that patron info is displayed
cy.wait(3000)
cy.get(':nth-child(2) > :nth-child(1) > .col-md-10', {timeout: timeOut})
.should('contain', simonetta.fullname)

// Checkout
cy.get('#search', {timeout: 4500})
.type(itemBarcode)
.type('{enter}')
cy.wait(800)
cy.scanPatronBarcodeThenItemBarcode(patronBarcode, simonetta.fullname, itemBarcode);

// Assert checkout
cy.get(':nth-child(2) > .col > admin-item > .row > :nth-child(1) > a', {timeout: timeOut})
Expand All @@ -70,9 +57,7 @@ describe('Circulation checkout checkin', function() {
.should('have.class', 'fa-arrow-circle-o-right')

// Checkin
cy.get('#search', {timeout: timeOut})
.type(itemBarcode)
.type('{enter}')
cy.scanItemBarcode(itemBarcode);

// Assert checkin
cy.get(':nth-child(11) > .col > admin-item > .row > :nth-child(1) > a', {timeout: timeOut})
Expand Down
36 changes: 36 additions & 0 deletions tests/e2e/cypress/cypress/support/circulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <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/>.
*/
// Scan the patron barcode, then the item barcode (this does a checkout)
Cypress.Commands.add('scanPatronBarcodeThenItemBarcode', (patronBarcode, patronName, itemBarcode) => {
// Enter patron barcode
cy.get('#search').type(patronBarcode).type('{enter}');
// Assert that patron info is displayed
cy.wait(3000)
cy.get(':nth-child(2) > :nth-child(1) > .col-md-10', {timeout: 3000})
.should('contain', patronName)
// Enter item barcode for checkout
cy.get('#search').type(itemBarcode).type('{enter}');
});

// Scan the barcode of an item (this can do a checkin, a receive or "nothing", depending on context)
Cypress.Commands.add('scanItemBarcode', (itemBarcode) => {
// Enter item barcode for checkout
cy.get('#search').type(itemBarcode).type('{enter}');
});
121 changes: 0 additions & 121 deletions tests/e2e/cypress/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,127 +57,6 @@ Cypress.Commands.add("setup", () => {
})
//#endregion

//#region User
// Logout
Cypress.Commands.add("logout", () => {
// click on username
cy.get('#my-account-menu').click()
// then click on Logout link
cy.get('#logout-menu').click()
})

Cypress.Commands.add("login", (email, password) => {
// click on "My account"
cy.get('#my-account-menu').click()
cy.get('#login-menu').click()
cy.get('#email').type(email)
cy.get('#password').type(password)
cy.get('form[name="login_user_form"]').submit()
})

// Login to professional interface
Cypress.Commands.add("adminLogin", (email, password) => {
cy.login(email, password)
cy.wait(1000)

// set language to english BEFORE going to professional interface
cy.setLanguageToEnglish()

// go to professional interface
cy.get('#my-account-menu').click()
cy.get('#professional-interface-menu').click()
cy.url().should('include', '/professional/')
})
//#endregion

//#region Navigation
// Go to user profile (using menus)
// tabId: (not mandatory). If exists: go directly to given tabId
Cypress.Commands.add("userProfile", (tabId) => {
// we should be already connected
cy.get('#my-account-menu').click()
cy.get('#my-profile-menu').click()
cy.wait(2500)
// Go to tabId if exist
if (tabId !== undefined) {
cy.get('#' + tabId).click()
}
})

// Go to a specific menu from professional homepage
// menuId: `id=` attribute content
Cypress.Commands.add("goToMenu", (menuId) => {
// Go to professional homepage
cy.get('#homepage-logo').click()
// if already on professional, do nothing
cy.url().then((url) => {
if (!url.includes('/professional/')) {
cy.get('#my-account-menu').click()
cy.get('#professional-interface-menu').click()
cy.wait(800)
}
})

// Check we're on admin page
cy.url().should('include', '/professional/')
// Click on 'menuTitle' from Catalog menu
cy.get('#' + menuId).click()
})

Cypress.Commands.add("goToItem", (itemBarcode) => {
// Go to homepage
cy.get('#homepage-logo').click()
cy.wait(800)
cy.url().then((url) => {
if (url.includes('/professional/')) {
// on professional context
cy.get('.form-control').type(itemBarcode).type('{enter}')
}
else {
// on public context
cy.get('.d-none > main-search-bar > .flex-grow-1 > .rero-ils-autocomplete > .form-control').type(itemBarcode).type('{enter}')
}
})
// Use first element
cy.get('.card-title > a').click()
})
//#endregion

//#region Record
Cypress.Commands.add("createItem", (barcode, itemType, localisation) => {
// Go to Catalog > Documents
cy.goToMenu('documents-menu-frontpage')
// Use one document (between first and tenth)
let randomInteger = Math.floor((Math.random() * 9) + 1);
cy.wait(2100) // because ngx-spinner hide the menu with a black transparent filter
cy.get(':nth-child(' + randomInteger.toString() + ') > ng-core-record-search-result > admin-documents-brief-view > .card-title > a').click()
// Click on "Add…" button to add an item
cy.get('.col > .btn').click()
// Fill in Item barcode
cy.get('#barcode').type(barcode)
// Wait that barcode to be checked (by API)
cy.wait(800)
// Fill in Item Call number with barcode content
cy.get('#call_number').type(barcode)
// Fill in Item Category
cy.get('select').first().select(itemType)
// Fill in localisation (could be 0, 1, etc. to select first element from select list)
cy.get('select').eq(1).select(localisation)

// Validate the form
cy.get('.mt-4 > [type="submit"]').click()

// Assert that the item has been created
cy.contains(barcode, {timeout: 8000})
})
//#endregion

Cypress.Commands.add("deleteRecordFromDetailView", () => {
// Delete record and confirm deletion
cy.get('#detail-delete-button').click();
cy.get('#modal-confirm-button').click();
});

//#region Document editor ----------------------------------------------------->
Cypress.Commands.add("populateSimpleRecord", (document) => {
cy.fixture('document').then(function (documentData) {
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/cypress/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// Import commands.js using ES2015 syntax:
import './commands'
import './utils'
import './circulation'
import './user'
import './navigation'
import './record'

// Alternatively you can use CommonJS syntax:
// require('./commands')
69 changes: 69 additions & 0 deletions tests/e2e/cypress/cypress/support/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// <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/>.
*/
// Go to user profile (using menus)
// tabId: (not mandatory). If exists: go directly to given tabId
Cypress.Commands.add("userProfile", (tabId) => {
// we should be already connected
cy.get('#my-account-menu').click()
cy.get('#my-profile-menu').click()
cy.wait(2500)
// Go to tabId if exist
if (tabId !== undefined) {
cy.get('#' + tabId).click()
}
})

// Go to a specific menu from professional homepage
// menuId: `id=` attribute content
Cypress.Commands.add("goToMenu", (menuId) => {
// Go to professional homepage
cy.get('#homepage-logo').click()
// if already on professional, do nothing
cy.url().then((url) => {
if (!url.includes('/professional/')) {
cy.get('#my-account-menu').click()
cy.get('#professional-interface-menu').click()
cy.wait(800)
}
})

// Check we're on admin page
cy.url().should('include', '/professional/')
// Click on 'menuTitle' from Catalog menu
cy.get('#' + menuId).click()
})

Cypress.Commands.add("goToItem", (itemBarcode) => {
// Go to homepage
cy.get('#homepage-logo').click()
cy.wait(800)
cy.url().then((url) => {
if (url.includes('/professional/')) {
// on professional context
cy.get('.form-control').type(itemBarcode).type('{enter}')
}
else {
// on public context
cy.get('.d-none > main-search-bar > .flex-grow-1 > .rero-ils-autocomplete > .form-control').type(itemBarcode).type('{enter}')
}
})
// Use first element
cy.get('.card-title > a').click()
})
51 changes: 51 additions & 0 deletions tests/e2e/cypress/cypress/support/record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// <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/>.
*/
Cypress.Commands.add("createItem", (barcode, itemType, localisation) => {
// Go to Catalog > Documents
cy.goToMenu('documents-menu-frontpage')
// Use one document (between first and tenth)
let randomInteger = Math.floor((Math.random() * 9) + 1);
cy.wait(2100) // because ngx-spinner hide the menu with a black transparent filter
cy.get(':nth-child(' + randomInteger.toString() + ') > ng-core-record-search-result > admin-documents-brief-view > .card-title > a').click()
// Click on "Add…" button to add an item
cy.get('.col > .btn').click()
// Fill in Item barcode
cy.get('#barcode').type(barcode)
// Wait that barcode to be checked (by API)
cy.wait(800)
// Fill in Item Call number with barcode content
cy.get('#call_number').type(barcode)
// Fill in Item Category
cy.get('select').first().select(itemType)
// Fill in localisation (could be 0, 1, etc. to select first element from select list)
cy.get('select').eq(1).select(localisation)

// Validate the form
cy.get('.mt-4 > [type="submit"]').click()

// Assert that the item has been created
cy.contains(barcode, {timeout: 8000})
})

Cypress.Commands.add("deleteRecordFromDetailView", () => {
// Delete record and confirm deletion
cy.get('#detail-delete-button').click();
cy.get('#modal-confirm-button').click();
});
49 changes: 49 additions & 0 deletions tests/e2e/cypress/cypress/support/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/// <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/>.
*/
// Logout
Cypress.Commands.add("logout", () => {
// click on username
cy.get('#my-account-menu').click()
// then click on Logout link
cy.get('#logout-menu').click()
})

Cypress.Commands.add("login", (email, password) => {
// click on "My account"
cy.get('#my-account-menu').click()
cy.get('#login-menu').click()
cy.get('#email').type(email)
cy.get('#password').type(password)
cy.get('form[name="login_user_form"]').submit()
})

// Login to professional interface
Cypress.Commands.add("adminLogin", (email, password) => {
cy.login(email, password)
cy.wait(1000)

// set language to english BEFORE going to professional interface
cy.setLanguageToEnglish()

// go to professional interface
cy.get('#my-account-menu').click()
cy.get('#professional-interface-menu').click()
cy.url().should('include', '/professional/')
})

0 comments on commit a019cc3

Please sign in to comment.