fix: cypress add test for attach before doc save

added cypress test where attachment is added
before mandatory fields are filled so doc save will fail once
and then succeed after mandatory fields are filled then check if file is
attached to correct document and no orphaned files exist for that doc.
This commit is contained in:
Maharshi Patel 2023-10-18 16:15:02 +05:30
parent deb75cb07e
commit 86f0fdc5be

View file

@ -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");
});
});