Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

depends_on.js 4.9 KiB

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