From cbe5e86fe8422c4c0d134de6df730bea06086382 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 26 Jul 2023 13:26:03 +0000 Subject: [PATCH] Bug 34587: Cypress update Update the cypress tests to reflect recent changes Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- .../UsageStatisticsDataProvidersSummary.vue | 11 ++- .../integration/ERM/DataProviders_spec.ts | 87 +++++++++++++++++- .../integration/ERM/UsageReports_spec.ts | 92 ++++++++++++++++--- t/cypress/support/e2e.js | 43 +++++++++ 4 files changed, 212 insertions(+), 21 deletions(-) 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 121cc68df1..0179e269d1 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,7 +122,8 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return row.begin_date + const date = getEarliestDate(row, "TR") + return date }, }, { @@ -141,7 +142,8 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return row.begin_date + const date = getEarliestDate(row, "PR") + return date }, }, { @@ -160,7 +162,8 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return row.begin_date + const date = getEarliestDate(row, "DR") + return date }, }, { @@ -169,7 +172,7 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - const date = getLatestDate(row, "PR") + const date = getLatestDate(row, "DR") return date }, }, diff --git a/t/cypress/integration/ERM/DataProviders_spec.ts b/t/cypress/integration/ERM/DataProviders_spec.ts index 498d84a89a..5dfa26e9bc 100644 --- a/t/cypress/integration/ERM/DataProviders_spec.ts +++ b/t/cypress/integration/ERM/DataProviders_spec.ts @@ -54,7 +54,6 @@ describe("Data provider CRUD operations", () => { "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") }) @@ -526,4 +525,88 @@ describe("Data provider tab options", () => { 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 +}) + +describe("Data providers action buttons", () => { + 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 queue a harvest background job", () => { + 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 table tbody tr:first").contains("Run now").click() + cy.get(".modal_centered p").contains(dataProvider.name) + + cy.intercept("GET", "/api/v1/erm/usage_data_providers/1/run*", { + statusCode: 200, + body: { jobs: [ + { + report_type: 'TR_J1', + job_id: 1 + } + ]}, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }) + 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.") + }) + + it("Should test a provider's SUSHI connection", () => { + 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.intercept("GET", "/api/v1/erm/usage_data_providers/1/test_connection", { + statusCode: 200, + body: 1, + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }).as("test-connection") + cy.get("#usage_data_providers_list table tbody tr:first").contains("Test").click() + cy.wait("@test-connection") + cy.get('#erm > div > div.main.container-fluid > div > div.col-sm-10.col-sm-push-2 > main > div.dialog.message') + .contains("Harvester connection was successful for usage data provider " + dataProvider.name) + }) +}) + diff --git a/t/cypress/integration/ERM/UsageReports_spec.ts b/t/cypress/integration/ERM/UsageReports_spec.ts index a06ab46a3b..3c4e05eb80 100644 --- a/t/cypress/integration/ERM/UsageReports_spec.ts +++ b/t/cypress/integration/ERM/UsageReports_spec.ts @@ -1,14 +1,5 @@ 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() @@ -145,10 +136,9 @@ describe("Custom reports", () => { '{"value":"local"}' ) - const dataProvider = cy.get_usage_data_provider() - const dataProviders = [dataProvider] + const dataProviders = cy.get_multiple_providers() const defaultReport = cy.get_default_report() - const defaulReports = [defaultReport] + const defaultReports = [defaultReport] cy.intercept("GET", "/api/v1/erm/usage_data_providers*", { statusCode: 200, @@ -160,7 +150,7 @@ describe("Custom reports", () => { }) cy.intercept("GET", "/api/v1/erm/default_usage_reports*", { statusCode: 200, - body: defaulReports, + body: defaultReports, headers: { "X-Base-Total-Count": "1", "X-Total-Count": "1", @@ -168,9 +158,81 @@ describe("Custom reports", () => { }) cy.visit("/cgi-bin/koha/erm/eusage/reports") + cy.get("#usage_data_providerstabs").contains("Create report").click() + }) + + it("Should limit report types based on the provider(s) selected", () => { + const dataProviders = cy.get_multiple_providers() + cy.get('#report_type').find('.vs__actions').click() + cy.get('#report_type').find('li').as('options') + cy.get('@options').should('have.length', 16) + + cy.get("#usage_data_provider .vs__search").type( + dataProviders[0].name + "{enter}", + { force: true } + ) + cy.get('#report_type').find('.vs__actions').click() + cy.get('#report_type').find('li').as('options') + cy.get('@options').should('have.length', 1) + + cy.get("#usage_data_provider .vs__search").type( + dataProviders[1].name + "{enter}", + { force: true } + ) + cy.get('#report_type').find('.vs__actions').click() + cy.get('#report_type').find('li').as('options') + cy.get('@options').should('have.length', 3) + }) + + it("Should limit data providers based on the report type(s) selected", () => { + cy.get('#usage_data_provider').find('.vs__actions').click() + cy.get('#usage_data_provider').find('li').as('options') + cy.get('@options').should('have.length', 2) + + cy.get("#report_type .vs__search").type( + "TR_J2" + "{enter}", + { force: true } + ) + cy.get('#usage_data_provider').find('.vs__actions').click() + cy.get('#usage_data_provider').find('li').as('options') + cy.get('@options').should('have.length', 1) + + cy.get("#report_type .vs__search").type( + "TR_J1" + "{enter}", + { force: true } + ) + cy.get('#usage_data_provider').find('.vs__actions').click() + cy.get('#usage_data_provider').find('li').as('options') + cy.get('@options').should('have.length', 2) }) - it("Should offer options to create and display custom reports", () => { - // ToDo + it("Should limit metric types based on the report type(s) selected", () => { + cy.get("#metric_type .vs__search").should('be.disabled') + + cy.get("#report_type .vs__search").type( + "TR_J1" + "{enter}", + { force: true } + ) + cy.get('#metric_type').find('.vs__actions').click() + cy.get('#metric_type').find('li').as('options') + cy.get('@options').should('have.length', 2) + + cy.get("#report_type .vs__search").type( + "PR" + "{enter}", + { force: true } + ) + cy.get('#metric_type').find('.vs__actions').click() + cy.get('#metric_type').find('li').as('options') + cy.get('@options').should('have.length', 7) + }) + + it("Should disable the month selectors when a yearly report is selected", () => { + cy.get("#interval .vs__search").type( + "By year" + "{enter}", + { force: true } + ) + + cy.get("#start-month .vs__search").should('be.disabled') + cy.get("#end_month .vs__search").should('be.disabled') }) }) \ No newline at end of file diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index 95f224760b..f733af94cc 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -387,3 +387,46 @@ cy.get_default_report = () => { "report_url_params": JSON.stringify(params) } } + +cy.get_multiple_providers = () => { + 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", + }, + { + "active": 1, + "aggregator": "test_aggregator", + "api_key": '12345', + "begin_date": dates['today_iso'], + "customer_id": "12345", + "description": "A second provider for reports testing", + "end_date": dates['tomorrow_iso'], + "erm_usage_data_provider_id": 2, + "method": "test", + "name": "Second test provider", + "report_release": "test_report_release", + "report_types": "TR_J1;TR_J2;TR_J3", + "requestor_email": "test_requestor_email", + "requestor_id": "12345", + "requestor_name": "test_requestor_name", + "service_type": "test_service_type", + "service_url": "www.url.com", + }, + ] +} -- 2.39.5