From 8f9dc0fe536cff780a9a109a5c3446f0f6b15acc Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 29 Oct 2024 16:54:16 +0000 Subject: [PATCH] Bug 38290: Add cypress tests (cherry picked from commit e270a21e248c58ae7f402628252c9589dccb618e) --- .../integration/Acquisitions/Vendors_spec.ts | 86 +++ .../integration/stores/VendorStore_spec.ts | 71 +++ t/cypress/support/e2e.js | 565 ++++++++++++++++++ 3 files changed, 722 insertions(+) create mode 100644 t/cypress/integration/stores/VendorStore_spec.ts diff --git a/t/cypress/integration/Acquisitions/Vendors_spec.ts b/t/cypress/integration/Acquisitions/Vendors_spec.ts index 63d66f45abe..b1896e44d47 100644 --- a/t/cypress/integration/Acquisitions/Vendors_spec.ts +++ b/t/cypress/integration/Acquisitions/Vendors_spec.ts @@ -43,6 +43,11 @@ const getVendor = () => { ], invoice_currency: "USD", invoice_includes_gst: false, + lib_group_visibility: "|1|11|", + lib_group_limits: [ + { id: 1, title: "LibGroup1" }, + { id: 11, title: "LibGroup2" }, + ], list_currency: "USD", list_includes_gst: false, name: "My Vendor", @@ -225,12 +230,16 @@ describe("Vendor CRUD operations", () => { "X-Total-Count": "1", }, }); + cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor).as( + "get-vendor" + ); cy.visit("/cgi-bin/koha/vendors"); const name_link = cy.get( "#vendors_list table tbody tr:first td:first a" ); name_link.should("have.text", vendor.name + " (#" + vendor.id + ")"); name_link.click(); + cy.wait("@get-vendor"); cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! cy.get("#vendors_show h1").contains(vendor.name); @@ -279,3 +288,80 @@ describe("Vendor CRUD operations", () => { .contains("deleted"); }); }); + +describe("Library group limits", () => { + beforeEach(() => { + cy.login(); + cy.title().should("eq", "Koha staff interface"); + cy.intercept("GET", "/api/v1/library_groups*", { + statusCode: 200, + body: cy.getLibraryGroups(), + }); + }); + + it("Should show a dropdown of library groups", () => { + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { + statusCode: 200, + body: [], + }); + + // Click the button in the toolbar + cy.visit("/cgi-bin/koha/vendors"); + + cy.contains("New vendor").click(); + cy.get("#vendor_add h2").contains("New vendor"); + + cy.get("#lib_group_visibility .vs__open-indicator").click(); + cy.get("#lib_group_visibility ul.vs__dropdown-menu").should( + "be.visible" + ); + cy.get("#lib_group_visibility ul.vs__dropdown-menu") + .find("li") + .as("options"); + cy.get("@options").should("have.length", 10); + + cy.get( + "#lib_group_visibility ul.vs__dropdown-menu li:nth-child(1)" + ).contains("LibGroup1"); + cy.get( + "#lib_group_visibility ul.vs__dropdown-menu li:nth-child(4)" + ).contains("LibGroup1 SubGroupB"); + cy.get( + "#lib_group_visibility ul.vs__dropdown-menu li:nth-child(10)" + ).contains("LibGroup2 SubGroupC SubGroup2"); + }); + + it("Should show a table of library groups", () => { + const vendor = getVendor(); + + // Click the "name" link from the list + cy.intercept("GET", "/api/v1/acquisitions/vendors*", { + statusCode: 200, + body: [vendor], + headers: { + "X-Base-Total-Count": "1", + "X-Total-Count": "1", + }, + }); + + cy.intercept("GET", "/api/v1/acquisitions/vendors/*", vendor).as( + "get-vendor" + ); + cy.visit("/cgi-bin/koha/vendors"); + const name_link = cy.get( + "#vendors_list table tbody tr:first td:first a" + ); + name_link.should("have.text", vendor.name + " (#" + vendor.id + ")"); + name_link.click(); + cy.wait("@get-vendor"); + cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! + cy.get("#vendors_show h1").contains(vendor.name); + + cy.get( + "#lib_group_visibility_table tbody tr:nth-child(1) td:nth-child(2)" + ).contains("LibGroup1"); + cy.get( + "#lib_group_visibility_table tbody tr:nth-child(2) td:nth-child(2)" + ).contains("LibGroup2"); + }); +}); diff --git a/t/cypress/integration/stores/VendorStore_spec.ts b/t/cypress/integration/stores/VendorStore_spec.ts new file mode 100644 index 00000000000..3d6d1426c33 --- /dev/null +++ b/t/cypress/integration/stores/VendorStore_spec.ts @@ -0,0 +1,71 @@ +import { setActivePinia, createPinia } from "pinia"; +import { useVendorStore } from "../../../../koha-tmpl/intranet-tmpl/prog/js/vue/stores/vendors"; + +describe("VendorStore", () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); + it("Should determine which branch to use when calling determineBranch()", () => { + const store = useVendorStore(); + + store.user.loggedInUser = { loggedInBranch: "XYZ", branchcode: "123" }; + const branch = store.determineBranch("ABC"); + expect(branch).to.eq("ABC"); + + store.user.loggedInUser = { loggedInBranch: "XYZ", branchcode: "123" }; + const branch2 = store.determineBranch(); + expect(branch2).to.eq("XYZ"); + + store.user.loggedInUser = { loggedInBranch: null, branchcode: "123" }; + const branch3 = store.determineBranch(); + expect(branch3).to.eq("123"); + }); + it("Should filter library groups by users branchcode when calling filterLibGroupsByUsersBranchcode", () => { + const store = useVendorStore(); + + store.setLibraryGroups(cy.getLibraryGroups()); + const filteredGroups = store.filterLibGroupsByUsersBranchcode("TPL"); + + expect(filteredGroups).to.have.length(3); + expect(filteredGroups[0].title).to.eq("LibGroup2"); + expect(filteredGroups[1].title).to.eq("LibGroup2 SubGroupC"); + expect(filteredGroups[2].title).to.eq("LibGroup2 SubGroupC SubGroup2"); + + const filteredGroupsTwo = store.filterLibGroupsByUsersBranchcode( + "MPL", + filteredGroups.map(grp => grp.id) + ); + expect(filteredGroupsTwo).to.have.length(2); + expect(filteredGroupsTwo[0].title).to.eq("LibGroup2"); + expect(filteredGroupsTwo[1].title).to.eq("LibGroup2 SubGroupC"); + }); + it("Should format library groups ids when calling formatLibraryGroupIds", () => { + const store = useVendorStore(); + + let ids = store.formatLibraryGroupIds("1|2|3"); + expect(ids).to.deep.eql([1, 2, 3]); + + ids = store.formatLibraryGroupIds("1"); + expect(ids).to.eql([1]); + }); + it("Should set library groups when calling setLibraryGroups", () => { + const store = useVendorStore(); + + store.setLibraryGroups(cy.getLibraryGroups()); + const libraryGroups = store.libraryGroups; + expect(libraryGroups).to.have.length(3); + expect(libraryGroups[0].title).to.eq("LibGroup1"); + expect(libraryGroups[1].title).to.eq("LibGroup2"); + expect(libraryGroups[2].title).to.eq("LibGroup3"); + + expect(libraryGroups[0].libraries).to.have.length(2); + expect(libraryGroups[0].subGroups).to.have.length(2); + expect(libraryGroups[0].subGroups[0].libraries).to.have.length(2); + expect(libraryGroups[0].subGroups[0].subGroups).to.have.length(2); + + expect(libraryGroups[1].libraries).to.have.length(3); + expect(libraryGroups[1].subGroups).to.have.length(3); + expect(libraryGroups[1].subGroups[0].libraries).to.have.length(2); + expect(libraryGroups[1].subGroups[0].subGroups).to.have.length(2); + }); +}); diff --git a/t/cypress/support/e2e.js b/t/cypress/support/e2e.js index 269f5eabd56..eae158a8adf 100644 --- a/t/cypress/support/e2e.js +++ b/t/cypress/support/e2e.js @@ -1813,6 +1813,571 @@ cy.getSushiService = () => { }; }; +cy.getLibraryGroups = () => { + return [ + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: true, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "1", + parent_id: null, + title: "LibGroup1", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "2", + parent_id: 1, + title: "LibGroup1 SubGroupA", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "3", + parent_id: 2, + title: "LibGroup1 SubGroupA SubGroup1", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "4", + parent_id: 2, + title: "LibGroup1 SubGroupA SubGroup2", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "5", + parent_id: 1, + title: "LibGroup1 SubGroupB", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "6", + parent_id: 2, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "FPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "7", + parent_id: 2, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "8", + parent_id: 5, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "FPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "9", + parent_id: 3, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "10", + parent_id: 4, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: true, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "11", + parent_id: null, + title: "LibGroup2", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "12", + parent_id: 11, + title: "LibGroup2 SubGroupA", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "13", + parent_id: 12, + title: "LibGroup2 SubGroupA SubGroup1", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "14", + parent_id: 12, + title: "LibGroup2 SubGroupA SubGroup2", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "15", + parent_id: 11, + title: "LibGroup2 SubGroupB", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "16", + parent_id: 11, + title: "LibGroup2 SubGroupC", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "17", + parent_id: 16, + title: "LibGroup2 SubGroupC SubGroup1", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "18", + parent_id: 16, + title: "LibGroup2 SubGroupC SubGroup2", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "19", + parent_id: 12, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "MPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "20", + parent_id: 12, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "21", + parent_id: 15, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "22", + parent_id: 16, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "MPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "23", + parent_id: 16, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "TPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "24", + parent_id: 16, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "MPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "25", + parent_id: 13, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "26", + parent_id: 14, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "MPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "27", + parent_id: 17, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "28", + parent_id: 18, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "TPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "29", + parent_id: 18, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: true, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "30", + parent_id: null, + title: "LibGroup3", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "31", + parent_id: 30, + title: "LibGroup3 SubGroupA", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "FFL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "32", + parent_id: 31, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "33", + parent_id: null, + title: "LibGroup4", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: null, + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "34", + parent_id: 33, + title: "LibGroup4 SubGroupA", + updated_on: "2024-10-29T15:18:08+00:00", + }, + { + branchcode: "CPL", + created_on: "2024-10-29T15:18:08+00:00", + description: null, + ft_acquisitions: false, + ft_hide_patron_info: false, + ft_limit_item_editing: false, + ft_local_float_group: false, + ft_local_hold_group: false, + ft_search_groups_opac: false, + ft_search_groups_staff: false, + id: "35", + parent_id: 34, + title: null, + updated_on: "2024-10-29T15:18:08+00:00", + }, + ]; +}; + const mysql = require("cypress-mysql"); mysql.addCommands(); -- 2.48.1