@@ -, +, @@ --- t/cypress/integration/Agreements_spec.ts | 9 +++++++ t/cypress/integration/Licenses_spec.ts | 9 +++++++ t/cypress/integration/Packages_spec.ts | 9 +++++++ t/cypress/integration/Titles_spec.ts | 9 +++++++ t/cypress/support/commands.js | 30 ++++++++++++++++++++++++ 5 files changed, 66 insertions(+) --- a/t/cypress/integration/Agreements_spec.ts +++ a/t/cypress/integration/Agreements_spec.ts @@ -117,9 +117,18 @@ function get_licenses_to_relate() { } describe("Agreement CRUD operations", () => { + before(() => { + cy.fetch_initial_ERM_sys_pref_value(); + }); + beforeEach(() => { cy.login("koha", "koha"); cy.title().should("eq", "Koha staff interface"); + cy.set_ERM_sys_pref_value(true); + }); + + after(() => { + cy.reset_initial_ERM_sys_pref_value(); }); it("List agreements", () => { --- a/t/cypress/integration/Licenses_spec.ts +++ a/t/cypress/integration/Licenses_spec.ts @@ -33,9 +33,18 @@ function get_license() { } describe("License CRUD operations", () => { + before(() => { + cy.fetch_initial_ERM_sys_pref_value(); + }); + beforeEach(() => { cy.login("koha", "koha"); cy.title().should("eq", "Koha staff interface"); + cy.set_ERM_sys_pref_value(true); + }); + + after(() => { + cy.reset_initial_ERM_sys_pref_value(); }); it("List license", () => { --- a/t/cypress/integration/Packages_spec.ts +++ a/t/cypress/integration/Packages_spec.ts @@ -24,9 +24,18 @@ function get_package() { } describe("Package CRUD operations", () => { + before(() => { + cy.fetch_initial_ERM_sys_pref_value(); + }); + beforeEach(() => { cy.login("koha", "koha"); cy.title().should("eq", "Koha staff interface"); + cy.set_ERM_sys_pref_value(true); + }); + + after(() => { + cy.reset_initial_ERM_sys_pref_value(); }); it("List package", () => { --- a/t/cypress/integration/Titles_spec.ts +++ a/t/cypress/integration/Titles_spec.ts @@ -67,9 +67,18 @@ function get_packages_to_relate() { } describe("Title CRUD operations", () => { + before(() => { + cy.fetch_initial_ERM_sys_pref_value(); + }); + beforeEach(() => { cy.login("koha", "koha"); cy.title().should("eq", "Koha staff interface"); + cy.set_ERM_sys_pref_value(true); + }); + + after(() => { + cy.reset_initial_ERM_sys_pref_value(); }); it("Import titles", () => { --- a/t/cypress/support/commands.js +++ a/t/cypress/support/commands.js @@ -30,4 +30,34 @@ Cypress.Commands.add('login', (username, password) => { cy.get("#userid").type(username) cy.get("#password").type(password) cy.get("#submit-button").click() +}) + +Cypress.Commands.add('set_ERM_sys_pref_value', (enable) => { + cy.visit('/cgi-bin/koha/admin/admin-home.pl') + cy.get("h4").contains("Global system preferences").click(); + cy.get("a[title^=E-Resource]").contains("E-Resource management").click(); + cy.get('#pref_ERMModule').then(($select) => { + // Only enable if currently disabled, or only disable if currently enabled + let sys_pref_value = $select.find(":selected").text().trim(); + if (enable && sys_pref_value == 'Disable' || !enable && sys_pref_value == 'Enable') { + cy.get("#pref_ERMModule").select(enable ? 'Enable' : 'Disable'); + cy.get(".save-all").first().click(); + Cypress.env("current_ERM_Module_sys_pref_value", enable); + cy.wait(500); // Cypress is too fast! + } + }) +}) + +Cypress.Commands.add('fetch_initial_ERM_sys_pref_value', () => { + cy.login("koha", "koha"); + cy.visit('/cgi-bin/koha/admin/admin-home.pl') + cy.get("h4").contains("Global system preferences").click(); + cy.get("a[title^=E-Resource]").contains("E-Resource management").click(); + cy.get('#pref_ERMModule').then(($select) => { + Cypress.env('initial_ERM_Module_sys_pref_value', $select.find(":selected").text().trim() == 'Enable'); + }) +}) + +Cypress.Commands.add('reset_initial_ERM_sys_pref_value', () => { + cy.set_ERM_sys_pref_value(Cypress.env("initial_ERM_Module_sys_pref_value")); }) --