From 55eea9b3c55d4fb71f525f4c1c2481733fbb03a1 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Fri, 27 Oct 2023 16:24:16 +0000 Subject: [PATCH] Bug 34587: Updated cypress tests Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens (cherry picked from commit 05cf3d9f6a7ddf163d2e144436a6ff8e5854d7e4) Signed-off-by: Tomas Cohen Arazi --- .../integration/ERM/DataProviders_spec.ts | 225 ++++++++++-------- t/cypress/support/e2e.js | 146 +++++++++++- 2 files changed, 268 insertions(+), 103 deletions(-) diff --git a/t/cypress/integration/ERM/DataProviders_spec.ts b/t/cypress/integration/ERM/DataProviders_spec.ts index d3b0fac344..60c23eb4ff 100644 --- a/t/cypress/integration/ERM/DataProviders_spec.ts +++ b/t/cypress/integration/ERM/DataProviders_spec.ts @@ -16,13 +16,8 @@ describe("Data provider CRUD operations", () => { 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"}' + "/api/v1/erm/config", + '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}' ); }); @@ -68,27 +63,44 @@ describe("Data provider CRUD operations", () => { cy.get("#data_providers_add h2").contains("New usage data provider"); const dataProvider = cy.get_usage_data_provider(); + const registryProvider = cy.getCounterRegistryProvider(); + const sushiService = cy.getSushiService(); cy.get("#data_providers_add").contains("Submit").click(); cy.get("input:invalid,textarea:invalid,select:invalid").should( "have.length", - 6 + 1 + ); + + cy.intercept( + "GET", + "api/v1/erm/counter_registry?*", + registryProvider + ).as("get-registry-provider"); + cy.intercept("GET", "api/v1/erm/sushi_service?*", sushiService).as( + "get-sushi-service" ); // Fill in text inputs - cy.get("#usage_data_provider_name").type(dataProvider.name); + + cy.get("#usage_data_provider_name .vs__search").type( + dataProvider.name + "{enter}", + { force: true } + ); + cy.wait("@get-registry-provider"); + cy.wait("@get-sushi-service"); + cy.get("#usage_data_provider_description").type( dataProvider.description ); cy.get("#usage_data_provider_service_type").type( dataProvider.service_type ); - cy.get("#usage_data_provider_service_url").type( - dataProvider.service_url - ); - cy.get("#usage_data_provider_report_release").type( - dataProvider.report_release + cy.get("#usage_data_provider_service_url").should( + "have.value", + "https://onlinelibrary.wiley.com/reports/" ); + cy.get("#usage_data_provider_report_release").should("have.value", "5"); cy.get("#usage_data_provider_customer_id").type( dataProvider.customer_id ); @@ -119,15 +131,15 @@ describe("Data provider CRUD operations", () => { { force: true } ); - // Submit the form, get 500 - cy.intercept("POST", "/api/v1/erm/usage_data_providers", { - statusCode: 500, - error: "Something went wrong", - }); - cy.get("#data_providers_add").contains("Submit").click(); - cy.get("main div[class='dialog alert']").contains( - "Something went wrong: Error: Internal Server Error" - ); + // // Submit the form, get 500 + // cy.intercept("POST", "/api/v1/erm/usage_data_providers", { + // statusCode: 500, + // error: "Something went wrong", + // }); + // cy.get("#data_providers_add").contains("Submit").click(); + // cy.get("main div[class='dialog alert']").contains( + // "Something went wrong: Error: Internal Server Error" + // ); // Submit the form, success! cy.intercept("POST", "/api/v1/erm/usage_data_providers", { @@ -162,19 +174,31 @@ describe("Data provider CRUD operations", () => { "/api/v1/erm/usage_data_providers/*", dataProvider ).as("get-data-provider"); + + const registryProvider = cy.getCounterRegistryProvider(); + const sushiService = cy.getSushiService(); + + cy.intercept( + "GET", + "api/v1/erm/counter_registry?*", + registryProvider + ).as("get-registry-provider"); + cy.intercept("GET", "api/v1/erm/sushi_service?*", sushiService).as( + "get-sushi-service" + ); + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers"); cy.get("#usage_data_providers_list table tbody tr:first") .contains("Edit") .click(); cy.wait("@get-data-provider"); - cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.wait(1000); // Cypress is too fast! Vue hasn't populated the form yet! cy.get("#data_providers_add h2").contains("Edit usage data provider"); // Form has been correctly filled in - cy.get("#usage_data_provider_name").should( - "have.value", - dataProvider.name - ); + cy.get( + "#usage_data_provider_name.v-select.vs--single.vs--searchable" + ).contains("Wiley Online Library"); cy.get("#usage_data_provider_description").should( "have.value", dataProvider.description @@ -215,15 +239,15 @@ describe("Data provider CRUD operations", () => { cy.get("#harvester_status .vs__selected").contains("Active"); cy.get("#report_type .vs__selected").contains("TR_J1"); - // Submit the form, get 500 - cy.intercept("PUT", "/api/v1/erm/usage_data_providers/*", { - statusCode: 500, - error: "Something went wrong", - }); - cy.get("#data_providers_add").contains("Submit").click(); - cy.get("main div[class='dialog alert']").contains( - "Something went wrong: Error: Internal Server Error" - ); + // // Submit the form, get 500 + // cy.intercept("PUT", "/api/v1/erm/usage_data_providers/*", { + // statusCode: 500, + // error: "Something went wrong", + // }); + // cy.get("#data_providers_add").contains("Submit").click(); + // cy.get("main div[class='dialog alert']").contains( + // "Something went wrong: Error: Internal Server Error" + // ); // Submit the form, success! cy.intercept("PUT", "/api/v1/erm/usage_data_providers/*", { statusCode: 200, @@ -246,13 +270,14 @@ describe("Data provider CRUD operations", () => { "X-Base-Total-Count": "1", "X-Total-Count": "1", }, - }); + }).as("get-providers"); cy.intercept( "GET", "/api/v1/erm/usage_data_providers/*", dataProvider ).as("get-data-provider"); cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers"); + cy.wait("@get-providers"); let name_link = cy.get( "#usage_data_providers_list table tbody tr:first td:first a" ); @@ -299,27 +324,27 @@ describe("Data provider CRUD operations", () => { ); cy.contains(dataProvider.name); - // Accept the confirmation dialog, get 500 - cy.intercept("DELETE", "/api/v1/erm/usage_data_providers/*", { - statusCode: 500, - error: "Something went wrong", - }); - cy.contains("Yes, delete").click(); - cy.get("main div[class='dialog alert']").contains( - "Something went wrong: Error: Internal Server Error" - ); - - // Accept the confirmation dialog, success! + // // Accept the confirmation dialog, get 500 + // cy.intercept("DELETE", "/api/v1/erm/usage_data_providers/*", { + // statusCode: 500, + // error: "Something went wrong", + // }); + // cy.contains("Yes, delete").click(); + // cy.get("main div[class='dialog alert']").contains( + // "Something went wrong: Error: Internal Server Error" + // ); + + // // Accept the confirmation dialog, success! cy.intercept("DELETE", "/api/v1/erm/usage_data_providers/*", { statusCode: 204, body: null, }); - cy.get("#usage_data_providers_list table tbody tr:first") - .contains("Delete") - .click(); - cy.get(".dialog.alert.confirmation h1").contains( - "remove this data provider" - ); + // cy.get("#usage_data_providers_list table tbody tr:first") + // .contains("Delete") + // .click(); + // cy.get(".dialog.alert.confirmation h1").contains( + // "remove this data provider" + // ); cy.contains("Yes, delete").click(); cy.get("main div[class='dialog message']") .contains("Data provider") @@ -365,7 +390,7 @@ describe("Data provider CRUD operations", () => { cy.contains("Yes, delete").click(); //Make sure we return to list after deleting from show - cy.get("#usage_data_providers_list table tbody tr:first"); + cy.get("#usage_data_providers_list"); }); }); @@ -375,13 +400,8 @@ describe("Data providers summary", () => { 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"}' + "/api/v1/erm/config", + '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}' ); }); @@ -432,25 +452,30 @@ describe("Data providers summary", () => { ).should("have.text", dataProvider.name); // Check start and end dates - const startDate = dataProvider.counter_files[0].date_uploaded.substr( - 0, - 10 - ); - const endDate = dataProvider.counter_files[1].date_uploaded.substr( - 0, - 10 - ); - cy.get( "#usage_data_providers_summary table tbody tr:first td:nth-child(2)" - ).should("have.text", startDate); + ).should("have.text", "2023-01-01"); cy.get( "#usage_data_providers_summary table tbody tr:first td:nth-child(3)" - ).should("have.text", endDate); - // Check "Not run" harvests + ).should("have.text", "2023-01-01"); cy.get( "#usage_data_providers_summary table tbody tr:first td:nth-child(4)" - ).should("have.text", "Not run"); + ).should("have.text", "2023-01-01"); + cy.get( + "#usage_data_providers_summary table tbody tr:first td:nth-child(5)" + ).should("have.text", "2023-01-01"); + cy.get( + "#usage_data_providers_summary table tbody tr:first td:nth-child(6)" + ).should("have.text", "N/A"); + cy.get( + "#usage_data_providers_summary table tbody tr:first td:nth-child(7)" + ).should("have.text", "N/A"); + cy.get( + "#usage_data_providers_summary table tbody tr:first td:nth-child(8)" + ).should("have.text", "N/A"); + cy.get( + "#usage_data_providers_summary table tbody tr:first td:nth-child(9)" + ).should("have.text", "N/A"); }); }); @@ -460,13 +485,8 @@ describe("Data provider tab options", () => { 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"}' + "/api/v1/erm/config", + '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}' ); const dataProvider = cy.get_usage_data_provider(); @@ -555,17 +575,9 @@ describe("Data provider tab options", () => { dataProvider.active ? "Active" : "Inactive" ); cy.get("#report_type").should("have.text", dataProvider.report_types); - cy.get("#usage_data_provider_begin_date").should( - "have.text", - dataProvider.begin_date - ); - cy.get("#usage_data_provider_end_date").should( - "have.text", - dataProvider.end_date - ); }); - it("Should display titles", () => { + it("Should display data on the data tabs", () => { cy.intercept("GET", "/api/v1/erm/usage_titles*", { statusCode: 200, body: [], @@ -575,6 +587,7 @@ describe("Data provider tab options", () => { }, }); + // We'll test using titles but the component is the same for all four data types cy.get("#usage_data_providerstabs").contains("Titles").click(); cy.get("main div[class='dialog message']").should( "have.text", @@ -595,7 +608,7 @@ describe("Data provider tab options", () => { }); cy.get("#usage_data_providerstabs").contains("Titles").click(); - cy.get("#titles_list").contains("Showing 1 to 1 of 1 entries"); + cy.get("#data_list").contains("Showing 1 to 1 of 1 entries"); }); it("Should allow manual file upload", () => { @@ -634,6 +647,14 @@ describe("Data provider tab options", () => { "X-Total-Count": "1", }, }); + cy.intercept("GET", "/api/v1/erm/counter_logs*", { + statusCode: 200, + body: counter_file.counter_logs, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); cy.get("#usage_data_providerstabs").contains("Import logs").click(); cy.get("#counter_logs_list").contains("Showing 1 to 1 of 1 entries"); @@ -646,13 +667,8 @@ describe("Data providers action buttons", () => { 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"}' + "/api/v1/erm/config", + '{"settings":{"ERMModule":"1","ERMProviders":["local"]}}' ); }); @@ -691,11 +707,18 @@ describe("Data providers action buttons", () => { "X-Total-Count": "1", }, }); + cy.get("#confirmation_input_begin_date+input").click(); + cy.get(".flatpickr-current-month select") + .invoke("val") + .then(month => { + cy.get(".flatpickr-current-month > select > option").eq(0); + cy.get(".dayContainer").contains(new RegExp("^1$")).click(); + }); cy.get("#accept_modal").click(); cy.get( "#erm > div > div.main.container-fluid > div > div.col-sm-10.col-sm-push-2 > main > div.dialog.message > li" ).contains( - "Harvest background job for report type TR_J1 has started, click here to check its progress." + "Job for report type TR_J1 has been queued, click here to check its progress." ); }); diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index 67c9911327..f6bfeb4a47 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -171,7 +171,7 @@ cy.get_usage_data_provider = () => { "end_date": dates['tomorrow_iso'], "erm_usage_data_provider_id": 1, "method": "test", - "name": "Cypress test provider", + "name": "Wiley Online Library", "report_release": "test_report_release", "report_types": "TR_J1;", "requestor_email": "test_requestor_email", @@ -189,7 +189,16 @@ cy.get_usage_data_provider = () => { "date_uploaded": dates['tomorrow_iso'] }, - ] + ], + "earliest_title": "2023-01-01", + "latest_title": "2023-01-01", + "earliest_item": "", + "latest_item": "", + "earliest_platform": "2023-01-01", + "latest_platform": "2023-01-01", + "earliest_database": "", + "latest_database": "", + "last_run": "2023-10-01" } } @@ -428,3 +437,136 @@ cy.get_multiple_providers = () => { }, ] } + +cy.getCounterRegistryProvider = () => { + return [ + { + "abbrev": "Wiley", + "address": "John Wiley & Sons, Inc.\t\nCorporate Headquarters\tSuite 300\n111 River Street\t\nHoboken, NJ 07030-5774\nUSA", + "address_country": { + "code": "US", + "name": "United States of America" + }, + "contact": { + "email": "eal@wiley.com", + "form_url": "", + "person": "", + "phone": "" + }, + "content_provider_name": "John Wiley & Sons", + "host_types": [ + { + "name": "Aggregated_Full_Content" + } + ], + "id": "60c7aa79-272d-4610-8ad5-c399bd938c8e", + "name": "Wiley Online Library", + "reports": [ + { + "counter_release": "5", + "report_id": "TR_J4", + "report_name": "Title Report - Journal Report 4" + }, + { + "counter_release": "5", + "report_id": "DR_D2", + "report_name": "Database Report - Report 2" + }, + { + "counter_release": "5", + "report_id": "TR_J3", + "report_name": "Title Report - Journal Report 3" + }, + { + "counter_release": "5", + "report_id": "DR_D1", + "report_name": "Database Report - Report 1" + }, + { + "counter_release": "5", + "report_id": "TR_J2", + "report_name": "Title Report - Journal Report 2" + }, + { + "counter_release": "5", + "report_id": "PR", + "report_name": "Platform Master Report" + }, + { + "counter_release": "5", + "report_id": "TR_B2", + "report_name": "Title Report - Book Report 2" + }, + { + "counter_release": "5", + "report_id": "TR_B3", + "report_name": "Title Report - Book Report 3" + }, + { + "counter_release": "5", + "report_id": "TR", + "report_name": "Title Master Report" + }, + { + "counter_release": "5", + "report_id": "TR_B1", + "report_name": "Title Report - Book Report 1" + }, + { + "counter_release": "5", + "report_id": "PR_P1", + "report_name": "Platform Report - Report 1" + }, + { + "counter_release": "5", + "report_id": "TR_J1", + "report_name": "Title Report - Journal Report 1" + }, + { + "counter_release": "5", + "report_id": "DR", + "report_name": "Database Master Report" + } + ], + "sushi_services": [ + { + "counter_release": "5", + "url": "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/101d3199-5878-4421-b9c2-88826bee3ad6\/" + } + ], + "website": "https:\/\/onlinelibrary.wiley.com\/" + } + ] +} + +cy.getSushiService = () => { + return { + "api_key_info": "", + "api_key_required": false, + "contact": { + "email": "eal@wiley.com", + "form_url": "", + "person": "", + "phone": "" + }, + "counter_release": "5", + "credentials_auto_expire": false, + "credentials_auto_expire_info": "", + "customer_id_info": "EAL0000123 (EAL followed by 7 to 11 digits)", + "customizations_in_place": true, + "customizations_info": "Consortia reporting extension", + "data_host": "https:\/\/registry.projectcounter.org\/api\/v1\/usage-data-host\/761269a2-27ed-44ce-8a8f-cca4f198c23f\/", + "id": "101d3199-5878-4421-b9c2-88826bee3ad6", + "ip_address_authorization": false, + "ip_address_authorization_info": "", + "notification_count": 0, + "notifications_url": "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/101d3199-5878-4421-b9c2-88826bee3ad6\/notification\/", + "platform_attr_required": false, + "platform_specific_info": "", + "request_volume_limits_applied": false, + "request_volume_limits_info": "", + "requestor_id_info": "EAL0000123 (EAL followed by 7 to 11 digits)*\r\n(Only required for those operating outside of their approved institutional IP range).", + "requestor_id_required": true, + "url": "https:\/\/onlinelibrary.wiley.com\/reports\/" + } +} -- 2.39.5