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.
 
 
 
 
 
 

153 lines
5.0 KiB

  1. context("Depends On", () => {
  2. before(() => {
  3. cy.login();
  4. cy.visit("/app/website");
  5. return cy
  6. .window()
  7. .its("xhiveframework")
  8. .then((xhiveframework) => {
  9. return xhiveframework.xcall("xhiveframework.tests.ui_test_helpers.create_child_doctype", {
  10. name: "Child Test Depends On",
  11. fields: [
  12. {
  13. label: "Child Test Field",
  14. fieldname: "child_test_field",
  15. fieldtype: "Data",
  16. in_list_view: 1,
  17. },
  18. {
  19. label: "Child Dependant Field",
  20. fieldname: "child_dependant_field",
  21. fieldtype: "Data",
  22. in_list_view: 1,
  23. },
  24. {
  25. label: "Child Display Dependant Field",
  26. fieldname: "child_display_dependant_field",
  27. fieldtype: "Data",
  28. in_list_view: 1,
  29. },
  30. ],
  31. });
  32. })
  33. .then((xhiveframework) => {
  34. return xhiveframework.xcall("xhiveframework.tests.ui_test_helpers.create_doctype", {
  35. name: "Test Depends On",
  36. fields: [
  37. {
  38. label: "Test Field",
  39. fieldname: "test_field",
  40. fieldtype: "Data",
  41. },
  42. {
  43. label: "Dependant Field",
  44. fieldname: "dependant_field",
  45. fieldtype: "Data",
  46. mandatory_depends_on: "eval:doc.test_field=='Some Value'",
  47. read_only_depends_on: "eval:doc.test_field=='Some Other Value'",
  48. },
  49. {
  50. label: "Display Dependant Field",
  51. fieldname: "display_dependant_field",
  52. fieldtype: "Data",
  53. depends_on: "eval:doc.test_field=='Value'",
  54. },
  55. {
  56. label: "Child Test Depends On Field",
  57. fieldname: "child_test_depends_on_field",
  58. fieldtype: "Table",
  59. read_only_depends_on: "eval:doc.test_field=='Some Other Value'",
  60. options: "Child Test Depends On",
  61. },
  62. {
  63. label: "Dependent Tab",
  64. fieldname: "dependent_tab",
  65. fieldtype: "Tab Break",
  66. depends_on: "eval:doc.test_field=='Show Tab'",
  67. },
  68. {
  69. fieldname: "tab_section",
  70. fieldtype: "Section Break",
  71. },
  72. {
  73. label: "Field in Tab",
  74. fieldname: "field_in_tab",
  75. fieldtype: "Data",
  76. },
  77. ],
  78. });
  79. });
  80. });
  81. it("should show the tab on other setting field value", () => {
  82. cy.new_form("Test Depends On");
  83. cy.fill_field("test_field", "Show Tab");
  84. cy.get("body").click();
  85. cy.findByRole("tab", { name: "Dependent Tab" }).should("be.visible");
  86. });
  87. it("should set the field as mandatory depending on other fields value", () => {
  88. cy.new_form("Test Depends On");
  89. cy.fill_field("test_field", "Some Value");
  90. cy.findByRole("button", { name: "Save" }).click();
  91. cy.get(".msgprint-dialog .modal-title").contains("Missing Fields").should("be.visible");
  92. cy.hide_dialog();
  93. cy.fill_field("test_field", "Random value");
  94. cy.findByRole("button", { name: "Save" }).click();
  95. cy.get(".msgprint-dialog .modal-title")
  96. .contains("Missing Fields")
  97. .should("not.be.visible");
  98. });
  99. it("should set the field as read only depending on other fields value", () => {
  100. cy.new_form("Test Depends On");
  101. cy.fill_field("dependant_field", "Some Value");
  102. cy.fill_field("test_field", "Some Other Value");
  103. cy.get("body").click();
  104. cy.get('.control-input [data-fieldname="dependant_field"]').should("be.disabled");
  105. cy.fill_field("test_field", "Random Value");
  106. cy.get("body").click();
  107. cy.get('.control-input [data-fieldname="dependant_field"]').should("not.be.disabled");
  108. });
  109. it("should set the table and its fields as read only depending on other fields value", () => {
  110. cy.new_form("Test Depends On");
  111. cy.fill_field("dependant_field", "Some Value");
  112. //cy.fill_field('test_field', 'Some Other Value');
  113. cy.get('.xhiveframework-control[data-fieldname="child_test_depends_on_field"]').as("table");
  114. cy.get("@table").findByRole("button", { name: "Add Row" }).click();
  115. cy.get("@table").find('[data-idx="1"]').as("row1");
  116. cy.get("@row1").find(".btn-open-row").click();
  117. cy.get("@row1").find(".form-in-grid").as("row1-form_in_grid");
  118. //cy.get('@row1-form_in_grid').find('')
  119. cy.fill_table_field("child_test_depends_on_field", "1", "child_test_field", "Some Value");
  120. cy.fill_table_field(
  121. "child_test_depends_on_field",
  122. "1",
  123. "child_dependant_field",
  124. "Some Other Value"
  125. );
  126. cy.get("@row1-form_in_grid").find(".grid-collapse-row").click();
  127. // set the table to read-only
  128. cy.fill_field("test_field", "Some Other Value");
  129. // grid row form fields should be read-only
  130. cy.get("@row1").find(".btn-open-row").click();
  131. cy.get("@row1-form_in_grid")
  132. .find('.control-input [data-fieldname="child_test_field"]')
  133. .should("be.disabled");
  134. cy.get("@row1-form_in_grid")
  135. .find('.control-input [data-fieldname="child_dependant_field"]')
  136. .should("be.disabled");
  137. });
  138. it("should display the field depending on other fields value", () => {
  139. cy.new_form("Test Depends On");
  140. cy.get('.control-input [data-fieldname="display_dependant_field"]').should(
  141. "not.be.visible"
  142. );
  143. cy.get('.control-input [data-fieldname="test_field"]').clear();
  144. cy.fill_field("test_field", "Value");
  145. cy.get("body").click();
  146. cy.get('.control-input [data-fieldname="display_dependant_field"]').should("be.visible");
  147. });
  148. });