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.
 
 
 
 
 
 

87 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("xhiveframework")
  9. .then((xhiveframework) => {
  10. new xhiveframework.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()
  21. .find(".file-upload-area")
  22. .selectFile("cypress/fixtures/example.json", {
  23. action: "drag-drop",
  24. });
  25. cy.get_open_dialog().find(".file-name").should("contain", "example.json");
  26. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  27. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  28. cy.wait("@upload_file").its("response.statusCode").should("eq", 200);
  29. cy.get(".modal:visible").should("not.exist");
  30. });
  31. it("should accept uploaded files", () => {
  32. open_upload_dialog();
  33. cy.get_open_dialog().findByRole("button", { name: "Library" }).click();
  34. cy.findByPlaceholderText("Search by filename or extension").type("example.json");
  35. cy.get_open_dialog().findAllByText("example.json").first().click();
  36. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  37. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  38. cy.wait("@upload_file")
  39. .its("response.body.message")
  40. .should("have.property", "file_name", "example.json");
  41. cy.get(".modal:visible").should("not.exist");
  42. });
  43. it("should accept web links", () => {
  44. open_upload_dialog();
  45. cy.get_open_dialog().findByRole("button", { name: "Link" }).click();
  46. cy.get_open_dialog()
  47. .findByPlaceholderText("Attach a web link")
  48. .type("https://github.com", { delay: 100, force: true });
  49. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  50. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  51. cy.wait("@upload_file")
  52. .its("response.body.message")
  53. .should("have.property", "file_url", "https://github.com");
  54. cy.get(".modal:visible").should("not.exist");
  55. });
  56. it("should allow cropping and optimization for valid images", () => {
  57. open_upload_dialog();
  58. cy.get_open_dialog()
  59. .find(".file-upload-area")
  60. .selectFile("cypress/fixtures/sample_image.jpg", {
  61. action: "drag-drop",
  62. });
  63. cy.get_open_dialog().findAllByText("sample_image.jpg").should("exist");
  64. cy.get_open_dialog().find(".btn-crop").first().click();
  65. cy.get_open_dialog().findByRole("button", { name: "Crop" }).click();
  66. cy.get_open_dialog().findAllByRole("checkbox", { name: "Optimize" }).should("exist");
  67. cy.get_open_dialog().findAllByLabelText("Optimize").first().click();
  68. cy.intercept("POST", "/api/method/upload_file").as("upload_file");
  69. cy.get_open_dialog().findByRole("button", { name: "Upload" }).click();
  70. cy.wait("@upload_file").its("response.statusCode").should("eq", 200);
  71. cy.get(".modal:visible").should("not.exist");
  72. });
  73. });