From 544d248323576f56b8d70073e132f9831af6e835 Mon Sep 17 00:00:00 2001 From: Noah Jacob Date: Wed, 30 Mar 2022 18:34:25 +0530 Subject: [PATCH] test(ui): increasing coverage in tests --- cypress/fixtures/doctype_with_phone.js | 47 +++++++++++ cypress/integration/control_phone.js | 110 ++++++++++++++++++------- cypress/support/commands.js | 4 + 3 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 cypress/fixtures/doctype_with_phone.js diff --git a/cypress/fixtures/doctype_with_phone.js b/cypress/fixtures/doctype_with_phone.js new file mode 100644 index 0000000000..c62922ade2 --- /dev/null +++ b/cypress/fixtures/doctype_with_phone.js @@ -0,0 +1,47 @@ +export default { + name: "Doctype With Phone", + actions: [], + custom: 1, + is_submittable: 1, + autoname: "field:title", + creation: '2022-03-30 06:29:07.215072', + doctype: 'DocType', + engine: 'InnoDB', + fields: [ + + { + fieldname: 'title', + fieldtype: 'Data', + label: 'title', + unique: 1, + }, + { + fieldname: 'phone', + fieldtype: 'Phone', + label: 'Phone' + } + ], + links: [], + modified: '2019-03-30 14:40:53.127615', + modified_by: 'Administrator', + naming_rule: "By fieldname", + module: 'Custom', + owner: 'Administrator', + permissions: [ + { + create: 1, + delete: 1, + email: 1, + print: 1, + read: 1, + role: 'System Manager', + share: 1, + write: 1, + submit: 1, + cancel: 1 + } + ], + sort_field: 'modified', + sort_order: 'ASC', + track_changes: 1 +}; diff --git a/cypress/integration/control_phone.js b/cypress/integration/control_phone.js index 0d0812b983..2e6d30daf8 100644 --- a/cypress/integration/control_phone.js +++ b/cypress/integration/control_phone.js @@ -1,59 +1,113 @@ -context('Control Phone', () => { +import doctype_with_phone from '../fixtures/doctype_with_phone'; + +context("Control Phone", () => { before(() => { cy.login(); - cy.visit('/app/website'); + cy.visit("/app/website"); }); function get_dialog_with_phone() { return cy.dialog({ - title: 'Phone', + title: "Phone", fields: [{ - 'fieldname': 'phone', - 'fieldtype': 'Phone', + "fieldname": "phone", + "fieldtype": "Phone", }] }); } - it('should set flag and data', () => { - get_dialog_with_phone().as('dialog'); - cy.get('.selected-phone > svg').click(); - cy.get('.phone-picker .phone-wrapper[id="afghanistan"]').click(); - cy.get('.phone-picker .phone-wrapper[id="india"]').click(); - cy.get('.selected-phone .country').should('have.text', '+91'); - cy.get('.selected-phone > img').should('have.attr', 'src').and('include', '/in.svg'); + it("should set flag and data", () => { + get_dialog_with_phone().as("dialog"); + cy.get(".selected-phone > svg").click(); + cy.get(".phone-picker .phone-wrapper[id='afghanistan']").click(); + cy.get(".phone-picker .phone-wrapper[id='india']").click(); + cy.get(".selected-phone .country").should("have.text", "+91"); + cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg"); - let phone_number = '9312672712'; - cy.get('.selected-phone > img').click().first(); + let phone_number = "9312672712"; + cy.get(".selected-phone > img").click().first(); cy.get_field("phone") .first() .click({multiple: true}); - cy.get('.frappe-control[data-fieldname=phone]') - .findByRole('textbox') + cy.get(".frappe-control[data-fieldname=phone]") + .findByRole("textbox") .first() .type(phone_number, {force: true}); - cy.get_field("phone").first().should('have.value', phone_number); - cy.wait(1000) + cy.get_field("phone").first().should("have.value", phone_number); + cy.wait(1000); cy.get_field("phone").first().blur({force: true}); - cy.get('@dialog').then(dialog => { + cy.get("@dialog").then(dialog => { let value = dialog.get_value("phone"); - expect(value).to.equal('+91-' + phone_number); + expect(value).to.equal("+91-" + phone_number); }); }); - it('case insensitive search for country and clear search', () => { - let search_text = 'india'; - cy.get('.selected-phone > img').click().first(); - cy.get('.phone-picker').findByRole('searchbox').click().type(search_text); - cy.get('.phone-section .phone-wrapper:not(.hidden)').then(i => { - cy.get(`.phone-section .phone-wrapper[id*='${search_text.toLowerCase()}']`).then(countries => { + it("case insensitive search for country and clear search", () => { + let search_text = "india"; + cy.get(".selected-phone > img").click().first(); + cy.get(".phone-picker").findByRole("searchbox").click().type(search_text); + cy.get(".phone-section .phone-wrapper:not(.hidden)").then(i => { + cy.get(`.phone-section .phone-wrapper[id*="${search_text.toLowerCase()}"]`).then(countries => { expect(i.length).to.equal(countries.length); }); }); - cy.get('.phone-picker').findByRole('searchbox').clear().blur(); - cy.get('.phone-section .phone-wrapper').should('not.have.class', 'hidden'); + cy.get(".phone-picker").findByRole("searchbox").clear().blur(); + cy.get(".phone-section .phone-wrapper").should("not.have.class", "hidden"); }); + it("Already existing docs with phone field", () => { + cy.visit("/app/doctype"); + cy.insert_doc("DocType", doctype_with_phone, true); + cy.clear_cache(); + + // Creating custom doctype + cy.insert_doc("DocType", doctype_with_phone, true); + cy.visit("/app/doctype-with-phone"); + cy.click_listview_primary_button("Add Doctype With Phone"); + + //Adding a new entry for the created custom doctype + cy.fill_field("title", "Test Phone 1"); + cy.fill_field("phone", "+91-9823341234"); + cy.wait(500); + cy.get_field("phone").should("have.value", "9823341234"); + cy.click_doc_primary_button("Save"); + cy.wait(500); + cy.get_doc("Doctype With Phone", "Test Phone 1").then((doc) => { + let value = doc.data.phone; + expect(value).to.equal("+91-9823341234"); + }); + cy.go_to_list("Doctype With Phone"); + cy.click_listview_primary_button("Add Doctype With Phone"); + // Field should be empty on new doc + cy.get_field("phone").should("have.value", ""); + cy.get(".selected-phone .country").should("have.text", ""); + cy.fill_field("title", "Test Phone 2"); + cy.fill_field("phone", "+91-9823341291"); + cy.wait(500); + cy.get_field("phone").should("have.value", "9823341291"); + cy.click_doc_primary_button("Save"); + cy.wait(500); + cy.go_to_list("Doctype With Phone"); + cy.clear_cache(); + cy.click_listview_row_item(0); + cy.title().should("eq", "Test Phone 2"); + cy.get(".selected-phone .country").should("have.text", "+91"); + cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg"); + cy.get_field("phone").should("have.value", "9823341291"); + cy.go_to_list("Doctype With Phone"); + cy.click_listview_row_item(1); + cy.title().should("eq", "Test Phone 1"); + cy.get(".selected-phone .country").should("have.text", "+91"); + cy.get(".selected-phone > img").should("have.attr", "src").and("include", "/in.svg"); + cy.get_field("phone").should("have.value", "9823341234"); + cy.get_doc("Doctype With Phone", "Test Phone 2").then((doc) => { + let value = doc.data.phone; + expect(value).to.equal("+91-9823341291"); + cy.remove_doc("Doctype With Phone", "Test Phone 1", true); + cy.remove_doc("Doctype With Phone", "Test Phone 2", true); + }); + }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 4f273af21f..7d9932198d 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -325,6 +325,10 @@ Cypress.Commands.add('click_listview_primary_button', (btn_name) => { cy.get('.primary-action').contains(btn_name).click({force: true}); }); +Cypress.Commands.add('click_doc_primary_button', (btn_name) => { + cy.get('.primary-action').contains(btn_name).click({force: true}); +}); + Cypress.Commands.add('click_timeline_action_btn', (btn_name) => { cy.get('.timeline-message-box .actions .action-btn').contains(btn_name).click(); });