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.
 
 
 
 
 
 

91 rivejä
2.9 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. "fieldname": "phone",
  12. "fieldtype": "Phone",
  13. }]
  14. });
  15. }
  16. it("should set flag and data", () => {
  17. get_dialog_with_phone().as("dialog");
  18. cy.get(".selected-phone").click();
  19. cy.get(".phone-picker .phone-wrapper[id='afghanistan']").click();
  20. cy.get(".selected-phone").click();
  21. cy.get(".phone-picker .phone-wrapper[id='india']").click();
  22. cy.get(".selected-phone .country").should("have.text", "+91");
  23. cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg");
  24. let phone_number = "9312672712";
  25. cy.get(".selected-phone > img").click().first();
  26. cy.get_field("phone")
  27. .first()
  28. .click({multiple: true});
  29. cy.get(".frappe-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(countries => {
  47. expect(i.length).to.equal(countries.length);
  48. });
  49. });
  50. cy.get(".phone-picker").findByRole("searchbox").clear().blur();
  51. cy.get(".phone-section .phone-wrapper").should("not.have.class", "hidden");
  52. });
  53. it("existing document should render phone field with data", () => {
  54. cy.visit("/app/doctype");
  55. cy.insert_doc("DocType", doctype_with_phone, true);
  56. cy.clear_cache();
  57. // Creating custom doctype
  58. cy.insert_doc("DocType", doctype_with_phone, true);
  59. cy.visit("/app/doctype-with-phone");
  60. cy.click_listview_primary_button("Add Doctype With Phone");
  61. // create a record
  62. cy.fill_field("title", "Test Phone 1");
  63. cy.fill_field("phone", "+91-9823341234");
  64. cy.get_field("phone").should("have.value", "9823341234");
  65. cy.click_doc_primary_button("Save");
  66. cy.get_doc("Doctype With Phone", "Test Phone 1").then((doc) => {
  67. let value = doc.data.phone;
  68. expect(value).to.equal("+91-9823341234");
  69. });
  70. // open the doc from list view
  71. cy.go_to_list("Doctype With Phone");
  72. cy.clear_cache();
  73. cy.click_listview_row_item(0);
  74. cy.title().should("eq", "Test Phone 1");
  75. cy.get(".selected-phone .country").should("have.text", "+91");
  76. cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg");
  77. cy.get_field("phone").should("have.value", "9823341234");
  78. });
  79. });