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.

data_field_form_validation.js 1.6 KiB

1 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(`.xhiveframework-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(`.xhiveframework-control[data-fieldname="${fieldname}"]`).should(
  16. "not.have.class",
  17. "has-error"
  18. );
  19. }
  20. describe("Data Field Options", () => {
  21. it("should validate email address", () => {
  22. cy.new_form(doctype_name);
  23. validateField("email", "captian", "hello@test.com");
  24. });
  25. it("should validate URL", () => {
  26. validateField("url", "jkl", "https://xhiveframework.io");
  27. validateField("url", "abcd.com", "http://google.com/home");
  28. validateField("url", "&&http://google.uae", "gopher://xhiveframework.io");
  29. validateField("url", "ftt2:://google.in?q=news", "ftps2://xhiveframework.io/__/#home");
  30. validateField("url", "ftt2://", "ntps://localhost"); // For intranet URLs
  31. });
  32. it("should validate phone number", () => {
  33. validateField("phone", "america", "89787878");
  34. });
  35. it("should validate name", () => {
  36. validateField("person_name", " 777Hello", "James Bond");
  37. });
  38. });
  39. });