Bug 33625: Pretty .js files for vue

Test plan:
= Koha =
Apply the first patch, prove xt/vue_tidy.t and notice the failure
Apply this patch, now it passes

= QA test =
Apply the change to the merge request linked with this qa-test-tools' issue:
https://gitlab.com/koha-community/qa-test-tools/-/issues/62
inside your ktd container (at /kohadevbox/qa-test-tools/)
Edit a .js within koha-tmpl/intranet-tmpl/prog/js/vue and a .ts file
(cypress test) with something not pretty
Commit and run the QA script
=> It's failing!
Pretty the change, commit again, run the QA script
=> It's happy!

= KTD - git hook =
Go to the merge request linked with this ktd's issue:
https://gitlab.com/koha-community/koha-testing-docker/-/issues/374
Copy the modified git hook to .git/hooks/ktd/pre-commit
Edit a .js within koha-tmpl/intranet-tmpl/prog/js/vue and a .ts file
(cypress test) with something not pretty
Commit
=> Notice that the commit content is pretty!

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2023-05-02 10:32:37 +02:00
parent 0192bb0cb8
commit 1139972748
17 changed files with 448 additions and 265 deletions

View File

@ -13,7 +13,7 @@ export function useDataTable(table_id) {
export function build_url_params(filters) {
return Object.entries(filters)
.map(([k, v]) => (v ? k + "=" + v : undefined))
.filter((e) => e !== undefined)
.filter(e => e !== undefined)
.join("&");
}
export function build_url(base_url, filters) {

View File

@ -9,7 +9,7 @@ export class AcquisitionAPIClient extends HttpClient {
get vendors() {
return {
getAll: (query) =>
getAll: query =>
this.get({
endpoint: "vendors?" + (query || "_per_page=-1"),
headers: {

View File

@ -9,16 +9,18 @@ export class AVAPIClient extends HttpClient {
get values() {
return {
getCategoriesWithValues: (cat_array) =>
getCategoriesWithValues: cat_array =>
this.get({
endpoint: "?q={\"me.category_name\":["+(cat_array.join(", "))+"]}",
endpoint:
'?q={"me.category_name":[' +
cat_array.join(", ") +
"]}",
headers: {
"x-koha-embed":
"authorised_values",
"x-koha-embed": "authorised_values",
},
}),
}),
};
}
}
export default AVAPIClient;
export default AVAPIClient;

View File

@ -13,30 +13,31 @@ class HttpClient {
headers = {},
options = {},
return_response = false,
mark_submitting = false,
mark_submitting = false
) {
let res, error;
if ( mark_submitting) submitting()
if (mark_submitting) submitting();
await fetch(this._baseURL + endpoint, {
...options,
headers: { ...this._headers, ...headers },
})
.then((response) => this.checkError(response, return_response))
.then(response => this.checkError(response, return_response))
.then(
(result) => {
result => {
res = result;
},
(err) => {
err => {
error = err;
setError(err.toString());
}
)
.catch((err) => {
.catch(err => {
error = err;
setError(err);
}).then(() => {
if (mark_submitting) submitted()})
;
})
.then(() => {
if (mark_submitting) submitted();
});
if (error) throw Error(error);
@ -52,11 +53,12 @@ class HttpClient {
getAll(params = {}) {
let url =
params.endpoint + "?" +
params.endpoint +
"?" +
new URLSearchParams({
_per_page: -1,
...(params.query && { q: JSON.stringify(params.query) }),
})
});
return this._fetchJSON(url, params.headers, {
...params.options,
method: "GET",
@ -69,11 +71,17 @@ class HttpClient {
? params.body
: JSON.stringify(params.body)
: undefined;
return this._fetchJSON(params.endpoint, params.headers, {
...params.options,
body,
method: "POST",
}, false, true);
return this._fetchJSON(
params.endpoint,
params.headers,
{
...params.options,
body,
method: "POST",
},
false,
true
);
}
put(params = {}) {
@ -82,11 +90,17 @@ class HttpClient {
? params.body
: JSON.stringify(params.body)
: undefined;
return this._fetchJSON(params.endpoint, params.headers, {
...params.options,
body,
method: "PUT",
}, false, true);
return this._fetchJSON(
params.endpoint,
params.headers,
{
...params.options,
body,
method: "PUT",
},
false,
true
);
}
delete(params = {}) {
@ -98,19 +112,20 @@ class HttpClient {
...params.options,
method: "DELETE",
},
true, true
true,
true
);
}
count(params = {}) {
let res;
return this._fetchJSON(params.endpoint, params.headers, {}, 1).then(
(response) => {
response => {
if (response) {
return response.headers.get("X-Total-Count");
}
},
(error) => {
error => {
setError(error.toString());
}
);

View File

@ -9,7 +9,7 @@ export class PatronAPIClient extends HttpClient {
get patrons() {
return {
get: (id) =>
get: id =>
this.get({
endpoint: "patrons/" + id,
}),

View File

@ -9,7 +9,7 @@ export class SysprefAPIClient extends HttpClient {
get sysprefs() {
return {
get: (variable) =>
get: variable =>
this.get({
endpoint: "/?pref=" + variable,
}),

View File

@ -41,4 +41,4 @@ export const loaded = function () {
const mainStore = useMainStore();
const { loaded } = mainStore;
loaded();
};
};

View File

@ -34,7 +34,7 @@ const pinia = createPinia();
const i18n = {
install: (app, options) => {
app.config.globalProperties.$__ = (key) => {
app.config.globalProperties.$__ = key => {
return window["__"](key);
};
},
@ -65,14 +65,14 @@ router.beforeEach((to, from) => {
removeMessages(); // This will actually flag the messages as displayed already
});
router.afterEach((to, from) => {
let tab_id = 'agreement'; // Agreements
let tab_id = "agreement"; // Agreements
if (to.path.match(/\/erm\/licenses/)) {
tab_id = 'license';
tab_id = "license";
} else if (to.path.match(/\/erm\/eholdings\/local\/packages/)) {
tab_id = 'package';
tab_id = "package";
} else if (to.path.match(/\/erm\/eholdings\/local\/titles/)) {
tab_id = 'title';
tab_id = "title";
}
let node = document.getElementById(`${tab_id}_search_tab`);

View File

@ -47,11 +47,11 @@ export const useAVStore = defineStore("authorised_values", {
);
return;
}
let o = this[arr_name].find((e) => e.value == av);
let o = this[arr_name].find(e => e.value == av);
return o ? o.description : av;
},
map_av_dt_filter(arr_name) {
return this[arr_name].map((e) => {
return this[arr_name].map(e => {
e["_id"] = e["value"];
e["_str"] = e["description"];
return e;

View File

@ -19,31 +19,35 @@ export const useMainStore = defineStore("main", {
this._warning = null;
this._message = message;
this._confirmation = null;
this.displayed_already = displayed; /* Will be displayed on the next view */
this.displayed_already =
displayed; /* Will be displayed on the next view */
},
setError(error, displayed = true) {
this._error = error;
this._warning = null;
this._message = null;
this._confirmation = null;
this.displayed_already = displayed; /* Is displayed on the current view */
this.displayed_already =
displayed; /* Is displayed on the current view */
},
setWarning(warning, displayed = true) {
this._error = null;
this._warning = warning;
this._message = null;
this._confirmation = null;
this.displayed_already = displayed; /* Is displayed on the current view */
this.displayed_already =
displayed; /* Is displayed on the current view */
},
setConfirmationDialog(confirmation, accept_callback, displayed = true){
if(accept_callback) {
setConfirmationDialog(confirmation, accept_callback, displayed = true) {
if (accept_callback) {
this._accept_callback = async () => {
await accept_callback()
this.removeConfirmationMessages()
}
await accept_callback();
this.removeConfirmationMessages();
};
}
this._confirmation = confirmation;
this.displayed_already = displayed; /* Is displayed on the current view */
this.displayed_already =
displayed; /* Is displayed on the current view */
},
removeMessages() {
if (this.displayed_already) {
@ -55,44 +59,44 @@ export const useMainStore = defineStore("main", {
}
this.displayed_already = true;
},
removeConfirmationMessages(){
removeConfirmationMessages() {
this._confirmation = null;
this._accept_callback = null;
},
submitting(){
submitting() {
this._is_submitting = true;
},
submitted(){
submitted() {
this._is_submitting = false;
},
loading(){
loading() {
this._is_loading = true;
},
loaded(){
loaded() {
this._is_loading = false;
},
},
getters: {
error() {
return this._error
return this._error;
},
warning() {
return this._warning
return this._warning;
},
message() {
return this._message
return this._message;
},
confirmation() {
return this._confirmation
return this._confirmation;
},
accept_callback() {
return this._accept_callback
return this._accept_callback;
},
is_submitting(){
return this._is_submitting
is_submitting() {
return this._is_submitting;
},
is_loading(){
return this._is_loading
is_loading() {
return this._is_loading;
},
},
});

View File

@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import { defineStore } from "pinia";
export const useVendorStore = defineStore('vendors', {
state: () => ({
vendors: [],
}),
})
export const useVendorStore = defineStore("vendors", {
state: () => ({
vendors: [],
}),
});

View File

@ -43,13 +43,13 @@ function get_agreement() {
license_id: 1,
name: "license name",
status: "expired",
type: "alliance"
type: "alliance",
},
license_id:1,
license_id: 1,
notes: "license notes",
physical_location: "cupboard",
status: "controlling",
uri: "license uri"
uri: "license uri",
},
{
agreement_id: 1,
@ -59,39 +59,39 @@ function get_agreement() {
license_id: 2,
name: "second license name",
status: "expired",
type: "alliance"
type: "alliance",
},
license_id:2,
license_id: 2,
notes: "second license notes",
physical_location: "cupboard",
status: "future",
uri: "license uri"
}
uri: "license uri",
},
],
agreement_relationships: [
{
agreement_id: 1,
notes: 'related agreement notes',
notes: "related agreement notes",
related_agreement: {
agreement_id: 2,
description: "agreement description",
name: "agreement name"
name: "agreement name",
},
related_agreement_id: 2,
relationship: "supersedes"
}
relationship: "supersedes",
},
],
agreement_packages: [],
documents: [
{
agreement_id:1,
agreement_id: 1,
file_description: "file description",
file_name: "file.json",
notes: "file notes",
physical_location: "file physical location",
uri: "file uri",
uploaded_on: "2022-10-27T11:57:02+00:00"
}
uploaded_on: "2022-10-27T11:57:02+00:00",
},
],
};
}
@ -101,27 +101,35 @@ function get_licenses_to_relate() {
{
license_id: 1,
description: "a license",
name: "first license name"
name: "first license name",
},
{
license_id: 2,
description: "a second license",
name: "second license name"
name: "second license name",
},
{
license_id: 3,
description: "a third license",
name: "third license name"
name: "third license name",
},
]
];
}
describe("Agreement CRUD operations", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("List agreements", () => {
@ -309,12 +317,18 @@ describe("Agreement CRUD operations", () => {
// Add new document
cy.get("#documents").contains("Add new document").click();
cy.get("#document_0 input[id=file_0]").click();
cy.get('#document_0 input[id=file_0]').selectFile('t/cypress/fixtures/file.json');
cy.get("#document_0 input[id=file_0]").selectFile(
"t/cypress/fixtures/file.json"
);
cy.get("#document_0 .file_information span").contains("file.json");
cy.get('#document_0 input[id=file_description_0]').type('file description');
cy.get('#document_0 input[id=physical_location_0]').type('file physical location');
cy.get('#document_0 input[id=uri_0]').type('file URI');
cy.get('#document_0 input[id=notes_0]').type('file notes');
cy.get("#document_0 input[id=file_description_0]").type(
"file description"
);
cy.get("#document_0 input[id=physical_location_0]").type(
"file physical location"
);
cy.get("#document_0 input[id=uri_0]").type("file URI");
cy.get("#document_0 input[id=notes_0]").type("file notes");
// Submit the form, get 500
cy.intercept("POST", "/api/v1/erm/agreements", {
@ -354,7 +368,9 @@ describe("Agreement CRUD operations", () => {
cy.get("#agreement_license_0 #license_id_0 .vs__search").type(
related_license.license.name
);
cy.get("#agreement_license_0 #license_id_0 .vs__dropdown-menu li").eq(0).click( { force: true } ); //click first license suggestion
cy.get("#agreement_license_0 #license_id_0 .vs__dropdown-menu li")
.eq(0)
.click({ force: true }); //click first license suggestion
cy.get("#agreement_license_0 #license_status_0 .vs__search").type(
related_license.status + "{enter}",
{ force: true }
@ -363,7 +379,9 @@ describe("Agreement CRUD operations", () => {
related_license.physical_location + "{enter}",
{ force: true }
);
cy.get("#agreement_license_0 #license_notes_0").type(related_license.notes);
cy.get("#agreement_license_0 #license_notes_0").type(
related_license.notes
);
cy.get("#agreement_license_0 #license_uri_0").type(related_license.uri);
// Add new related agreement
@ -373,17 +391,24 @@ describe("Agreement CRUD operations", () => {
body: cy.get_agreements_to_relate(),
});
cy.visit("/cgi-bin/koha/erm/agreements/add");
cy.get("#agreement_relationships").contains("Add new related agreement").click();
cy.get("#agreement_relationships")
.contains("Add new related agreement")
.click();
cy.get("#related_agreement_0").contains("Related agreement 1");
cy.get("#related_agreement_0 #related_agreement_id_0 .vs__search").type(
related_agreement.related_agreement.name
);
cy.get("#related_agreement_0 #related_agreement_id_0 .vs__dropdown-menu li").eq(0).click( { force: true } ); //click first agreement suggestion
cy.get("#related_agreement_0 #related_agreement_notes_0").type(related_agreement.notes);
cy.get("#related_agreement_0 #related_agreement_relationship_0 .vs__search").type(
related_agreement.relationship + "{enter}",
{ force: true }
cy.get(
"#related_agreement_0 #related_agreement_id_0 .vs__dropdown-menu li"
)
.eq(0)
.click({ force: true }); //click first agreement suggestion
cy.get("#related_agreement_0 #related_agreement_notes_0").type(
related_agreement.notes
);
cy.get(
"#related_agreement_0 #related_agreement_relationship_0 .vs__search"
).type(related_agreement.relationship + "{enter}", { force: true });
});
it("Edit agreement", () => {
@ -396,10 +421,10 @@ describe("Agreement CRUD operations", () => {
{
method: "GET",
url: "/api/v1/erm/agreements*",
times: 1
times: 1,
},
{
body: agreements
body: agreements,
}
);
@ -458,13 +483,19 @@ describe("Agreement CRUD operations", () => {
cy.get("#notes_1").should("have.value", "this is a note");
//Test related content
cy.get("#agreement_license_0 #license_id_0 .vs__selected").contains("first license name");
cy.get("#agreement_license_1 #license_id_1 .vs__selected").contains("second license name");
cy.get("#document_0 .file_information span").contains("file.json" );
cy.get("#related_agreement_0 #related_agreement_id_0 .vs__selected").contains("agreement name");
cy.get("#agreement_license_0 #license_id_0 .vs__selected").contains(
"first license name"
);
cy.get("#agreement_license_1 #license_id_1 .vs__selected").contains(
"second license name"
);
cy.get("#document_0 .file_information span").contains("file.json");
cy.get(
"#related_agreement_0 #related_agreement_id_0 .vs__selected"
).contains("agreement name");
// Submit the form, get 500
cy.intercept("PUT", "/api/v1/erm/agreements/*", (req) => {
cy.intercept("PUT", "/api/v1/erm/agreements/*", req => {
req.reply({
statusCode: 500,
error: "Something went wrong",
@ -545,7 +576,9 @@ describe("Agreement CRUD operations", () => {
cy.get("#agreements_list table tbody tr:first")
.contains("Delete")
.click();
cy.get(".dialog.alert.confirmation h1").contains("remove this agreement");
cy.get(".dialog.alert.confirmation h1").contains(
"remove this agreement"
);
cy.contains(agreement.name);
// Accept the confirmation dialog, get 500
@ -566,9 +599,13 @@ describe("Agreement CRUD operations", () => {
cy.get("#agreements_list table tbody tr:first")
.contains("Delete")
.click();
cy.get(".dialog.alert.confirmation h1").contains("remove this agreement");
cy.get(".dialog.alert.confirmation h1").contains(
"remove this agreement"
);
cy.contains("Yes, delete").click();
cy.get("main div[class='dialog message']").contains("Agreement").contains("deleted");
cy.get("main div[class='dialog message']")
.contains("Agreement")
.contains("deleted");
// Delete from show
// Click the "name" link from the list
@ -598,11 +635,13 @@ describe("Agreement CRUD operations", () => {
"Agreement #" + agreement.agreement_id
);
cy.get('#agreements_show .action_links .fa-trash').click();
cy.get(".dialog.alert.confirmation h1").contains("remove this agreement");
cy.get("#agreements_show .action_links .fa-trash").click();
cy.get(".dialog.alert.confirmation h1").contains(
"remove this agreement"
);
cy.contains("Yes, delete").click();
//Make sure we return to list after deleting from show
cy.get("#agreements_list table tbody tr:first")
cy.get("#agreements_list table tbody tr:first");
});
});

View File

@ -25,8 +25,16 @@ describe("Dialog operations", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("There are no ... defined", () => {
@ -58,7 +66,9 @@ describe("Dialog operations", () => {
cy.intercept("GET", "/api/v1/erm/agreements*", []);
cy.get("#navmenulist").contains("Agreements").click();
// Info messages should be cleared when view is changed
cy.get("main div[class='dialog message']").contains("There are no agreements defined");
cy.get("main div[class='dialog message']").contains(
"There are no agreements defined"
);
cy.get("main div[class='dialog message']").should("have.length", 1);
});

View File

@ -20,14 +20,14 @@ function get_license() {
user_roles: [],
documents: [
{
license_id:1,
license_id: 1,
file_description: "file description",
file_name: "file.json",
notes: "file notes",
physical_location: "file physical location",
uri: "file uri",
uploaded_on: "2022-10-27T11:57:02+00:00"
}
uploaded_on: "2022-10-27T11:57:02+00:00",
},
],
};
}
@ -36,8 +36,16 @@ describe("License CRUD operations", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("List license", () => {
@ -91,8 +99,12 @@ describe("License CRUD operations", () => {
cy.get("#license_name").type(license.name);
cy.get("#license_description").type(license.description);
cy.get("#licenses_add").contains("Submit").click();
cy.get("#license_type .vs__search").type(license.type + '{enter}',{force:true});
cy.get("#license_status .vs__search").type(license.status + '{enter}',{force:true});
cy.get("#license_type .vs__search").type(license.type + "{enter}", {
force: true,
});
cy.get("#license_status .vs__search").type(license.status + "{enter}", {
force: true,
});
cy.get("#started_on+input").click();
cy.get(".flatpickr-calendar")
@ -110,12 +122,18 @@ describe("License CRUD operations", () => {
// Add new document
cy.get("#documents").contains("Add new document").click();
cy.get("#document_0 input[id=file_0]").click();
cy.get('#document_0 input[id=file_0]').selectFile('t/cypress/fixtures/file.json');
cy.get("#document_0 input[id=file_0]").selectFile(
"t/cypress/fixtures/file.json"
);
cy.get("#document_0 .file_information span").contains("file.json");
cy.get('#document_0 input[id=file_description_0]').type('file description');
cy.get('#document_0 input[id=physical_location_0]').type('file physical location');
cy.get('#document_0 input[id=uri_0]').type('file URI');
cy.get('#document_0 input[id=notes_0]').type('file notes');
cy.get("#document_0 input[id=file_description_0]").type(
"file description"
);
cy.get("#document_0 input[id=physical_location_0]").type(
"file physical location"
);
cy.get("#document_0 input[id=uri_0]").type("file URI");
cy.get("#document_0 input[id=notes_0]").type("file notes");
// Submit the form, get 500
cy.intercept("POST", "/api/v1/erm/licenses", {
@ -133,9 +151,7 @@ describe("License CRUD operations", () => {
body: license,
});
cy.get("#licenses_add").contains("Submit").click();
cy.get("main div[class='dialog message']").contains(
"License created"
);
cy.get("main div[class='dialog message']").contains("License created");
});
it("Edit license", () => {
@ -154,9 +170,7 @@ describe("License CRUD operations", () => {
"get-license"
);
cy.visit("/cgi-bin/koha/erm/licenses");
cy.get("#licenses_list table tbody tr:first")
.contains("Edit")
.click();
cy.get("#licenses_list table tbody tr:first").contains("Edit").click();
cy.wait("@get-license");
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
cy.get("#licenses_add h2").contains("Edit license");
@ -173,7 +187,7 @@ describe("License CRUD operations", () => {
cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]);
// Test related document
cy.get("#document_0 .file_information span").contains("file.json" );
cy.get("#document_0 .file_information span").contains("file.json");
// Submit the form, get 500
cy.intercept("PUT", "/api/v1/erm/licenses/*", {
@ -191,9 +205,7 @@ describe("License CRUD operations", () => {
body: license,
});
cy.get("#licenses_add").contains("Submit").click();
cy.get("main div[class='dialog message']").contains(
"License updated"
);
cy.get("main div[class='dialog message']").contains("License updated");
});
it("Show license", () => {
@ -222,9 +234,7 @@ describe("License CRUD operations", () => {
name_link.click();
cy.wait("@get-license");
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
cy.get("#licenses_show h2").contains(
"License #" + license.license_id
);
cy.get("#licenses_show h2").contains("License #" + license.license_id);
});
it("Delete license", () => {
@ -269,7 +279,9 @@ describe("License CRUD operations", () => {
.click();
cy.get(".dialog.alert.confirmation h1").contains("remove this license");
cy.contains("Yes, delete").click();
cy.get("main div[class='dialog message']").contains("License").contains("deleted");
cy.get("main div[class='dialog message']")
.contains("License")
.contains("deleted");
// Delete from show
// Click the "name" link from the list
@ -295,15 +307,13 @@ describe("License CRUD operations", () => {
name_link.click();
cy.wait("@get-license");
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
cy.get("#licenses_show h2").contains(
"License #" + license.license_id
);
cy.get("#licenses_show h2").contains("License #" + license.license_id);
cy.get('#licenses_show .action_links .fa-trash').click();
cy.get("#licenses_show .action_links .fa-trash").click();
cy.get(".dialog.alert.confirmation h1").contains("remove this license");
cy.contains("Yes, delete").click();
//Make sure we return to list after deleting from show
cy.get("#licenses_list table tbody tr:first")
cy.get("#licenses_list table tbody tr:first");
});
});

View File

@ -13,11 +13,11 @@ function get_package() {
agreement: {
agreement_id: 2,
description: "agreement description",
name: "agreement name"
name: "agreement name",
},
agreement_id: 2,
package_id: 1
}
package_id: 1,
},
],
resources_count: 0,
};
@ -27,8 +27,16 @@ describe("Package CRUD operations", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("List package", () => {
@ -77,7 +85,6 @@ describe("Package CRUD operations", () => {
});
it("Add package", () => {
cy.intercept("GET", "/api/v1/erm/agreements*", []);
// Click the button in the toolbar
@ -137,7 +144,9 @@ describe("Package CRUD operations", () => {
cy.get("#agreement_id_0 .vs__search").type(
related_agreement.agreement.name
);
cy.get("#agreement_id_0 .vs__dropdown-menu li").eq(0).click( { force: true } ); //click first agreement suggestion
cy.get("#agreement_id_0 .vs__dropdown-menu li")
.eq(0)
.click({ force: true }); //click first agreement suggestion
});
it("Edit package", () => {
@ -174,7 +183,9 @@ describe("Package CRUD operations", () => {
cy.get("#package_content_type .vs__selected").contains("Print");
//Test related content
cy.get("#package_agreement_0 #agreement_id_0 .vs__selected").contains("second agreement name");
cy.get("#package_agreement_0 #agreement_id_0 .vs__selected").contains(
"second agreement name"
);
// Submit the form, get 500
cy.intercept("PUT", "/api/v1/erm/eholdings/local/packages/*", {
@ -311,7 +322,9 @@ describe("Package CRUD operations", () => {
.click();
cy.get(".dialog.alert.confirmation h1").contains("remove this package");
cy.contains("Yes, delete").click();
cy.get("main div[class='dialog message']").contains("Local package").contains("deleted");
cy.get("main div[class='dialog message']")
.contains("Local package")
.contains("deleted");
// Delete from show
// Click the "name" link from the list
@ -343,11 +356,11 @@ describe("Package CRUD operations", () => {
"Package #" + erm_package.package_id
);
cy.get('#packages_show .action_links .fa-trash').click();
cy.get("#packages_show .action_links .fa-trash").click();
cy.get(".dialog.alert.confirmation h1").contains("remove this package");
cy.contains("Yes, delete").click();
//Make sure we return to list after deleting from show
cy.get("#packages_list table tbody tr:first")
cy.get("#packages_list table tbody tr:first");
});
});

View File

@ -1,34 +1,41 @@
import { mount } from "@cypress/vue";
describe("Searchbar header changes", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("Default option is agreements", () => {
cy.visit("/cgi-bin/koha/erm/erm.pl");
cy.get("#agreement_search_tab").parent().should("have.class", "active")
cy.get("#agreement_search_tab").parent().should("have.class", "active");
cy.visit("/cgi-bin/koha/erm/agreements");
cy.get("#agreement_search_tab").parent().should("have.class", "active")
})
cy.get("#agreement_search_tab").parent().should("have.class", "active");
});
it("Should change to licenses when in licenses", () => {
cy.visit("/cgi-bin/koha/erm/licenses");
cy.get("#license_search_tab").parent().should("have.class", "active")
})
});
it("Should change to packages when in local packages", () => {
cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
cy.get("#package_search_tab").parent().should("have.class", "active")
})
cy.get("#package_search_tab").parent().should("have.class", "active");
});
it("Should change to titles when in local titles", () => {
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
cy.get("#title_search_tab").parent().should("have.class", "active")
})
})
cy.get("#title_search_tab").parent().should("have.class", "active");
});
});

View File

@ -7,22 +7,30 @@ function get_packages_to_relate() {
{
package_id: 1,
description: "a package",
name: "first package name"
name: "first package name",
},
{
package_id: 2,
description: "a second package",
name: "second package name"
}
]
name: "second package name",
},
];
}
describe("Title CRUD operations", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule", '{"value":"1"}');
cy.intercept("GET", "/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders", '{"value":"local"}');
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMModule",
'{"value":"1"}'
);
cy.intercept(
"GET",
"/cgi-bin/koha/svc/config/systempreferences/?pref=ERMProviders",
'{"value":"local"}'
);
});
it("Import titles", () => {
@ -32,19 +40,19 @@ describe("Title CRUD operations", () => {
// Create a list in case none exists
cy.visit("/cgi-bin/koha/virtualshelves/shelves.pl");
cy.contains("New list").click();
cy.get("#shelfname").type('list name');
cy.get("#shelfname").type("list name");
cy.contains("Save").click();
// First attempt to import list has no packages
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
statusCode: 200,
body: []
body: [],
}).as("get-empty-packages");
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
cy.wait(500);
cy.get("#toolbar a").contains("Import from list").click();
cy.get("h2").contains("Import from a list");
cy.get("#package_list .vs__selected").should('not.exist');
cy.get("#package_list .vs__selected").should("not.exist");
// Make sure packages are returned
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
@ -59,10 +67,12 @@ describe("Title CRUD operations", () => {
// Prepare background job response to the POST
cy.intercept("POST", "/api/v1/erm/eholdings/local/titles/import", {
statusCode: 200,
body: {job_id: 1},
body: { job_id: 1 },
}).as("get-job-response");
cy.get("#list_list tbody tr:first td a").contains("Import").click();
cy.get("main div[class='dialog message']").contains("Import in progress, see job #1");
cy.get("main div[class='dialog message']").contains(
"Import in progress, see job #1"
);
});
it("List title", () => {
@ -106,15 +116,16 @@ describe("Title CRUD operations", () => {
});
it("Add title", () => {
cy.intercept({
method: "GET",
url: "/api/v1/erm/eholdings/local/packages*",
times: 1
},
{
body: [],
});
cy.intercept(
{
method: "GET",
url: "/api/v1/erm/eholdings/local/packages*",
times: 1,
},
{
body: [],
}
);
// Click the button in the toolbar
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
@ -133,12 +144,24 @@ describe("Title CRUD operations", () => {
cy.get("#title_publication_title").type(erm_title.publication_title);
cy.get("#title_print_identifier").type(erm_title.print_identifier);
cy.get("#title_online_identifier").type(erm_title.online_identifier);
cy.get("#title_date_first_issue_online").type(erm_title.date_first_issue_online);
cy.get("#title_num_first_vol_online").type(erm_title.num_first_vol_online);
cy.get("#title_num_first_issue_online").type(erm_title.num_first_issue_online);
cy.get("#title_date_last_issue_online").type(erm_title.date_last_issue_online);
cy.get("#title_num_last_vol_online").type(erm_title.num_last_vol_online);
cy.get("#title_num_last_issue_online").type(erm_title.num_last_issue_online);
cy.get("#title_date_first_issue_online").type(
erm_title.date_first_issue_online
);
cy.get("#title_num_first_vol_online").type(
erm_title.num_first_vol_online
);
cy.get("#title_num_first_issue_online").type(
erm_title.num_first_issue_online
);
cy.get("#title_date_last_issue_online").type(
erm_title.date_last_issue_online
);
cy.get("#title_num_last_vol_online").type(
erm_title.num_last_vol_online
);
cy.get("#title_num_last_issue_online").type(
erm_title.num_last_issue_online
);
cy.get("#title_title_url").type(erm_title.title_url);
cy.get("#title_first_author").type(erm_title.first_author);
cy.get("#title_embargo_info").type(erm_title.embargo_info);
@ -149,18 +172,24 @@ describe("Title CRUD operations", () => {
erm_title.publication_type + "{enter}",
{ force: true }
);
cy.get("#title_date_monograph_published_print").type(erm_title.date_monograph_published_print);
cy.get("#title_date_monograph_published_online").type(erm_title.date_monograph_published_online);
cy.get("#title_date_monograph_published_print").type(
erm_title.date_monograph_published_print
);
cy.get("#title_date_monograph_published_online").type(
erm_title.date_monograph_published_online
);
cy.get("#title_monograph_volume").type(erm_title.monograph_volume);
cy.get("#title_monograph_edition").type(erm_title.monograph_edition);
cy.get("#title_first_editor").type(erm_title.first_editor);
cy.get("#title_parent_publication_title_id").type(erm_title.parent_publication_title_id);
cy.get("#title_preceeding_publication_title_id").type(erm_title.preceeding_publication_title_id);
cy.get("#title_parent_publication_title_id").type(
erm_title.parent_publication_title_id
);
cy.get("#title_preceeding_publication_title_id").type(
erm_title.preceeding_publication_title_id
);
cy.get("#title_access_type").type(erm_title.access_type);
cy.get("#resources").contains(
"There are no packages created yet"
);
cy.get("#resources").contains("There are no packages created yet");
// Submit the form, get 500
cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", {
@ -185,14 +214,16 @@ describe("Title CRUD operations", () => {
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
statusCode: 200,
body: get_packages_to_relate(),
}).as('get-related-packages');
}).as("get-related-packages");
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/add");
cy.get("#resources").contains("Add to another package").click();
cy.get("#resources").contains("Package 1");
cy.get("#resources #resource_package_id_0 .vs__search").type(
related_package.package.name
);
cy.get("#resources #resource_package_id_0 .vs__dropdown-menu li").eq(0).click( { force: true } ); //click first package suggestion
cy.get("#resources #resource_package_id_0 .vs__dropdown-menu li")
.eq(0)
.click({ force: true }); //click first package suggestion
});
it("Edit title", () => {
@ -217,7 +248,7 @@ describe("Title CRUD operations", () => {
cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
statusCode: 200,
body: get_packages_to_relate(),
}).as('get-related-packages');
}).as("get-related-packages");
cy.get("#titles_list table tbody tr:first").contains("Edit").click();
cy.wait("@get-title");
@ -225,33 +256,98 @@ describe("Title CRUD operations", () => {
cy.get("#titles_add h2").contains("Edit title");
// Form has been correctly filled in
cy.get("#title_publication_title").should("have.value", erm_title.publication_title);
cy.get("#title_print_identifier").should("have.value", erm_title.print_identifier);
cy.get("#title_online_identifier").should("have.value", erm_title.online_identifier);
cy.get("#title_date_first_issue_online").should("have.value", erm_title.date_first_issue_online);
cy.get("#title_num_first_vol_online").should("have.value", erm_title.num_first_vol_online);
cy.get("#title_num_first_issue_online").should("have.value", erm_title.num_first_issue_online);
cy.get("#title_date_last_issue_online").should("have.value", erm_title.date_last_issue_online);
cy.get("#title_num_last_vol_online").should("have.value", erm_title.num_last_vol_online);
cy.get("#title_num_last_issue_online").should("have.value", erm_title.num_last_issue_online);
cy.get("#title_publication_title").should(
"have.value",
erm_title.publication_title
);
cy.get("#title_print_identifier").should(
"have.value",
erm_title.print_identifier
);
cy.get("#title_online_identifier").should(
"have.value",
erm_title.online_identifier
);
cy.get("#title_date_first_issue_online").should(
"have.value",
erm_title.date_first_issue_online
);
cy.get("#title_num_first_vol_online").should(
"have.value",
erm_title.num_first_vol_online
);
cy.get("#title_num_first_issue_online").should(
"have.value",
erm_title.num_first_issue_online
);
cy.get("#title_date_last_issue_online").should(
"have.value",
erm_title.date_last_issue_online
);
cy.get("#title_num_last_vol_online").should(
"have.value",
erm_title.num_last_vol_online
);
cy.get("#title_num_last_issue_online").should(
"have.value",
erm_title.num_last_issue_online
);
cy.get("#title_title_url").should("have.value", erm_title.title_url);
cy.get("#title_first_author").should("have.value", erm_title.first_author);
cy.get("#title_embargo_info").should("have.value", erm_title.embargo_info);
cy.get("#title_coverage_depth").should("have.value", erm_title.coverage_depth);
cy.get("#title_first_author").should(
"have.value",
erm_title.first_author
);
cy.get("#title_embargo_info").should(
"have.value",
erm_title.embargo_info
);
cy.get("#title_coverage_depth").should(
"have.value",
erm_title.coverage_depth
);
cy.get("#title_notes").should("have.value", erm_title.notes);
cy.get("#title_publisher_name").should("have.value", erm_title.publisher_name);
cy.get("#title_publication_type .vs__selected").contains('Journal');
cy.get("#title_date_monograph_published_print").should("have.value", erm_title.date_monograph_published_print);
cy.get("#title_date_monograph_published_online").should("have.value", erm_title.date_monograph_published_online);
cy.get("#title_monograph_volume").should("have.value", erm_title.monograph_volume);
cy.get("#title_monograph_edition").should("have.value", erm_title.monograph_edition);
cy.get("#title_first_editor").should("have.value", erm_title.first_editor);
cy.get("#title_parent_publication_title_id").should("have.value", erm_title.parent_publication_title_id);
cy.get("#title_preceeding_publication_title_id").should("have.value", erm_title.preceeding_publication_title_id);
cy.get("#title_access_type").should("have.value", erm_title.access_type);
cy.get("#title_publisher_name").should(
"have.value",
erm_title.publisher_name
);
cy.get("#title_publication_type .vs__selected").contains("Journal");
cy.get("#title_date_monograph_published_print").should(
"have.value",
erm_title.date_monograph_published_print
);
cy.get("#title_date_monograph_published_online").should(
"have.value",
erm_title.date_monograph_published_online
);
cy.get("#title_monograph_volume").should(
"have.value",
erm_title.monograph_volume
);
cy.get("#title_monograph_edition").should(
"have.value",
erm_title.monograph_edition
);
cy.get("#title_first_editor").should(
"have.value",
erm_title.first_editor
);
cy.get("#title_parent_publication_title_id").should(
"have.value",
erm_title.parent_publication_title_id
);
cy.get("#title_preceeding_publication_title_id").should(
"have.value",
erm_title.preceeding_publication_title_id
);
cy.get("#title_access_type").should(
"have.value",
erm_title.access_type
);
//Test related content
cy.get("#resources #resource_package_id_0 .vs__selected").contains("package name");
cy.get("#resources #resource_package_id_0 .vs__selected").contains(
"package name"
);
// Submit the form, get 500
cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", {
@ -289,27 +385,23 @@ describe("Title CRUD operations", () => {
{
method: "GET",
url: "/api/v1/erm/eholdings/local/titles/*",
times: 1
times: 1,
},
{
body: {
publication_title: "publication title",
resources: [],
title_id: 1,
}
},
}
).as("get-title");
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
let title_link = cy.get(
"#titles_list table tbody tr:first td:first a"
);
let title_link = cy.get("#titles_list table tbody tr:first td:first a");
title_link.should(
"have.text",
erm_title.publication_title + " (#" + erm_title.title_id + ")"
);
cy.get(
"#titles_list table tbody tr:first td:first a"
).click();
cy.get("#titles_list table tbody tr:first td:first a").click();
cy.wait("@get-title");
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
cy.get("#eholdings_title_show h2").contains(
@ -336,11 +428,12 @@ describe("Title CRUD operations", () => {
// cy.get("#package_list tbody tr:first td a").contains("first package name").click();
cy.intercept(
"GET",
"/api/v1/erm/eholdings/local/resources/"+related_package.resource_id,
"/api/v1/erm/eholdings/local/resources/" +
related_package.resource_id,
related_package
).as("get-related-package");
cy.get("table#package_list").contains("first package name").click();
cy.contains("Resource #"+related_package.resource_id);
cy.contains("Resource #" + related_package.resource_id);
cy.contains(related_package.package.name);
});
@ -357,16 +450,10 @@ describe("Title CRUD operations", () => {
"X-Total-Count": "1",
},
});
cy.intercept(
"GET",
"/api/v1/erm/eholdings/local/titles/*",
erm_title
);
cy.intercept("GET", "/api/v1/erm/eholdings/local/titles/*", erm_title);
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
cy.get("#titles_list table tbody tr:first")
.contains("Delete")
.click();
cy.get("#titles_list table tbody tr:first").contains("Delete").click();
cy.get(".dialog.alert.confirmation h1").contains("remove this title");
cy.contains(erm_title.publication_title);
@ -385,12 +472,12 @@ describe("Title CRUD operations", () => {
statusCode: 204,
body: null,
});
cy.get("#titles_list table tbody tr:first")
.contains("Delete")
.click();
cy.get("#titles_list table tbody tr:first").contains("Delete").click();
cy.get(".dialog.alert.confirmation h1").contains("remove this title");
cy.contains("Yes, delete").click();
cy.get("main div[class='dialog message']").contains("Local title").contains("deleted");
cy.get("main div[class='dialog message']")
.contains("Local title")
.contains("deleted");
// Delete from show
// Click the "name" link from the list
@ -407,38 +494,34 @@ describe("Title CRUD operations", () => {
{
method: "GET",
url: "/api/v1/erm/eholdings/local/titles/*",
times: 1
times: 1,
},
{
body: {
publication_title: "publication title",
resources: [],
title_id: 1,
}
},
}
).as("get-title");
cy.visit("/cgi-bin/koha/erm/eholdings/local/titles");
let title_link = cy.get(
"#titles_list table tbody tr:first td:first a"
);
let title_link = cy.get("#titles_list table tbody tr:first td:first a");
title_link.should(
"have.text",
erm_title.publication_title + " (#" + erm_title.title_id + ")"
);
cy.get(
"#titles_list table tbody tr:first td:first a"
).click();
cy.get("#titles_list table tbody tr:first td:first a").click();
cy.wait("@get-title");
cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
cy.get("#eholdings_title_show h2").contains(
"Title #" + erm_title.title_id
);
cy.get('#eholdings_title_show .action_links .fa-trash').click();
cy.get("#eholdings_title_show .action_links .fa-trash").click();
cy.get(".dialog.alert.confirmation h1").contains("remove this title");
cy.contains("Yes, delete").click();
//Make sure we return to list after deleting from show
cy.get("#titles_list table tbody tr:first")
cy.get("#titles_list table tbody tr:first");
});
});