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.
 
 
 
 
 
 

93 lines
3.0 KiB

  1. import doctype_with_phone from "../fixtures/doctype_with_phone";
  2. context("Control Phone", () => {
  3. before(() => {
  4. cy.login();
  5. cy.visit("/app/website");
  6. });
  7. function get_dialog_with_phone() {
  8. return cy.dialog({
  9. title: "Phone",
  10. fields: [
  11. {
  12. fieldname: "phone",
  13. fieldtype: "Phone",
  14. },
  15. ],
  16. });
  17. }
  18. it("should set flag and data", () => {
  19. get_dialog_with_phone().as("dialog");
  20. cy.get(".selected-phone").click();
  21. cy.get(".phone-picker .phone-wrapper[id='afghanistan']").click();
  22. cy.get(".selected-phone").click();
  23. cy.get(".phone-picker .phone-wrapper[id='india']").click();
  24. cy.get(".selected-phone .country").should("have.text", "+91");
  25. cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg");
  26. let phone_number = "9312672712";
  27. cy.get(".selected-phone > img").click().first();
  28. cy.get_field("phone").first().click({ multiple: true });
  29. cy.get(".xhiveframework-control[data-fieldname=phone]")
  30. .findByRole("textbox")
  31. .first()
  32. .type(phone_number, { force: true });
  33. cy.get_field("phone").first().should("have.value", phone_number);
  34. cy.get_field("phone").first().blur({ force: true });
  35. cy.wait(100);
  36. cy.get("@dialog").then((dialog) => {
  37. let value = dialog.get_value("phone");
  38. expect(value).to.equal("+91-" + phone_number);
  39. });
  40. });
  41. it("case insensitive search for country and clear search", () => {
  42. let search_text = "india";
  43. cy.get(".selected-phone").click().first();
  44. cy.get(".phone-picker").findByRole("searchbox").click().type(search_text);
  45. cy.get(".phone-section .phone-wrapper:not(.hidden)").then((i) => {
  46. cy.get(`.phone-section .phone-wrapper[id*="${search_text.toLowerCase()}"]`).then(
  47. (countries) => {
  48. expect(i.length).to.equal(countries.length);
  49. }
  50. );
  51. });
  52. cy.get(".phone-picker").findByRole("searchbox").clear().blur();
  53. cy.get(".phone-section .phone-wrapper").should("not.have.class", "hidden");
  54. });
  55. it("existing document should render phone field with data", () => {
  56. cy.visit("/app/doctype");
  57. cy.insert_doc("DocType", doctype_with_phone, true);
  58. cy.clear_cache();
  59. // Creating custom doctype
  60. cy.insert_doc("DocType", doctype_with_phone, true);
  61. cy.visit("/app/doctype-with-phone");
  62. cy.click_listview_primary_button("Add Doctype With Phone");
  63. // create a record
  64. cy.fill_field("title", "Test Phone 1");
  65. cy.fill_field("phone", "+91-9823341234");
  66. cy.get_field("phone").should("have.value", "9823341234");
  67. cy.click_doc_primary_button("Save");
  68. cy.get_doc("Doctype With Phone", "Test Phone 1").then((doc) => {
  69. let value = doc.data.phone;
  70. expect(value).to.equal("+91-9823341234");
  71. });
  72. // open the doc from list view
  73. cy.go_to_list("Doctype With Phone");
  74. cy.clear_cache();
  75. cy.click_listview_row_item(0);
  76. cy.title().should("eq", "Test Phone 1");
  77. cy.get(".selected-phone .country").should("have.text", "+91");
  78. cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg");
  79. cy.get_field("phone").should("have.value", "9823341234");
  80. });
  81. });