Skip to content

Commit

Permalink
ACQUI-42: Add cypress tests for the settings module
Browse files Browse the repository at this point in the history
  • Loading branch information
mblenk committed Jun 27, 2024
1 parent 7e0da45 commit e7ba10c
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/Settings/ModuleSettings.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div v-if="initialized">
<h1>{{ moduleTitle }} settings</h1>
<form @submit="onSubmit($event)" v-if="settingsRenderingData.length">
<form @submit="onSubmit($event)" v-if="settingsRenderingData.length" id="settingsForm">
<fieldset class="rows">
<ol>
<ol id="settingsList">
<SettingFormElement
v-for="(item, key) in settingsRenderingData"
v-bind:key="key"
Expand Down
131 changes: 131 additions & 0 deletions tests/cypress/e2e/settings/ModulesEnabled_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@

describe("modulesEnabled", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
});

it("Should correctly show the modules in modulesEnabled settings", () => {
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
cy.visit("/acquisitions/settings/general");
cy.get("#modulesEnabled").find(".vs__actions").click();
cy.get("#modulesEnabled").find("li").as("options");
cy.get("@options").should("have.length", 1);

cy.get("#modulesEnabled .vs__open-indicator").click();
cy.get("#modulesEnabled .vs__dropdown-menu li:first").should(
"have.text",
"Funds and ledgers"
);
})

it("Should show newly selected modules on the settings homepage", () => {
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
cy.visit("/acquisitions/settings/general");
cy.get("#modulesEnabled .vs__search").type(
"Funds and ledgers" + "{enter}",
{ force: true }
);

cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "funds",
"variable": "modulesEnabled"
}
]
);
cy.get("#settingsForm > fieldset.action > input[type=submit]").click();

//Should navigate back to the settings homepage and show the new module
cy.get("h1").contains("Settings");
cy.get(".navPanesGrid").children().should("have.length", 4);
cy.get(".navPanesGrid > a:nth-child(3) > span").contains("Funds and ledgers");
})

it("Should show newly selected modules in the left hand menu", () => {
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
cy.visit("/acquisitions/settings/general");
cy.get("#modulesEnabled .vs__search").type(
"Funds and ledgers" + "{enter}",
{ force: true }
);

cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "funds",
"variable": "modulesEnabled"
}
]
);
cy.get("#settingsForm > fieldset.action > input[type=submit]").click();

//Should navigate back to the settings homepage and include the new module in the left hand menu
cy.get("h1").contains("Settings");
cy.get("#navmenulist > h5").contains("Acquisitions");
cy.get("#navmenulist > ul").children().should("have.length", 3);
cy.get("#navmenulist > ul > li:nth-child(1) > span > a > span").contains("Funds and ledgers");
cy.get("#navmenulist > ul > li:nth-child(2) > span > a > span").contains("Tasks");
cy.get("#navmenulist > ul > li:nth-child(3) > span > a > span").contains("Settings");
})
});
80 changes: 80 additions & 0 deletions tests/cypress/e2e/settings/Settings_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
describe("Acquisitions settings", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
});

it("Should load the settings homepage", () => {
cy.visit("/acquisitions/settings");
cy.get("h1").contains("Settings");
});

it("Should only show active modules and base modules", () => {
cy.visit("/acquisitions/settings");
cy.get(".navPanesGrid").children().should("have.length", 3);
cy.get(".navPanesGrid > a:nth-child(1) > span").contains("General");
cy.get(".navPanesGrid > a:nth-child(2) > span").contains("Task management");
cy.get(".navPanesGrid > a:nth-child(3) > span").contains("Manual");
})

it("Should show module settings in each Module", () => {
// We'll use the general module for testing
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
cy.visit("/acquisitions/settings/general");
cy.get("h1").contains("General settings");
cy.get("#settingsList").children().should("have.length", 1);
cy.get("#settingsList > li:nth-child(1) > label").contains("modulesEnabled:");
})

});

describe("Acquisitions settings for a user with no settings permissions", () => {
beforeEach(() => {
cy.login('CPLmanage_budgets', 'Test1234');
cy.title().should("eq", "Koha staff interface");
cy.intercept(
"GET",
"/api/v1/contrib/acquire/settings",
[
{
"explanation": "Select which modules you wish to use in the acquisitions portal",
"options": "",
"type": "multiple",
"value": "",
"variable": "modulesEnabled"
}
]
);
});

it("Should only show the manual", () => {
cy.visit("/acquisitions/settings");
cy.get(".navPanesGrid").children().should("have.length", 1);
cy.get(".navPanesGrid > a:nth-child(1) > span").contains("Manual");
})
})

0 comments on commit e7ba10c

Please sign in to comment.