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.
 
 
 
 
 
 

115 line
4.3 KiB

  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. });
  60. });
  61. });
  62. it('should set the field as mandatory depending on other fields value', () => {
  63. cy.new_form('Test Depends On');
  64. cy.fill_field('test_field', 'Some Value');
  65. cy.findByRole('button', {name: 'Save'}).click();
  66. cy.get('.msgprint-dialog .modal-title').contains('Missing Fields').should('be.visible');
  67. cy.hide_dialog();
  68. cy.fill_field('test_field', 'Random value');
  69. cy.findByRole('button', {name: 'Save'}).click();
  70. cy.get('.msgprint-dialog .modal-title').contains('Missing Fields').should('not.be.visible');
  71. });
  72. it('should set the field as read only depending on other fields value', () => {
  73. cy.new_form('Test Depends On');
  74. cy.fill_field('dependant_field', 'Some Value');
  75. cy.fill_field('test_field', 'Some Other Value');
  76. cy.get('body').click();
  77. cy.get('.control-input [data-fieldname="dependant_field"]').should('be.disabled');
  78. cy.fill_field('test_field', 'Random Value');
  79. cy.get('body').click();
  80. cy.get('.control-input [data-fieldname="dependant_field"]').should('not.be.disabled');
  81. });
  82. it('should set the table and its fields as read only depending on other fields value', () => {
  83. cy.new_form('Test Depends On');
  84. cy.fill_field('dependant_field', 'Some Value');
  85. //cy.fill_field('test_field', 'Some Other Value');
  86. cy.get('.frappe-control[data-fieldname="child_test_depends_on_field"]').as('table');
  87. cy.get('@table').findByRole('button', {name: 'Add Row'}).click();
  88. cy.get('@table').find('[data-idx="1"]').as('row1');
  89. cy.get('@row1').find('.btn-open-row').click();
  90. cy.get('@row1').find('.form-in-grid').as('row1-form_in_grid');
  91. //cy.get('@row1-form_in_grid').find('')
  92. cy.fill_table_field('child_test_depends_on_field', '1', 'child_test_field', 'Some Value');
  93. cy.fill_table_field('child_test_depends_on_field', '1', 'child_dependant_field', 'Some Other Value');
  94. cy.get('@row1-form_in_grid').find('.grid-collapse-row').click();
  95. // set the table to read-only
  96. cy.fill_field('test_field', 'Some Other Value');
  97. // grid row form fields should be read-only
  98. cy.get('@row1').find('.btn-open-row').click();
  99. cy.get('@row1-form_in_grid').find('.control-input [data-fieldname="child_test_field"]').should('be.disabled');
  100. cy.get('@row1-form_in_grid').find('.control-input [data-fieldname="child_dependant_field"]').should('be.disabled');
  101. });
  102. it('should display the field depending on other fields value', () => {
  103. cy.new_form('Test Depends On');
  104. cy.get('.control-input [data-fieldname="display_dependant_field"]').should('not.be.visible');
  105. cy.get('.control-input [data-fieldname="test_field"]').clear();
  106. cy.fill_field('test_field', 'Value');
  107. cy.get('body').click();
  108. cy.get('.control-input [data-fieldname="display_dependant_field"]').should('be.visible');
  109. });
  110. });