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.
 
 
 
 
 
 

43 lines
1.6 KiB

  1. import data_field_validation_doctype from '../fixtures/data_field_validation_doctype';
  2. const doctype_name = data_field_validation_doctype.name;
  3. context('Data Field Input Validation in New Form', () => {
  4. before(() => {
  5. cy.login();
  6. cy.visit('/app/website');
  7. return cy.insert_doc('DocType', data_field_validation_doctype, true);
  8. });
  9. function validateField(fieldname, invalid_value, valid_value) {
  10. // Invalid, should have has-error class
  11. cy.get_field(fieldname).clear().type(invalid_value).blur();
  12. cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should('have.class', 'has-error');
  13. // Valid value, should not have has-error class
  14. cy.get_field(fieldname).clear().type(valid_value);
  15. cy.get(`.frappe-control[data-fieldname="${fieldname}"]`).should('not.have.class', 'has-error');
  16. }
  17. describe('Data Field Options', () => {
  18. it('should validate email address', () => {
  19. cy.new_form(doctype_name);
  20. validateField('email', 'captian', 'hello@test.com');
  21. });
  22. it('should validate URL', () => {
  23. validateField('url', 'jkl', 'https://frappe.io');
  24. validateField('url', 'abcd.com', 'http://google.com/home');
  25. validateField('url', '&&http://google.uae', 'gopher://frappe.io');
  26. validateField('url', 'ftt2:://google.in?q=news', 'ftps2://frappe.io/__/#home');
  27. validateField('url', 'ftt2://', 'ntps://localhost'); // For intranet URLs
  28. });
  29. it('should validate phone number', () => {
  30. validateField('phone', 'america', '89787878');
  31. });
  32. it('should validate name', () => {
  33. validateField('person_name', ' 777Hello', 'James Bond');
  34. });
  35. });
  36. });