| Line 0
          
      
      
        Link Here | 
          
            
              | 0 | -  | 1 | import { mount } from "@cypress/vue"; | 
            
              |  |  | 2 |  | 
            
              | 3 | function get_package() { | 
            
              | 4 |     return { | 
            
              | 5 |         package_id: 1, | 
            
              | 6 |         name: "package 1", | 
            
              | 7 |         package_type: "complete", | 
            
              | 8 |         content_type: "Print", | 
            
              | 9 |         package_agreements: [ | 
            
              | 10 |             { | 
            
              | 11 |                 agreement: { | 
            
              | 12 |                     agreement_id: 2, | 
            
              | 13 |                     description: "agreement description", | 
            
              | 14 |                     name: "agreement name", | 
            
              | 15 |                 }, | 
            
              | 16 |                 agreement_id: 2, | 
            
              | 17 |                 package_id: 1, | 
            
              | 18 |             }, | 
            
              | 19 |         ], | 
            
              | 20 |         resources_count: 0, | 
            
              | 21 |     }; | 
            
              | 22 | } | 
            
              | 23 |  | 
            
              | 24 | describe("Dialog operations", () => { | 
            
              | 25 |     before(() => { | 
            
              | 26 |         cy.fetch_initial_ERM_sys_pref_value(); | 
            
              | 27 |         cy.set_ERM_sys_pref_value(true); | 
            
              | 28 |     }); | 
            
              | 29 |  | 
            
              | 30 |     beforeEach(() => { | 
            
              | 31 |         cy.login(); | 
            
              | 32 |         cy.title().should("eq", "Koha staff interface"); | 
            
              | 33 |     }); | 
            
              | 34 |  | 
            
              | 35 |     after(() => { | 
            
              | 36 |         cy.reset_initial_ERM_sys_pref_value(); | 
            
              | 37 |     }); | 
            
              | 38 |  | 
            
              | 39 |     it("There are no ... defined", () => { | 
            
              | 40 |         // GET packages returns empty list | 
            
              | 41 |         cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { | 
            
              | 42 |             statusCode: 200, | 
            
              | 43 |             body: [], | 
            
              | 44 |             headers: { | 
            
              | 45 |                 "X-Base-Total-Count": "0", | 
            
              | 46 |                 "X-Total-Count": "0", | 
            
              | 47 |             }, | 
            
              | 48 |         }); | 
            
              | 49 |         cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); | 
            
              | 50 |         cy.get("#packages_list").contains("There are no packages defined"); | 
            
              | 51 |     }); | 
            
              | 52 |  | 
            
              | 53 |     it("Something went wrong - 500", () => { | 
            
              | 54 |         // GET package returns 500 | 
            
              | 55 |         cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { | 
            
              | 56 |             statusCode: 500, | 
            
              | 57 |             error: "Something went wrong", | 
            
              | 58 |         }); | 
            
              | 59 |         cy.visit("/cgi-bin/koha/erm/erm.pl"); | 
            
              | 60 |         cy.get("#navmenulist").contains("Packages").click(); | 
            
              | 61 |         cy.get("main div[class='dialog alert']").contains( | 
            
              | 62 |             /Something went wrong/ | 
            
              | 63 |         ); | 
            
              | 64 |  | 
            
              | 65 |         cy.intercept("GET", "/api/v1/erm/agreements*", []); | 
            
              | 66 |         cy.get("#navmenulist").contains("Agreements").click(); | 
            
              | 67 |         // Info messages should be cleared when view is changed | 
            
              | 68 |         cy.get("main div[class='dialog message']").contains("There are no agreements defined"); | 
            
              | 69 |         cy.get("main div[class='dialog message']").should("have.length", 1); | 
            
              | 70 |     }); | 
            
              | 71 |  | 
            
              | 72 |     it("...created!", () => { | 
            
              | 73 |         let erm_package = get_package(); | 
            
              | 74 |         cy.intercept("GET", "/api/v1/erm/agreements*", []); | 
            
              | 75 |  | 
            
              | 76 |         cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add"); | 
            
              | 77 |         cy.get("#package_name").type(erm_package.name); | 
            
              | 78 |         cy.get("#package_type .vs__search").type( | 
            
              | 79 |             erm_package.package_type + "{enter}", | 
            
              | 80 |             { force: true } | 
            
              | 81 |         ); | 
            
              | 82 |  | 
            
              | 83 |         cy.intercept("POST", "/api/v1/erm/eholdings/local/packages", { | 
            
              | 84 |             statusCode: 201, | 
            
              | 85 |             body: erm_package, | 
            
              | 86 |         }); | 
            
              | 87 |         cy.get("#packages_add").contains("Submit").click(); | 
            
              | 88 |         cy.get("main div[class='dialog message']").contains("Package created"); | 
            
              | 89 |         cy.get("main div[class='dialog message']").should("have.length", 1); | 
            
              | 90 |  | 
            
              | 91 |         cy.get("#navmenulist").contains("Agreements").click(); | 
            
              | 92 |         // Info messages should be cleared when view is changed | 
            
              | 93 |         cy.get("main div[class='dialog message']").should("not.exist"); | 
            
              | 94 |     }); | 
            
              | 95 |  | 
            
              | 96 |     it("Confirmation messages", () => { | 
            
              | 97 |         let erm_package = get_package(); | 
            
              | 98 |         let packages = [erm_package]; | 
            
              | 99 |  | 
            
              | 100 |         // Click the 'Delete' button from the list | 
            
              | 101 |         cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", { | 
            
              | 102 |             statusCode: 200, | 
            
              | 103 |             body: packages, | 
            
              | 104 |             headers: { | 
            
              | 105 |                 "X-Base-Total-Count": "1", | 
            
              | 106 |                 "X-Total-Count": "1", | 
            
              | 107 |             }, | 
            
              | 108 |         }); | 
            
              | 109 |         cy.intercept("PUT", "/api/v1/erm/eholdings/local/packages/*", { | 
            
              | 110 |             statusCode: 200, | 
            
              | 111 |             body: [erm_package], | 
            
              | 112 |         }); | 
            
              | 113 |         cy.intercept( | 
            
              | 114 |             "GET", | 
            
              | 115 |             "/api/v1/erm/eholdings/local/packages/*", | 
            
              | 116 |             erm_package | 
            
              | 117 |         ); | 
            
              | 118 |         cy.visit("/cgi-bin/koha/erm/eholdings/local/packages"); | 
            
              | 119 |  | 
            
              | 120 |         cy.get("#packages_list table tbody tr:first").contains("Edit").click(); | 
            
              | 121 |         cy.get("#packages_add").contains("Submit").click(); | 
            
              | 122 |         cy.get("main div[class='dialog message']").contains("Package updated"); | 
            
              | 123 |         cy.get("main div[class='dialog message']").should("have.length", 1); | 
            
              | 124 |  | 
            
              | 125 |         cy.get("#packages_list table tbody tr:first") | 
            
              | 126 |             .contains("Delete") | 
            
              | 127 |             .click(); | 
            
              | 128 |         cy.contains("No, do not delete").click(); | 
            
              | 129 |         cy.get(".dialog.alert.confirmation h1").should("not.exist"); | 
            
              | 130 |         cy.get("main div[class='dialog message']").contains("Package updated"); | 
            
              | 131 |         cy.get("main div[class='dialog message']").should("have.length", 1); | 
            
              | 132 |  | 
            
              | 133 |         cy.intercept("DELETE", "/api/v1/erm/eholdings/local/packages/*", { | 
            
              | 134 |             statusCode: 204, | 
            
              | 135 |             body: null, | 
            
              | 136 |         }); | 
            
              | 137 |         cy.get("#packages_list table tbody tr:first") | 
            
              | 138 |             .contains("Delete") | 
            
              | 139 |             .click(); | 
            
              | 140 |         cy.get(".dialog.alert.confirmation h1").contains("remove this package"); | 
            
              | 141 |         cy.contains("Yes, delete").click(); | 
            
              | 142 |         cy.get("main div[class='dialog message']") | 
            
              | 143 |             .contains("Local package") | 
            
              | 144 |             .contains("deleted"); | 
            
              | 145 |         cy.get("main div[class='dialog message']").should("have.length", 1); | 
            
              | 146 |     }); | 
            
              | 147 | }); |