You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.9 KiB

  1. context("FileUploader", () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit("/app");
  5. });
  6. function open_upload_dialog() {
  7. cy.window()
  8. .its("frappe")
  9. .then((frappe) => {
  10. new frappe.ui.FileUploader();
  11. });
  12. }
  13. it("upload dialog api works", () => {
  14. open_upload_dialog();
  15. cy.get_open_dialog().should("contain", "Drag and drop files");
  16. cy.hide_dialog();
  17. });
  18. it("should accept dropped files", () => {
  19. open_upload_dialog();
  20. cy.get_open_dialog().find(".file-upload-area").attachFile("example.json", {
  21. subjectType: "drag-n-drop",
  22. });
  23. cy.get_open_dialog().find(".file-name").should("contain", "example.json");
  24. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  25. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  26. cy.wait("@upload_file").its("response.statusCode").should("eq", 200);
  27. cy.get(".modal:visible").should("not.exist");
  28. });
  29. it("should accept uploaded files", () => {
  30. open_upload_dialog();
  31. cy.get_open_dialog().findByRole("button", { name: "Library" }).click();
  32. cy.findByPlaceholderText("Search by filename or extension").type("example.json");
  33. cy.get_open_dialog().findAllByText("example.json").first().click();
  34. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  35. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  36. cy.wait("@upload_file")
  37. .its("response.body.message")
  38. .should("have.property", "file_name", "example.json");
  39. cy.get(".modal:visible").should("not.exist");
  40. });
  41. it("should accept web links", () => {
  42. open_upload_dialog();
  43. cy.get_open_dialog().findByRole("button", { name: "Link" }).click();
  44. cy.get_open_dialog()
  45. .findByPlaceholderText("Attach a web link")
  46. .type("https://github.com", { delay: 100, force: true });
  47. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  48. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  49. cy.wait("@upload_file")
  50. .its("response.body.message")
  51. .should("have.property", "file_url", "https://github.com");
  52. cy.get(".modal:visible").should("not.exist");
  53. });
  54. it("should allow cropping and optimization for valid images", () => {
  55. open_upload_dialog();
  56. cy.get_open_dialog().find(".file-upload-area").attachFile("sample_image.jpg", {
  57. subjectType: "drag-n-drop",
  58. });
  59. cy.get_open_dialog().findAllByText("sample_image.jpg").should("exist");
  60. cy.get_open_dialog().find(".btn-crop").first().click();
  61. cy.get_open_dialog().findByRole("button", { name: "Crop" }).click();
  62. cy.get_open_dialog().findAllByRole("checkbox", { name: "Optimize" }).should("exist");
  63. cy.get_open_dialog().findAllByLabelText("Optimize").first().click();
  64. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  65. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  66. cy.wait("@upload_file").its("response.statusCode").should("eq", 200);
  67. cy.get(".modal:visible").should("not.exist");
  68. });
  69. });