From 4803c4ff44522043d1eebdd0beb2fd379ae2c8d9 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 28 Oct 2022 19:08:21 +0000 Subject: [PATCH] Bug 32030: Cypress tests Agreements: 'add' and 'edit' tests for related documents, agreements, licenses; Licenses: 'add' and 'edit' tests for related documents; Packages: 'add' and 'edit' tests for related agreements; Titles: Regular tests + titles import + resource Added file.json to fixtures - empty file to test file upload Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- cypress/fixtures/file.json | 0 cypress/integration/Agreements_spec.ts | 176 +++++++++- cypress/integration/Licenses_spec.ts | 25 +- cypress/integration/Packages_spec.ts | 33 +- cypress/integration/Titles_spec.ts | 436 +++++++++++++++++++++++++ cypress/support/index.js | 22 +- 6 files changed, 671 insertions(+), 21 deletions(-) create mode 100644 cypress/fixtures/file.json create mode 100644 cypress/integration/Titles_spec.ts diff --git a/cypress/fixtures/file.json b/cypress/fixtures/file.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cypress/integration/Agreements_spec.ts b/cypress/integration/Agreements_spec.ts index edfc5810be..7e394faa01 100644 --- a/cypress/integration/Agreements_spec.ts +++ b/cypress/integration/Agreements_spec.ts @@ -34,13 +34,88 @@ function get_agreement() { }, ], user_roles: [], - agreement_licenses: [], - agreement_relationships: [], + agreement_licenses: [ + { + agreement_id: 1, + agreement_license_id: 3, + license: { + description: "license description", + license_id: 1, + name: "license name", + status: "expired", + type: "alliance" + }, + license_id:1, + notes: "license notes", + physical_location: "cupboard", + status: "controlling", + uri: "license uri" + }, + { + agreement_id: 1, + agreement_license_id: 4, + license: { + description: "second license description", + license_id: 2, + name: "second license name", + status: "expired", + type: "alliance" + }, + license_id:2, + notes: "second license notes", + physical_location: "cupboard", + status: "future", + uri: "license uri" + } + ], + agreement_relationships: [ + { + agreement_id: 1, + notes: 'related agreement notes', + related_agreement: { + agreement_id: 2, + description: "agreement description", + name: "agreement name" + }, + related_agreement_id: 2, + relationship: "supersedes" + } + ], agreement_packages: [], - documents: [], + documents: [ + { + 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" + } + ], }; } +function get_licenses_to_relate() { + return [ + { + license_id: 1, + description: "a license", + name: "first license name" + }, + { + license_id: 2, + description: "a second license", + name: "second license name" + }, + { + license_id: 3, + description: "a third license", + name: "third license name" + }, + ] +} + describe("Agreement CRUD operations", () => { beforeEach(() => { cy.login("koha", "koha"); @@ -185,8 +260,15 @@ describe("Agreement CRUD operations", () => { "There are no other agreements created yet" ); - cy.get("#documents").contains("Add new document"); - // TODO Test document upload + // 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('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'); // Submit the form, get 500 cy.intercept("POST", "/api/v1/erm/agreements", { @@ -212,36 +294,96 @@ describe("Agreement CRUD operations", () => { statusCode: 200, body: [{ agreement_id: 1, description: "an existing agreement" }], }); + + // Add new license + let licenses_to_relate = get_licenses_to_relate(); + let related_license = agreement.agreement_licenses[0]; cy.intercept("GET", "/api/v1/erm/licenses", { statusCode: 200, - body: [{ license_id: 1, description: "a license" }], + body: licenses_to_relate, }); cy.visit("/cgi-bin/koha/erm/agreements/add"); - cy.get("#agreement_licenses").contains( - "Add new license" + cy.get("#agreement_licenses").contains("Add new license").click(); + cy.get("#agreement_license_0").contains("Agreement license 1"); + cy.get("#agreement_license_0 #license_id_0 .vs__search").type( + related_license.license.name ); - cy.get("#agreement_relationships").contains( - "Add new related agreement" + 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 } + ); + cy.get("#agreement_license_0 #license_location_0 .vs__search").type( + 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_uri_0").type(related_license.uri); + // Add new related agreement + let related_agreement = agreement.agreement_relationships[0]; + cy.intercept("GET", "/api/v1/erm/agreements", { + statusCode: 200, + 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("#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 } + ); }); it("Edit agreement", () => { + let licenses_to_relate = get_licenses_to_relate(); let agreement = get_agreement(); let agreements = [agreement]; - // Click the 'Edit' button from the list - cy.intercept("GET", "/api/v1/erm/agreements*", { + + // Intercept initial /agreements request once + cy.intercept( + { + method: "GET", + url: "/api/v1/erm/agreements", + times: 1 + }, + { + body: agreements + } + ); + + // Intercept follow-up 'search' request after entering /agreements + cy.intercept("GET", "/api/v1/erm/agreements?_page*", { statusCode: 200, body: agreements, headers: { "X-Base-Total-Count": "1", "X-Total-Count": "1", }, - }); + }).as("get-single-agreement-search-result"); + cy.visit("/cgi-bin/koha/erm/agreements"); + + // Intercept request after edit click cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as( "get-agreement" ); - cy.visit("/cgi-bin/koha/erm/agreements"); + // Intercept related licenses request after entering agreement edit + cy.intercept("GET", "/api/v1/erm/licenses", { + statusCode: 200, + body: licenses_to_relate, + }).as("get-related-licenses"); + // Intercept related agreements request after entering agreement edit + cy.intercept("GET", "/api/v1/erm/agreements", { + statusCode: 200, + body: cy.get_agreements_to_relate(), + }).as("get-related-agreements"); + + // Click the 'Edit' button from the list cy.get("#agreements_list table tbody tr:first") .contains("Edit") .click(); @@ -268,6 +410,12 @@ describe("Agreement CRUD operations", () => { .should("eq", dates["tomorrow_iso"]); 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"); + // Submit the form, get 500 cy.intercept("PUT", "/api/v1/erm/agreements/*", { statusCode: 500, diff --git a/cypress/integration/Licenses_spec.ts b/cypress/integration/Licenses_spec.ts index 893df6cb8d..4235359571 100644 --- a/cypress/integration/Licenses_spec.ts +++ b/cypress/integration/Licenses_spec.ts @@ -17,7 +17,17 @@ function get_license() { status: "active", started_on: dates["today_iso"], ended_on: dates["tomorrow_iso"], - documents: [], + documents: [ + { + 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" + } + ], }; } @@ -94,6 +104,16 @@ describe("License CRUD operations", () => { .next("span") .click(); + // 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('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'); + // Submit the form, get 500 cy.intercept("POST", "/api/v1/erm/licenses", { statusCode: 500, @@ -149,6 +169,9 @@ describe("License CRUD operations", () => { cy.get("#started_on").invoke("val").should("eq", dates["today_iso"]); cy.get("#ended_on").invoke("val").should("eq", dates["tomorrow_iso"]); + // Test related document + cy.get("#document_0 .file_information span").contains("file.json" ); + // Submit the form, get 500 cy.intercept("PUT", "/api/v1/erm/licenses/*", { statusCode: 500, diff --git a/cypress/integration/Packages_spec.ts b/cypress/integration/Packages_spec.ts index dd517a4dc1..718f411d08 100644 --- a/cypress/integration/Packages_spec.ts +++ b/cypress/integration/Packages_spec.ts @@ -8,7 +8,17 @@ function get_package() { name: "package 1", package_type: "complete", content_type: "Print", - package_agreements: [], + package_agreements: [ + { + agreement: { + agreement_id: 2, + description: "agreement description", + name: "agreement name" + }, + agreement_id: 2, + package_id: 1 + } + ], resources_count: 0, }; } @@ -87,7 +97,6 @@ describe("Package CRUD operations", () => { cy.get("#package_agreements").contains( "There are no agreements created yet" ); - // FIXME Test with agreements // Submit the form, get 500 cy.intercept("POST", "/api/v1/erm/eholdings/local/packages", { @@ -107,13 +116,19 @@ describe("Package CRUD operations", () => { cy.get("#packages_add").contains("Submit").click(); cy.get("main div[class='dialog message']").contains("Package created"); - // Link with an agreement + // Add new related agreement + let related_agreement = erm_package.package_agreements[0]; cy.intercept("GET", "/api/v1/erm/agreements", { statusCode: 200, - body: [{ package_id: 1, description: "an agreement" }], + body: cy.get_agreements_to_relate(), }); cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); - cy.get("#package_agreements").contains("Add new agreement"); + cy.get("#package_agreements").contains("Add new agreement").click(); + cy.get("#package_agreement_0").contains("Agreement 1"); + 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 }); it("Edit package", () => { @@ -134,6 +149,11 @@ describe("Package CRUD operations", () => { erm_package ).as("get-package"); cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); + // Intercept related agreements request after entering agreement edit + cy.intercept("GET", "/api/v1/erm/agreements", { + statusCode: 200, + body: cy.get_agreements_to_relate(), + }).as("get-related-agreements"); cy.get("#packages_list table tbody tr:first").contains("Edit").click(); cy.wait("@get-package"); cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! @@ -144,6 +164,9 @@ describe("Package CRUD operations", () => { cy.get("#package_type .vs__selected").contains("Complete"); 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"); + // Submit the form, get 500 cy.intercept("PUT", "/api/v1/erm/eholdings/local/packages/*", { statusCode: 500, diff --git a/cypress/integration/Titles_spec.ts b/cypress/integration/Titles_spec.ts new file mode 100644 index 0000000000..6e46b23a48 --- /dev/null +++ b/cypress/integration/Titles_spec.ts @@ -0,0 +1,436 @@ +import { mount } from "@cypress/vue"; +const dayjs = require("dayjs"); /* Cannot use our calendar JS code, it's in an include file (!) + Also note that moment.js is deprecated */ + +function get_title() { + return { + access_type: "access type", + biblio_id: null, + coverage_depth: "coverage depth", + date_first_issue_online: "date first", + date_last_issue_online: "date last", + date_monograph_published_online: "date mono online", + date_monograph_published_print: "date mono print", + embargo_info: "embargo info", + external_id: "", + first_author: "first author", + first_editor: "first editor", + monograph_edition: "monograph edition", + monograph_volume: "monograph volume", + notes: "notes", + num_first_issue_online: "num first issue", + num_first_vol_online: "num first vol", + num_last_issue_online: "num last issue", + num_last_vol_online: "num last vol", + online_identifier: "online identifier", + parent_publication_title_id: "parent id", + preceeding_publication_title_id: "preceeding id", + print_identifier: "print identifier", + publication_title: "publication title", + publication_type: "journal", + publisher_name: "publication name", + resources: [ + { + ended_on: null, + package: { + content_type: "", + package_id: 1, + name: "first package name" + }, + package_id: 1, + resource_id: 2, + title: { + biblio_id: 439, + title_id: 1, + }, + title_id: 1 + } + ], + title_id: 1, + title_url: "title url" + }; +} + +function get_packages_to_relate() { + return [ + { + package_id: 1, + description: "a package", + name: "first package name" + }, + { + package_id: 2, + description: "a second package", + name: "second package name" + } + ] +} + +describe("Title CRUD operations", () => { + beforeEach(() => { + cy.login("koha", "koha"); + cy.title().should("eq", "Koha staff interface"); + }); + + it("Import titles", () => { + let erm_title = get_title(); + let resource = erm_title.resources[0]; + + // 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.contains("Save").click(); + + // First attempt to import list has no packages + cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", { + statusCode: 200, + 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'); + + // Make sure packages are returned + cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", { + statusCode: 200, + body: get_packages_to_relate(), + }).as("get-related-packages"); + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles"); + cy.get("#toolbar a").contains("Import from list").click(); + cy.get("h2").contains("Import from a list"); + cy.wait(500); + + // Prepare background job response to the POST + cy.intercept("POST", "/api/v1/erm/eholdings/local/titles/import", { + statusCode: 200, + 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"); + }); + + it("List title", () => { + // GET title returns 500 + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles", { + statusCode: 500, + error: "Something went wrong", + }); + cy.visit("/cgi-bin/koha/erm/erm.pl"); + cy.get("#navmenulist").contains("Titles").click(); + cy.get("main div[class='dialog alert']").contains( + /Something went wrong/ + ); + + // GET titles returns empty list + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", []); + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles"); + cy.get("#titles_list").contains("There are no titles defined"); + + // GET titles returns something + let erm_title = get_title(); + let titles = [erm_title]; + + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept( + "GET", + "/api/v1/erm/eholdings/local/titles/*", + erm_title + ); + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles"); + cy.get("#titles_list").contains("Showing 1 to 1 of 1 entries"); + }); + + it("Add title", () => { + + 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"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.contains("New title").click(); + cy.get("#titles_add h2").contains("New title"); + + // Fill in the form for normal attributes + let erm_title = get_title(); + + cy.get("#titles_add").contains("Submit").click(); + cy.get("input:invalid,textarea:invalid,select:invalid").should( + "have.length", + 1 + ); + 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_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); + cy.get("#title_coverage_depth").type(erm_title.coverage_depth); + cy.get("#title_notes").type(erm_title.notes); + cy.get("#title_publisher_name").type(erm_title.publisher_name); + cy.get("#title_publication_type .vs__search").type( + 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_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_access_type").type(erm_title.access_type); + + cy.get("#resources").contains( + "There are no packages created yet" + ); + + // Submit the form, get 500 + cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", { + statusCode: 500, + error: "Something went wrong", + }); + cy.get("#titles_add").contains("Submit").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("POST", "/api/v1/erm/eholdings/local/titles", { + statusCode: 201, + body: erm_title, + }); + cy.get("#titles_add").contains("Submit").click(); + cy.get("main div[class='dialog message']").contains("Title created"); + + // Add new related package (resource) + let related_package = erm_title.resources[0]; + cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", { + statusCode: 200, + body: get_packages_to_relate(), + }).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 + }); + + it("Edit title", () => { + let erm_title = get_title(); + let titles = [erm_title]; + // Click the 'Edit' button from the list + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + cy.intercept( + "GET", + "/api/v1/erm/eholdings/local/titles/*", + erm_title + ).as("get-title"); + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles"); + // Intercept related packages request after entering title edit + cy.intercept("GET", "/api/v1/erm/eholdings/local/packages", { + statusCode: 200, + body: get_packages_to_relate(), + }).as('get-related-packages'); + + cy.get("#titles_list table tbody tr:first").contains("Edit").click(); + cy.wait("@get-title"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + 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_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_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); + + //Test related content + 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/*", { + statusCode: 500, + error: "Something went wrong", + }); + cy.get("#titles_add").contains("Submit").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("PUT", "/api/v1/erm/eholdings/local/titles/*", { + statusCode: 200, + body: erm_title, + }); + cy.get("#titles_add").contains("Submit").click(); + cy.get("main div[class='dialog message']").contains("Title updated"); + }); + + it("Show title", () => { + let erm_title = get_title(); + let titles = [erm_title]; + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + // Title with empty resources. + cy.intercept( + { + method: "GET", + url: "/api/v1/erm/eholdings/local/titles/*", + 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" + ); + 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.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 + ); + // There are no packages, the table should not be displayed + cy.contains("Packages (0)"); + cy.get("#table#package_list").should("not.exist"); + + // Test now with all values + cy.intercept( + "GET", + "/api/v1/erm/eholdings/local/titles/*", + erm_title + ).as("get-title"); + + // List packages + cy.visit("/cgi-bin/koha/erm/eholdings/local/titles/1"); + cy.contains("Packages (1)"); + cy.wait(500); + + // Visit resource + let related_package = erm_title.resources[0]; + // 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, + 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(related_package.package.name); + }); + + it("Delete title", () => { + let erm_title = get_title(); + let titles = [erm_title]; + + // Click the 'Delete' button from the list + cy.intercept("GET", "/api/v1/erm/eholdings/local/titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + 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("#eholdings_confirm_delete h2").contains("Delete title"); + cy.contains("Title: " + erm_title.publication_title); + + // Submit the form, get 500 + cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", { + statusCode: 500, + error: "Something went wrong", + }); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog alert']").contains( + "Something went wrong: Internal Server Error" + ); + + // Submit the form, success! + cy.intercept("DELETE", "/api/v1/erm/eholdings/local/titles/*", { + statusCode: 204, + body: null, + }); + cy.contains("Yes, delete").click(); + cy.get("main div[class='dialog message']").contains("Title deleted"); + }); +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index d68db96df2..fd5bfb64f4 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -14,7 +14,27 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import './commands' +import './commands'; // Alternatively you can use CommonJS syntax: // require('./commands') + +cy.get_agreements_to_relate = () => { + return [ + { + agreement_id: 2, + description: "a second agreement", + name: "second agreement name" + }, + { + agreement_id: 3, + description: "a third agreement", + name: "third agreement name" + }, + { + agreement_id: 4, + description: "a fourth agreement", + name: "fourth agreement name" + }, + ] +} \ No newline at end of file -- 2.39.5