From eee5f986853f20601821affa1a902c62d2d33d1a Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 24 Oct 2024 16:00:20 +0000 Subject: [PATCH] Bug 35287: Fix tests Have a single point go get_license to be used by both Licenses_spec.ts and AdditionalFields_spec.ts Test plan, apply patch: $ yarn js:build $ cypress run --spec t/cypress/integration/AdditionalFields_spec.ts $ cypress run --spec t/cypress/integration/Licenses_spec.ts --- .../integration/AdditionalFields_spec.ts | 91 +------------------ t/cypress/integration/ERM/Licenses_spec.ts | 35 +------ t/cypress/support/e2e.js | 86 ++++++++++++++++++ 3 files changed, 94 insertions(+), 118 deletions(-) diff --git a/t/cypress/integration/AdditionalFields_spec.ts b/t/cypress/integration/AdditionalFields_spec.ts index 9a7885aa5d..a334df4688 100644 --- a/t/cypress/integration/AdditionalFields_spec.ts +++ b/t/cypress/integration/AdditionalFields_spec.ts @@ -37,91 +37,6 @@ function get_no_additional_fields_license() { }, }; } -function get_license() { - return { - license_id: 1, - name: "license 1", - description: "my first license", - type: "local", - status: "active", - started_on: dates["today_iso"], - ended_on: dates["tomorrow_iso"], - user_roles: [], - vendor_id: 1, - vendor: [cy.get_vendors_to_relate()[0]], - 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", - }, - ], - extended_attributes: [ - { - field_id: 1, - id: "1", - record_id: "1", - value: "REF", - }, - { - field_id: 1, - id: "2", - record_id: "1", - value: "NFIC", - }, - { - field_id: 2, - id: "3", - record_id: "1", - value: "some text", - }, - { - field_id: 3, - id: "4", - record_id: "1", - value: "some repeatable text", - }, - { - field_id: 4, - id: "5", - record_id: "1", - value: "AF", - }, - ], - _strings: { - additional_field_values: [ - { - field_id: 1, - field_label: "AV Repeatable", - type: "av", - value_str: "Reference, Non-fiction", - }, - { - field_id: 2, - field_label: "Text non-repeatable", - type: "text", - value_str: "some text", - }, - { - field_id: 3, - field_label: "Text repeatable", - type: "text", - value_str: "some repeatable text", - }, - { - field_id: 4, - field_label: "AV Searchable", - type: "av", - value_str: "Afghanistan", - }, - ], - }, - }; -} function get_licenses_additional_fields() { return [ @@ -253,7 +168,7 @@ describe("Additional Fields operations", () => { }); it("Additional Fields display - Table (licenses)", () => { - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; let license_additional_fields = get_licenses_additional_fields(); let av_cats = get_av_cats(); @@ -296,7 +211,7 @@ describe("Additional Fields operations", () => { it("Additional Fields display - Show (licenses)", () => { let empty_license = get_no_additional_fields_license(); - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; let vendors = cy.get_vendors_to_relate(); let license_additional_fields = get_licenses_additional_fields(); @@ -529,7 +444,7 @@ describe("Additional Fields operations", () => { }); it("Additional Fields entry - Edit (licenses)", () => { - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; let vendors = cy.get_vendors_to_relate(); let license_additional_fields = get_licenses_additional_fields(); diff --git a/t/cypress/integration/ERM/Licenses_spec.ts b/t/cypress/integration/ERM/Licenses_spec.ts index ae189b640e..f712b528cd 100644 --- a/t/cypress/integration/ERM/Licenses_spec.ts +++ b/t/cypress/integration/ERM/Licenses_spec.ts @@ -8,31 +8,6 @@ const dates = { tomorrow_iso: dayjs().add(1, "day").format("YYYY-MM-DD"), tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"), }; -function get_license() { - return { - license_id: 1, - name: "license 1", - description: "my first license", - type: "local", - status: "active", - started_on: dates["today_iso"], - ended_on: dates["tomorrow_iso"], - user_roles: [], - vendor_id: 1, - vendor: [cy.get_vendors_to_relate()[0]], - 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", - }, - ], - }; -} describe("License CRUD operations", () => { beforeEach(() => { @@ -62,7 +37,7 @@ describe("License CRUD operations", () => { cy.get("#licenses_list").contains("There are no licenses defined"); // GET licenses returns something - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; cy.intercept("GET", "/api/v1/erm/licenses*", { @@ -79,7 +54,7 @@ describe("License CRUD operations", () => { }); it("Add license", () => { - let license = get_license(); + let license = cy.get_license(); let vendors = cy.get_vendors_to_relate(); //Intercept vendors request cy.intercept("GET", "/api/v1/acquisitions/vendors*", { @@ -174,7 +149,7 @@ describe("License CRUD operations", () => { }); it("Edit license", () => { - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; let vendors = cy.get_vendors_to_relate(); @@ -256,7 +231,7 @@ describe("License CRUD operations", () => { }); it("Show license", () => { - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; // Click the "name" link from the list cy.intercept("GET", "/api/v1/erm/licenses*", { @@ -286,7 +261,7 @@ describe("License CRUD operations", () => { }); it("Delete license", () => { - let license = get_license(); + let license = cy.get_license(); let licenses = [license]; // Click the 'Delete' button from the list diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index c0d0d2d6f7..27d79e47c6 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -53,6 +53,92 @@ const dates = { tomorrow_us: dayjs().add(1, "day").format("MM/DD/YYYY"), } +cy.get_license = () => { + return { + license_id: 1, + name: "license 1", + description: "my first license", + type: "local", + status: "active", + started_on: dates["today_iso"], + ended_on: dates["tomorrow_iso"], + user_roles: [], + vendor_id: 1, + vendor: [cy.get_vendors_to_relate()[0]], + 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", + }, + ], + extended_attributes: [ + { + field_id: 1, + id: "1", + record_id: "1", + value: "REF", + }, + { + field_id: 1, + id: "2", + record_id: "1", + value: "NFIC", + }, + { + field_id: 2, + id: "3", + record_id: "1", + value: "some text", + }, + { + field_id: 3, + id: "4", + record_id: "1", + value: "some repeatable text", + }, + { + field_id: 4, + id: "5", + record_id: "1", + value: "AF", + }, + ], + _strings: { + additional_field_values: [ + { + field_id: 1, + field_label: "AV Repeatable", + type: "av", + value_str: "Reference, Non-fiction", + }, + { + field_id: 2, + field_label: "Text non-repeatable", + type: "text", + value_str: "some text", + }, + { + field_id: 3, + field_label: "Text repeatable", + type: "text", + value_str: "some repeatable text", + }, + { + field_id: 4, + field_label: "AV Searchable", + type: "av", + value_str: "Afghanistan", + }, + ], + }, + }; +} + cy.get_agreement = () => { let licenses = cy.get_licenses_to_relate(); return { -- 2.39.5