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.
 
 
 
 
 
 

252 lines
9.5 KiB

  1. context("Attach Control", () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit("/app/doctype");
  5. return cy
  6. .window()
  7. .its("xhiveframework")
  8. .then((xhiveframework) => {
  9. return xhiveframework.xcall("xhiveframework.tests.ui_test_helpers.create_doctype", {
  10. name: "Test Attach Control",
  11. fields: [
  12. {
  13. label: "Attach File or Image",
  14. fieldname: "attach",
  15. fieldtype: "Attach",
  16. in_list_view: 1,
  17. },
  18. ],
  19. });
  20. });
  21. });
  22. it('Checking functionality for "Link" button in the "Attach" fieldtype', () => {
  23. //Navigating to the new form for the newly created doctype
  24. cy.new_form("Test Attach Control");
  25. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  26. cy.findByRole("button", { name: "Attach" }).click();
  27. //Clicking on "Link" button to attach a file using the "Link" button
  28. cy.findByRole("button", { name: "Link" }).click();
  29. cy.findByPlaceholderText("Attach a web link").type(
  30. "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg",
  31. { force: true }
  32. );
  33. //Clicking on the Upload button to upload the file
  34. cy.intercept("POST", "/api/method/upload_file").as("upload_image");
  35. cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 });
  36. cy.wait("@upload_image");
  37. cy.findByRole("button", { name: "Save" }).click();
  38. //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype
  39. cy.get(".attached-file > .ellipsis > .attached-file-link")
  40. .should("have.attr", "href")
  41. .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg");
  42. //Clicking on the "Clear" button
  43. cy.get('[data-action="clear_attachment"]').click();
  44. //Checking if clicking on the clear button clears the field of the doctype form and again displays the attach button
  45. cy.get(".control-input > .btn-sm").should("contain", "Attach");
  46. //Deleting the doc
  47. cy.go_to_list("Test Attach Control");
  48. cy.get(".list-row-checkbox").eq(0).click();
  49. cy.get(".actions-btn-group > .btn").contains("Actions").click();
  50. cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click();
  51. cy.click_modal_primary_button("Yes");
  52. });
  53. it('Checking functionality for "Library" button in the "Attach" fieldtype', () => {
  54. //Navigating to the new form for the newly created doctype
  55. cy.new_form("Test Attach Control");
  56. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  57. cy.findByRole("button", { name: "Attach" }).click();
  58. //Clicking on "Link" button to attach a file using the "Link" button
  59. cy.findByRole("button", { name: "Link" }).click();
  60. cy.findByPlaceholderText("Attach a web link").type(
  61. "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg",
  62. { force: true }
  63. );
  64. //Clicking on the Upload button to upload the file
  65. cy.intercept("POST", "/api/method/upload_file").as("upload_image");
  66. cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 });
  67. cy.wait("@upload_image");
  68. cy.findByRole("button", { name: "Save" }).click();
  69. //Navigating to the new form for the newly created doctype to check Library button
  70. cy.new_form("Test Attach Control");
  71. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  72. cy.findByRole("button", { name: "Attach" }).click();
  73. //Clicking on "Library" button to attach a file using the "Library" button
  74. cy.findByRole("button", { name: "Library" }).click();
  75. cy.contains("72402.jpg").click();
  76. //Clicking on the Upload button to upload the file
  77. cy.intercept("POST", "/api/method/upload_file").as("upload_image");
  78. cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 });
  79. cy.wait("@upload_image");
  80. cy.findByRole("button", { name: "Save" }).click();
  81. //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype
  82. cy.get(".attached-file > .ellipsis > .attached-file-link")
  83. .should("have.attr", "href")
  84. .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg");
  85. //Clicking on the "Clear" button
  86. cy.get('[data-action="clear_attachment"]').click();
  87. //Checking if clicking on the clear button clears the field of the doctype form and again displays the attach button
  88. cy.get(".control-input > .btn-sm").should("contain", "Attach");
  89. //Deleting both docs
  90. cy.go_to_list("Test Attach Control");
  91. cy.get(".list-row-checkbox").eq(0).click();
  92. cy.get(".list-row-checkbox").eq(1).click();
  93. cy.get(".actions-btn-group > .btn").contains("Actions").click();
  94. cy.get('.actions-btn-group > .dropdown-menu [data-label="Delete"]').click();
  95. cy.click_modal_primary_button("Yes");
  96. });
  97. it('Checking that "Camera" button in the "Attach" fieldtype does show if camera is available', () => {
  98. //Navigating to the new form for the newly created doctype
  99. let doctype = "Test Attach Control";
  100. let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
  101. cy.visit(`/app/${dt_in_route}/new`, {
  102. onBeforeLoad(win) {
  103. // Mock "window.navigator.mediaDevices" property
  104. // to return mock mediaDevices object
  105. win.navigator.mediaDevices = {
  106. ondevicechange: null,
  107. };
  108. },
  109. });
  110. cy.get("body").should(($body) => {
  111. const dataRoute = $body.attr("data-route");
  112. expect(dataRoute).to.match(new RegExp(`^Form/${doctype}/new-${dt_in_route}-`));
  113. });
  114. cy.get("body").should("have.attr", "data-ajax-state", "complete");
  115. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  116. cy.findByRole("button", { name: "Attach" }).click();
  117. //Clicking on "Camera" button
  118. cy.findByRole("button", { name: "Camera" }).should("exist");
  119. });
  120. it('Checking that "Camera" button in the "Attach" fieldtype does not show if no camera is available', () => {
  121. //Navigating to the new form for the newly created doctype
  122. let doctype = "Test Attach Control";
  123. let dt_in_route = doctype.toLowerCase().replace(/ /g, "-");
  124. cy.visit(`/app/${dt_in_route}/new`, {
  125. onBeforeLoad(win) {
  126. // Delete "window.navigator.mediaDevices" property
  127. delete win.navigator.mediaDevices;
  128. },
  129. });
  130. cy.get("body").should(($body) => {
  131. const dataRoute = $body.attr("data-route");
  132. expect(dataRoute).to.match(new RegExp(`^Form/${doctype}/new-${dt_in_route}-`));
  133. });
  134. cy.get("body").should("have.attr", "data-ajax-state", "complete");
  135. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  136. cy.findByRole("button", { name: "Attach" }).click();
  137. //Clicking on "Camera" button
  138. cy.findByRole("button", { name: "Camera" }).should("not.exist");
  139. });
  140. });
  141. context("Attach Control with Failed Document Save", () => {
  142. before(() => {
  143. cy.login();
  144. cy.visit("/app/doctype");
  145. return cy
  146. .window()
  147. .its("xhiveframework")
  148. .then((xhiveframework) => {
  149. return xhiveframework.xcall("xhiveframework.tests.ui_test_helpers.create_doctype", {
  150. name: "Test Mandatory Attach Control",
  151. fields: [
  152. {
  153. label: "Attach File or Image",
  154. fieldname: "attach",
  155. fieldtype: "Attach",
  156. in_list_view: 1,
  157. },
  158. {
  159. label: "Mandatory Text Field",
  160. fieldname: "text_field",
  161. fieldtype: "Text Editor",
  162. in_list_view: 1,
  163. reqd: 1,
  164. },
  165. ],
  166. });
  167. });
  168. });
  169. let temp_name = "";
  170. let docname = "";
  171. it("Attaching a file on an unsaved document", () => {
  172. //Navigating to the new form for the newly created doctype
  173. cy.new_form("Test Mandatory Attach Control");
  174. cy.get("body").should(($body) => {
  175. temp_name = $body.attr("data-route").split("/")[2];
  176. });
  177. //Clicking on the attach button which is displayed as part of creating a doctype with "Attach" fieldtype
  178. cy.findByRole("button", { name: "Attach" }).click();
  179. //Clicking on "Link" button to attach a file using the "Link" button
  180. cy.findByRole("button", { name: "Link" }).click();
  181. cy.findByPlaceholderText("Attach a web link").type(
  182. "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg",
  183. { force: true }
  184. );
  185. //Clicking on the Upload button to upload the file
  186. cy.intercept("POST", "/api/method/upload_file").as("upload_image");
  187. cy.get(".modal-footer").findByRole("button", { name: "Upload" }).click({ delay: 500 });
  188. cy.wait("@upload_image");
  189. cy.get(".msgprint-dialog .modal-title").contains("Missing Fields").should("be.visible");
  190. cy.hide_dialog();
  191. cy.fill_field("text_field", "Random value", "Text Editor").wait(500);
  192. cy.findByRole("button", { name: "Save" }).click().wait(500);
  193. //Checking if the URL of the attached image is getting displayed in the field of the newly created doctype
  194. cy.get(".attached-file > .ellipsis > .attached-file-link")
  195. .should("have.attr", "href")
  196. .and("equal", "https://wallpaperplay.com/walls/full/8/2/b/72402.jpg");
  197. cy.get(".title-text").then(($value) => {
  198. docname = $value.text();
  199. });
  200. });
  201. it("Check if file was uploaded correctly", () => {
  202. cy.go_to_list("File");
  203. cy.open_list_filter();
  204. cy.get(".fieldname-select-area .form-control")
  205. .click()
  206. .type("Attached To Name{enter}")
  207. .blur()
  208. .wait(500);
  209. cy.get('input[data-fieldname="attached_to_name"]').click().type(docname).blur();
  210. cy.get(".filter-popover .apply-filters").click({ force: true });
  211. cy.get("header .level-right .list-count").should("contain.text", "1 of 1");
  212. });
  213. it("Check if file exists with temporary name", () => {
  214. cy.open_list_filter();
  215. cy.get('input[data-fieldname="attached_to_name"]').click().clear().type(temp_name).blur();
  216. cy.get(".filter-popover .apply-filters").click({ force: true });
  217. cy.get(".xhiveframework-list > .no-result").should("be.visible");
  218. });
  219. });