diff --git a/cypress/integration/control_attach.js b/cypress/integration/control_attach.js index 84a0487ce0..09f512b1e4 100644 --- a/cypress/integration/control_attach.js +++ b/cypress/integration/control_attach.js @@ -163,3 +163,89 @@ context("Attach Control", () => { cy.findByRole("button", { name: "Camera" }).should("not.exist"); }); }); +context("Attach Control with Failed Document Save", () => { + before(() => { + cy.login(); + cy.visit("/app/doctype"); + return cy + .window() + .its("frappe") + .then((frappe) => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", { + name: "Test Mandatory Attach Control", + fields: [ + { + label: "Attach File or Image", + fieldname: "attach", + fieldtype: "Attach", + in_list_view: 1, + }, + { + label: "Mandatory Text Field", + fieldname: "text_field", + fieldtype: "Text Editor", + in_list_view: 1, + reqd: 1, + }, + ], + }); + }); + }); + let temp_name = ""; + let docname = ""; + it('Checking functionality for "Attach" Where Document is not saved but File is Uploaded', () => { + //Navigating to the new form for the newly created doctype + cy.new_form("Test Mandatory Attach Control"); + cy.get("body").should(($body) => { + temp_name = $body.attr("data-route").split("/")[2]; + }); + + //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype + cy.findByRole("button", { name: "Attach" }).click(); + + //Clicking on "Link" button to attach a file using the "Link" button + cy.findByRole("button", { name: "Link" }).click(); + cy.findByPlaceholderText("Attach a web link").type( + "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg", + { force: true } + ); + + //Clicking on the Upload button to upload the file + cy.intercept("POST", "/api/method/upload_file").as("upload_image"); + cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 }); + cy.wait("@upload_image"); + cy.get(".msgprint-dialog .modal-title").contains("Missing Fields").should("be.visible"); + cy.hide_dialog(); + cy.fill_field("text_field", "Random value", "Text Editor").wait(500); + cy.findByRole("button", { name: "Save" }).click().wait(500); + + //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype + cy.get(".attached-file > .ellipsis > .attached-file-link") + .should("have.attr", "href") + .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg"); + + cy.get(".title-text").then(($value) => { + docname = $value.text(); + }); + }); + + it("Check If File was uploaded correctly", () => { + cy.go_to_list("File"); + cy.open_list_filter(); + cy.get(".fieldname-select-area .form-control") + .click() + .type("Attached To Name{enter}") + .blur() + .wait(500); + cy.get('input[data-fieldname="attached_to_name"]').click().type(docname).blur(); + cy.get(".filter-popover .apply-filters").click({ force: true }); + cy.get("header .level-right .list-count").should("contain.text", "1 of 1"); + }); + + it("Check If File exists with temp name", () => { + cy.open_list_filter(); + cy.get('input[data-fieldname="attached_to_name"]').click().clear().type(temp_name).blur(); + cy.get(".filter-popover .apply-filters").click({ force: true }); + cy.get(".frappe-list > .no-result").should("be.visible"); + }); +});