From e46321b31e18dad2b4a44a3e9bc199778125a998 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 20 Jun 2023 10:15:38 +0000 Subject: [PATCH] Bug 34587: Add cypress tests for Data providers Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- .gitignore | 1 + .../UsageStatisticsDataProviderDetails.vue | 6 + .../ERM/UsageStatisticsDataProvidersShow.vue | 3 - .../UsageStatisticsDataProvidersSummary.vue | 9 +- .../integration/ERM/DataProviders_spec.ts | 529 ++++++++++++++++++ .../integration/ERM/UsageReports_spec.ts | 176 ++++++ t/cypress/support/e2e.js | 258 +++++++++ 7 files changed, 973 insertions(+), 9 deletions(-) create mode 100644 t/cypress/integration/ERM/DataProviders_spec.ts create mode 100644 t/cypress/integration/ERM/UsageReports_spec.ts diff --git a/.gitignore b/.gitignore index bced881ece..343534876e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ koha-tmpl/intranet-tmpl/prog/js/vue/dist/ how-to.pl koha-tmpl/intranet-tmpl/prog/en/modules/how-to.tt +installer/data/mysql/atomicupdate/demo_data.pl \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProviderDetails.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProviderDetails.vue index a4efc5f254..50ce56cbc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProviderDetails.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProviderDetails.vue @@ -101,3 +101,9 @@ export default { name: "UsageStatisticsDataProviderDetails", } + + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue index 6a73f83b49..603cef528b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersShow.vue @@ -230,7 +230,4 @@ export default { .active { cursor: pointer; } -.rows { - float: none; -} diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue index a8cf0e2f69..121cc68df1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue @@ -122,8 +122,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - const date = getEarliestDate(row, "TR") - return date + return row.begin_date }, }, { @@ -142,8 +141,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - const date = getEarliestDate(row, "PR") - return date + return row.begin_date }, }, { @@ -162,8 +160,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - const date = getEarliestDate(row, "DR") - return date + return row.begin_date }, }, { diff --git a/t/cypress/integration/ERM/DataProviders_spec.ts b/t/cypress/integration/ERM/DataProviders_spec.ts new file mode 100644 index 0000000000..498d84a89a --- /dev/null +++ b/t/cypress/integration/ERM/DataProviders_spec.ts @@ -0,0 +1,529 @@ +import { mount } from "@cypress/vue" +import { data } from "cypress/types/jquery" + +const dayjs = require("dayjs") + +const dates = { + today_iso: dayjs().format("YYYY-MM-DD"), + today_us: dayjs().format("MM/DD/YYYY"), + tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"), + tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"), +} + +describe("Data provider 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"}' + ) + }) + + it("Should list providers", () => { + // GET usage_data_providers returns 500 + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 500, + error: "Something went wrong", + }) + cy.visit("/cgi-bin/koha/erm/erm.pl") + cy.get("#navmenulist").contains("Data providers").click() + cy.get("main div[class='dialog alert']").contains( + /Something went wrong/ + ) + + // GET usage_data_providers returns empty list + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", []) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + cy.get("#usage_data_providers_list").contains("There are no usage data providers defined") + + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/usage_data_providers/*", dataProvider) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + cy.get("#usage_data_providers_list").contains("Showing 1 to 1 of 1 entries") + }) + + it("Should add provider", () => { + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + cy.contains("New data provider").click() + cy.get("#data_providers_add h2").contains("New usage data provider") + + const dataProvider = cy.get_usage_data_provider() + + cy.get("#data_providers_add").contains("Submit").click() + cy.get("input:invalid,textarea:invalid,select:invalid").should( + "have.length", + 6 + ) + + // Fill in text inputs + cy.get("#usage_data_provider_name").type(dataProvider.name) + 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_customer_id").type(dataProvider.customer_id) + cy.get("#usage_data_provider_requestor_id").type(dataProvider.requestor_id) + cy.get("#usage_data_provider_api_key").type(dataProvider.api_key) + cy.get("#usage_data_provider_requestor_name").type(dataProvider.requestor_name) + cy.get("#usage_data_provider_requestor_email").type(dataProvider.requestor_email) + + cy.get("#data_providers_add").contains("Submit").click() + cy.get("input:invalid,textarea:invalid,select:invalid").should( + "have.length", + 1 + ) + + // Fill in status and report types + cy.get("#harvester_status .vs__search").type( + dataProvider.active + "{enter}", + { force: true } + ) + cy.get("#report_type .vs__search").type( + dataProvider.report_types.slice(0, -1) + "{enter}", + { force: true } + ) + + // Fill in start and end dates + cy.get("#usage_data_provider_begin_date+input").click() + cy.get(".flatpickr-calendar") + .eq(1) + .find("span.today") + .click({ force: true }) + cy.get("#usage_data_provider_end_date+input").click() + cy.get(".flatpickr-calendar") + .eq(1) + .find("span.today") + .next("span") + .click({ 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, success! + cy.intercept("POST", "/api/v1/erm/usage_data_providers", { + statusCode: 201, + body: dataProvider, + }) + cy.get("#data_providers_add").contains("Submit").click() + cy.get("main div[class='dialog message']").contains( + "Data provider created" + ) + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: [dataProvider], + }) + }) + + it("Should edit provider", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + 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.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.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_description").should("have.value", dataProvider.description) + cy.get("#usage_data_provider_service_type").should("have.value", dataProvider.service_type) + cy.get("#usage_data_provider_service_url").should("have.value", dataProvider.service_url) + cy.get("#usage_data_provider_report_release").should("have.value", dataProvider.report_release) + cy.get("#usage_data_provider_customer_id").should("have.value", dataProvider.customer_id) + cy.get("#usage_data_provider_requestor_id").should("have.value", dataProvider.requestor_id) + cy.get("#usage_data_provider_api_key").should("have.value", dataProvider.api_key) + cy.get("#usage_data_provider_requestor_name").should("have.value", dataProvider.requestor_name) + cy.get("#usage_data_provider_requestor_email").should("have.value", dataProvider.requestor_email) + + cy.get("#harvester_status .vs__selected").contains("Active") + cy.get("#report_type .vs__selected").contains("TR_J1") + cy.get("#usage_data_provider_begin_date").invoke("val").should("eq", dates["today_iso"]) + cy.get("#usage_data_provider_end_date").invoke("val").should("eq", dates["tomorrow_iso"]) + + // 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, + body: dataProvider, + }) + cy.get("#data_providers_add").contains("Submit").click() + cy.get("main div[class='dialog message']").contains("Data provider updated") + }) + + it("Should show provider", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/usage_data_providers/*", dataProvider).as( + "get-data-provider" + ) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + let name_link = cy.get( + "#usage_data_providers_list table tbody tr:first td:first a" + ) + name_link.should( + "have.text", + dataProvider.name + " (#" + dataProvider.erm_usage_data_provider_id + ")" + ) + name_link.click() + cy.wait("@get-data-provider") + cy.wait(500) // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#usage_data_providers_show h2").contains("Data provider #" + dataProvider.erm_usage_data_provider_id) + }) + + it("Should delete provider", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + // Click the 'Delete' button from the list + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + 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.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(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! + 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.contains("Yes, delete").click() + cy.get("main div[class='dialog message']") + .contains("Data provider") + .contains("deleted") + + // Delete from show + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/usage_data_providers/*", dataProvider).as( + "get-data-provider" + ) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + let name_link = cy.get( + "#usage_data_providers_list table tbody tr:first td:first a" + ) + name_link.should( + "have.text", + dataProvider.name + " (#" + dataProvider.erm_usage_data_provider_id + ")" + ) + name_link.click() + cy.wait("@get-data-provider") + cy.wait(500) + cy.get("#usage_data_providers_show h2").contains("Data provider #" + dataProvider.erm_usage_data_provider_id) + + cy.get("#usage_data_providers_show .action_links .fa-trash").click() + cy.get(".dialog.alert.confirmation h1").contains("remove this data provider") + 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") + }) +}) + +describe("Data providers summary", () => { + 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"}' + ) + }) + + it("Should navigate to the summary page and back to providers list", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + + cy.contains("Data providers summary").click() + cy.get("#usage_data_providers_summary").contains("Showing 1 to 1 of 1 entries") + + cy.contains("Data providers list").click() + cy.get("#usage_data_providers_list").contains("Showing 1 to 1 of 1 entries") + + }) + + it("Should correctly display dates", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + + cy.contains("Data providers summary").click() + + // Check provider name + cy.get("#usage_data_providers_summary table tbody tr:first td:first").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 + ) + cy.get("#usage_data_providers_summary table tbody tr:first td:nth-child(3)").should( + "have.text", + endDate + ) + // Check "Not run" harvests + cy.get("#usage_data_providers_summary table tbody tr:first td:nth-child(4)").should( + "have.text", + "Not run" + ) + }) +}) + +describe("Data provider tab options", () => { + 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"}' + ) + + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/usage_data_providers/*", dataProvider).as( + "get-data-provider" + ) + cy.visit("/cgi-bin/koha/erm/eusage/usage_data_providers") + let name_link = cy.get( + "#usage_data_providers_list table tbody tr:first td:first a" + ) + name_link.should( + "have.text", + dataProvider.name + " (#" + dataProvider.erm_usage_data_provider_id + ")" + ) + name_link.click() + cy.wait("@get-data-provider") + cy.wait(500) + }) + + it("Should display provider details", () => { + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + + cy.get("#usage_data_providers_show > div.tab-content > div > legend:nth-child(1)").should( + "have.text", + "Data provider" + ) + + //Page should be populated correctly + cy.get("#usage_data_provider_name").should("have.text", dataProvider.name) + cy.get("#usage_data_provider_description").should("have.text", dataProvider.description) + cy.get("#usage_data_provider_service_type").should("have.text", dataProvider.service_type) + cy.get("#usage_data_provider_service_url").should("have.text", dataProvider.service_url) + cy.get("#usage_data_provider_report_release").should("have.text", dataProvider.report_release) + cy.get("#usage_data_provider_customer_id").should("have.text", dataProvider.customer_id) + cy.get("#usage_data_provider_requestor_id").should("have.text", dataProvider.requestor_id) + cy.get("#usage_data_provider_api_key").should("have.text", dataProvider.api_key) + cy.get("#usage_data_provider_requestor_name").should("have.text", dataProvider.requestor_name) + cy.get("#usage_data_provider_requestor_email").should("have.text", dataProvider.requestor_email) + cy.get("#harvester_status").should("have.text", 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", () => { + cy.intercept("GET", "/api/v1/erm/usage_titles*", { + statusCode: 200, + body: [], + headers: { + "X-Base-Total-Count": "0", + "X-Total-Count": "0", + }, + }) + + cy.get("#usage_data_providerstabs").contains("Titles").click() + cy.get("main div[class='dialog message']").should( + "have.text", "No title data has been harvested for this provider" + ) + + cy.get("#usage_data_providerstabs").contains("Detail").click() + + const title = cy.get_usage_title() + const titles = [title] + cy.intercept("GET", "/api/v1/erm/usage_titles*", { + statusCode: 200, + body: titles, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + + cy.get("#usage_data_providerstabs").contains("Titles").click() + cy.get("#titles_list").contains("Showing 1 to 1 of 1 entries") + }) + + it("Should allow manual file upload", () => { + cy.get("#usage_data_providerstabs").contains("Manual upload").click() + cy.get("#files h2").should("have.text", "Manual upload:") + + cy.get("#import_file").click() + cy.get("#import_file").selectFile( + "t/cypress/fixtures/file.json" + ) + cy.get("#files .file_information span").contains("file.json") + }) + + it("Should display import logs", () => { + cy.intercept("GET", "/api/v1/erm/counter_files*", { + statusCode: 200, + body: [], + headers: { + "X-Base-Total-Count": "0", + "X-Total-Count": "0", + }, + }) + cy.get("#usage_data_providerstabs").contains("Import logs").click() + cy.get("main div[class='dialog message']").should( + "have.text", "There are no import logs defined" + ) + + cy.get("#usage_data_providerstabs").contains("Detail").click() + + const counter_file = cy.get_counter_file() + const counter_files = [counter_file] + cy.intercept("GET", "/api/v1/erm/counter_files*", { + statusCode: 200, + body: counter_files, + 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") + }) +}) \ No newline at end of file diff --git a/t/cypress/integration/ERM/UsageReports_spec.ts b/t/cypress/integration/ERM/UsageReports_spec.ts new file mode 100644 index 0000000000..a06ab46a3b --- /dev/null +++ b/t/cypress/integration/ERM/UsageReports_spec.ts @@ -0,0 +1,176 @@ +import { mount } from "@cypress/vue" + +const dayjs = require("dayjs") + +const dates = { + today_iso: dayjs().format("YYYY-MM-DD"), + today_us: dayjs().format("MM/DD/YYYY"), + tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"), + tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"), +} + +describe("Reports home tabs", () => { + 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"}' + ) + + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + const defaultReport = cy.get_default_report() + const defaulReports = [defaultReport] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/default_usage_reports*", { + statusCode: 200, + body: defaulReports, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + + cy.visit("/cgi-bin/koha/erm/eusage/reports") + }) + + it("Should display the saved reports page", () => { + cy.get("#report_builder .default-report h2") + .should('have.text', "Select saved report") + }) + + it("Should display the custom report builder", () => { + cy.get("#usage_data_providerstabs").contains("Create report").click() + + cy.get("#report-builder h2") + .should('have.text', "Build a custom report") + }) +}) + +describe("Saved reports", () => { + 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"}' + ) + + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + const defaultReport = cy.get_default_report() + const defaulReports = [defaultReport] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/default_usage_reports*", { + statusCode: 200, + body: defaulReports, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + + cy.visit("/cgi-bin/koha/erm/eusage/reports") + }) + + it("Should correctly populate the dropdown menu", () => { + const defaultReport = cy.get_default_report() + + cy.get("#default_usage_reports .vs__open-indicator").click() + cy.get("#default_usage_reports .vs__dropdown-menu li:first").should( + "have.text", defaultReport.report_name + ) + }) + + it("Should redirect to the reports viewer with the correct url params", () => { + const defaultReport = cy.get_default_report() + + cy.get("#default_usage_reports .vs__search").type( + defaultReport.report_name + "{enter}", + { force: true } + ) + + cy.get("#report_builder .default-report .action input").click() + + cy.url({ decode: true }).then(url => { + const urlParams = url.split('viewer?')[1].split('data=')[1] + const reportParams = defaultReport.report_url_params + + expect(urlParams).to.eq(reportParams) + }) + }) +}) + +describe("Custom reports", () => { + 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"}' + ) + + const dataProvider = cy.get_usage_data_provider() + const dataProviders = [dataProvider] + const defaultReport = cy.get_default_report() + const defaulReports = [defaultReport] + + cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { + statusCode: 200, + body: dataProviders, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + cy.intercept("GET", "/api/v1/erm/default_usage_reports*", { + statusCode: 200, + body: defaulReports, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + + cy.visit("/cgi-bin/koha/erm/eusage/reports") + }) + + it("Should offer options to create and display custom reports", () => { + // ToDo + }) +}) \ No newline at end of file diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index a423c73c7c..95f224760b 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -43,6 +43,15 @@ Cypress.Commands.add('login', (username, password) => { Cypress.Commands.add('left_menu_active_item_is', (label) => { cy.get("#navmenulist a.current:not(.disabled)").should('have.length',1).contains(label); }) +const dayjs = require("dayjs") /* Cannot use our calendar JS code, it's in an include file (!) + Also note that moment.js is deprecated */ + +const dates = { + today_iso: dayjs().format("YYYY-MM-DD"), + today_us: dayjs().format("MM/DD/YYYY"), + tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"), + tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"), +} cy.get_title = () => { return { @@ -129,3 +138,252 @@ cy.get_vendors_to_relate = () => { } ] } +cy.get_counter_file = () => { + return { + "date_uploaded": "2023-06-19T09:13:39+00:00", + "erm_counter_files_id": 1, + "file_content": "Report_Name,\"Journal Requests (Excluding OA_Gold)\"\r\nReport_ID,TR_J1\r\nRelease,5\r\nInstitution_Name,\"University Of West London\"\r\nInstitution_ID,\"Proprietary:Wiley:EAL00000122866; ISNI:0000000121857124\"\r\nMetric_Types,\"Total_Item_Requests; Unique_Item_Requests\"\r\nReport_Filters,\"Metric_Type:Total_Item_Requests|Unique_Item_Requests; Access_Type:Controlled; End_Date:2023-06-01; Begin_Date:2022-01-01; Data_Type:Journal; Access_Method:Regular\"\r\nReport_Attributes,\r\nExceptions,\"3031: Usage Not Ready for Requested Dates (Requested data between 2023-06-01 and 2023-06-01. However only data between 2018-11-01 and 2023-05-31 exists.)\"\r\nReporting_Period,\"Begin_Date=2022-01-01; End_Date=2023-06-01\"\r\nCreated,2023-06-19T02:13:31Z\r\nCreated_By,\"Atypon Systems LLC.\"\r\n\r\nTitle,Publisher,Publisher_ID,Platform,DOI,Proprietary_ID,Print_ISSN,Online_ISSN,URI,Metric_Type,Reporting_Period_Total,\"Jan 2022\",\"Feb 2022\",\"Mar 2022\",\"Apr 2022\",\"May 2022\",\"Jun 2022\",\"Jul 2022\",\"Aug 2022\",\"Sep 2022\",\"Oct 2022\",\"Nov 2022\",\"Dez 2022\",\"Jan 2023\",\"Feb 2023\",\"Mar 2023\",\"Apr 2023\",\"May 2023\",\"Jun 2023\"\r\n\"AEM Education and Training\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)2472-5390,Wiley:AET2,2472-5390,2472-5390,,Total_Item_Requests,16,1,3,0,1,3,1,0,2,1,0,0,1,0,3,0,0,0,0\r\n\"AEM Education and Training\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)2472-5390,Wiley:AET2,2472-5390,2472-5390,,Unique_Item_Requests,10,1,2,0,1,1,1,0,1,1,0,0,1,0,1,0,0,0,0\r\n\"AIChE Journal\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)1547-5905,Wiley:AIC,0001-1541,1547-5905,,Total_Item_Requests,4,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0\r\n\"AIChE Journal\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)1547-5905,Wiley:AIC,0001-1541,1547-5905,,Unique_Item_Requests,4,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0\r\n\"ANZ Journal of Surgery\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1445-2197,Wiley:ANS,1445-1433,1445-2197,,Total_Item_Requests,103,11,2,20,14,8,2,9,1,0,5,6,0,2,4,6,5,8,0\r\n\"ANZ Journal of Surgery\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1445-2197,Wiley:ANS,1445-1433,1445-2197,,Unique_Item_Requests,77,9,2,16,8,6,1,9,1,0,3,4,0,1,4,4,2,7,0\r\n\"AORN Journal\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)1878-0369,Wiley:AORN,0001-2092,1878-0369,,Total_Item_Requests,634,71,45,59,20,43,47,45,11,14,15,31,22,29,18,28,39,97,0\r\n\"AORN Journal\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)1878-0369,Wiley:AORN,0001-2092,1878-0369,,Unique_Item_Requests,436,53,27,27,15,34,30,30,6,11,13,22,17,23,16,26,26,60,0\r\nAPMIS,Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0463,Wiley:APM,0903-4641,1600-0463,,Total_Item_Requests,6,0,0,0,1,0,0,0,2,0,0,0,2,0,1,0,0,0,0\r\nAPMIS,Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0463,Wiley:APM,0903-4641,1600-0463,,Unique_Item_Requests,4,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0\r\n\"AWWA Water Science\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)2577-8161,Wiley:AWS2,,2577-8161,,Total_Item_Requests,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0\r\n\"AWWA Water Science\",Wiley,0000000403801313,\"Wiley Online Library\",10.1002/(ISSN)2577-8161,Wiley:AWS2,,2577-8161,,Unique_Item_Requests,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0\r\nAbacus,Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1467-6281,Wiley:ABAC,0001-3072,1467-6281,,Total_Item_Requests,51,3,0,7,0,2,0,1,0,0,0,11,6,0,3,17,1,0,0\r\nAbacus,Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1467-6281,Wiley:ABAC,0001-3072,1467-6281,,Unique_Item_Requests,36,2,0,6,0,2,0,1,0,0,0,7,2,0,2,13,1,0,0\r\n\"Academic Emergency Medicine\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1553-2712,Wiley:ACEM,1069-6563,1553-2712,,Total_Item_Requests,213,18,16,11,13,21,20,28,16,6,11,2,4,18,17,1,7,4,0\r\n\"Academic Emergency Medicine\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1553-2712,Wiley:ACEM,1069-6563,1553-2712,,Unique_Item_Requests,159,15,11,10,10,15,13,23,12,6,7,2,2,10,12,1,7,3,0\r\n\"Accounting & Finance\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1467-629X,Wiley:ACFI,0810-5391,1467-629X,,Total_Item_Requests,67,2,4,4,13,8,1,0,2,2,1,9,6,2,0,2,4,7,0\r\n\"Accounting & Finance\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1467-629X,Wiley:ACFI,0810-5391,1467-629X,,Unique_Item_Requests,53,1,4,4,11,7,1,0,2,1,1,7,3,1,0,2,4,4,0\r\n\"Accounting Perspectives\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1911-3838,Wiley:APR,1911-382X,1911-3838,,Total_Item_Requests,19,0,0,2,1,3,0,1,0,0,0,0,0,3,1,0,4,4,0\r\n\"Accounting Perspectives\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1911-3838,Wiley:APR,1911-382X,1911-3838,,Unique_Item_Requests,14,0,0,1,1,1,0,1,0,0,0,0,0,2,1,0,4,3,0\r\n\"Acta Anaesthesiologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1399-6576,Wiley:AAS,0001-5172,1399-6576,,Total_Item_Requests,181,29,20,19,5,15,4,19,6,5,6,4,0,3,29,1,12,4,0\r\n\"Acta Anaesthesiologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1399-6576,Wiley:AAS,0001-5172,1399-6576,,Unique_Item_Requests,117,21,12,11,4,10,4,14,3,5,4,4,0,2,14,1,4,4,0\r\n\"Acta Neurologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0404,Wiley:ANE,0001-6314,1600-0404,,Total_Item_Requests,23,0,0,2,0,5,0,1,1,0,2,2,0,2,1,5,2,0,0\r\n\"Acta Neurologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0404,Wiley:ANE,0001-6314,1600-0404,,Unique_Item_Requests,21,0,0,2,0,4,0,1,1,0,1,2,0,2,1,5,2,0,0\r\n\"Acta Obstetricia et Gynecologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0412,Wiley:AOGS,0001-6349,1600-0412,,Total_Item_Requests,22,1,0,0,0,0,0,0,0,0,0,0,0,0,0,15,4,2,0\r\n\"Acta Obstetricia et Gynecologica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0412,Wiley:AOGS,0001-6349,1600-0412,,Unique_Item_Requests,11,1,0,0,0,0,0,0,0,0,0,0,0,0,0,7,2,1,0\r\n\"Acta Ophthalmologica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1755-3768,Wiley:AOS,1755-375X,1755-3768,,Total_Item_Requests,2,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0\r\n\"Acta Ophthalmologica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1755-3768,Wiley:AOS,1755-375X,1755-3768,,Unique_Item_Requests,2,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0\r\n\"Acta Paediatrica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1651-2227,Wiley:APA,0803-5253,1651-2227,,Total_Item_Requests,229,23,26,14,12,8,45,22,6,10,8,3,9,7,8,11,9,8,0\r\n\"Acta Paediatrica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1651-2227,Wiley:APA,0803-5253,1651-2227,,Unique_Item_Requests,165,16,19,8,8,8,37,11,6,7,6,3,8,6,7,7,3,5,0\r\n\"Acta Physiologica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1748-1716,Wiley:APHA,1748-1708,1748-1716,,Total_Item_Requests,13,2,0,0,1,1,8,0,0,0,0,0,0,0,1,0,0,0,0\r\n\"Acta Physiologica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1748-1716,Wiley:APHA,1748-1708,1748-1716,,Unique_Item_Requests,12,2,0,0,1,1,7,0,0,0,0,0,0,0,1,0,0,0,0\r\n\"Acta Psychiatrica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0447,Wiley:ACPS,0001-690X,1600-0447,,Total_Item_Requests,226,5,9,28,28,15,18,4,1,2,4,13,14,24,8,20,21,12,0\r\n\"Acta Psychiatrica Scandinavica\",Wiley,0000000403801313,\"Wiley Online Library\",10.1111/(ISSN)1600-0447,Wiley:ACPS,0001-690X,1600-0447,,Unique_Item_Requests,178,4,5,19,23,10,17,3,1,1,4,13,10,19,6,18,14,11,0\r\n", + "filename": "PTFS Journals_TR_J1", + "type": "TR_J1", + "usage_data_provider_id": 1, + "counter_logs": [ + { + "borrowernumber": null, + "counter_files_id": 2, + "erm_counter_log_id": 2, + "filename": "PTFS Journals_TR_J1", + "importdate": "2023-06-19T09:40:46+00:00", + "logdetails": null + } + ] + } + +} + +cy.get_usage_data_provider = () => { + return { + "active": 1, + "aggregator": "test_aggregator", + "api_key": '12345', + "begin_date": dates['today_iso'], + "customer_id": "12345", + "description": "A data provider for cypress testing", + "end_date": dates['tomorrow_iso'], + "erm_usage_data_provider_id": 1, + "method": "test", + "name": "Cypress test provider", + "report_release": "test_report_release", + "report_types": "TR_J1;", + "requestor_email": "test_requestor_email", + "requestor_id": "12345", + "requestor_name": "test_requestor_name", + "service_type": "test_service_type", + "service_url": "www.url.com", + "counter_files": [ + { + "type": "TR_J1", + "date_uploaded": dates['today_iso'] + }, + { + "type": "TR_J1", + "date_uploaded": dates['tomorrow_iso'] + }, + + ] + } +} + +cy.get_usage_title = () => { + return [ + { + "online_issn": "2472-5390", + "print_issn": "2472-5390", + "publisher": "Wiley", + "publisher_id": "0000000403801313", + "title": "AEM Education and Training", + "title_doi": "10.1002/(ISSN)2472-5390", + "title_id": 1338, + "title_uri": "", + "usage_data_provider_id": 5 + } + ] +} + +cy.get_default_report = () => { + const params = { + "url": "/api/v1/erm/usage_titles/monthly_report?q=[{\"erm_usage_muses.year\":2022,\"erm_usage_muses.report_type\":\"TR_J1\",\"erm_usage_muses.month\":[1,2,3,4,5,6,7,8,9,10,11,12],\"erm_usage_muses.metric_type\":[\"Total_Item_Requests\",\"Unique_Item_Requests\"]},{\"erm_usage_muses.year\":2023,\"erm_usage_muses.report_type\":\"TR_J1\",\"erm_usage_muses.month\":[1,2,3,4,5,6,7,8,9,10,11,12],\"erm_usage_muses.metric_type\":[\"Total_Item_Requests\",\"Unique_Item_Requests\"]}]", + "columns": [1], + "queryObject": { + "data_display": "monthly", + "report_type": "TR_J1", + "metric_types": [ + "Total_Item_Requests", + "Unique_Item_Requests" + ], + "usage_data_providers": null, + "titles": null, + "start_month": null, + "start_year": "2022", + "end_month": null, + "end_year": "2023" + }, + "yearly_filter": true, + "type": "monthly", + "tp_columns": { + "2022": [ + { + "short": "Jan", + "description": "January", + "value": 1, + "active": true + }, + { + "short": "Feb", + "description": "February", + "value": 2, + "active": true + }, + { + "short": "Mar", + "description": "March", + "value": 3, + "active": true + }, + { + "short": "Apr", + "description": "April", + "value": 4, + "active": true + }, + { + "short": "May", + "description": "May", + "value": 5, + "active": true + }, + { + "short": "Jun", + "description": "June", + "value": 6, + "active": true + }, + { + "short": "Jul", + "description": "July", + "value": 7, + "active": true + }, + { + "short": "Aug", + "description": "August", + "value": 8, + "active": true + }, + { + "short": "Sep", + "description": "September", + "value": 9, + "active": true + }, + { + "short": "Oct", + "description": "October", + "value": 10, + "active": true + }, + { + "short": "Nov", + "description": "November", + "value": 11, + "active": true + }, + { + "short": "Dec", + "description": "December", + "value": 12, + "active": true + } + ], + "2023": [ + { + "short": "Jan", + "description": "January", + "value": 1, + "active": true + }, + { + "short": "Feb", + "description": "February", + "value": 2, + "active": true + }, + { + "short": "Mar", + "description": "March", + "value": 3, + "active": true + }, + { + "short": "Apr", + "description": "April", + "value": 4, + "active": true + }, + { + "short": "May", + "description": "May", + "value": 5, + "active": true + }, + { + "short": "Jun", + "description": "June", + "value": 6, + "active": true + }, + { + "short": "Jul", + "description": "July", + "value": 7, + "active": true + }, + { + "short": "Aug", + "description": "August", + "value": 8, + "active": true + }, + { + "short": "Sep", + "description": "September", + "value": 9, + "active": true + }, + { + "short": "Oct", + "description": "October", + "value": 10, + "active": true + }, + { + "short": "Nov", + "description": "November", + "value": 11, + "active": true + }, + { + "short": "Dec", + "description": "December", + "value": 12, + "active": true + } + ] + } + } + + return { + "erm_default_usage_report_id": 1, + "report_name": "Cypress report", + "report_url_params": JSON.stringify(params) + } +} -- 2.39.5