From 76b17cd24996c1a4f2c2404e748805b366b06214 Mon Sep 17 00:00:00 2001 From: swtmply Date: Thu, 15 Jun 2023 00:22:17 +0800 Subject: [PATCH] IO-2327 converting a job tests --- .../cypress/e2e/job-import/converting.cy.js | 65 +++++++++++++++++++ client/cypress/support/commands.js | 23 +++++++ .../jobs-convert-button.component.jsx | 18 +++-- 3 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 client/cypress/e2e/job-import/converting.cy.js diff --git a/client/cypress/e2e/job-import/converting.cy.js b/client/cypress/e2e/job-import/converting.cy.js new file mode 100644 index 000000000..93347deb8 --- /dev/null +++ b/client/cypress/e2e/job-import/converting.cy.js @@ -0,0 +1,65 @@ +describe( + "Check if there are job without RO number", + { + defaultCommandTimeout: 5000, + }, + () => { + beforeEach(() => { + cy.visit("/manage"); + + cy.get("body").then(($body) => { + if ($body.text().includes("Login")) { + // Log in + cy.get('[data-cy="username"]').type("john@imex.dev"); + cy.get('[data-cy="password"]').type("john123"); + cy.get('[data-cy="sign-in-button"]').click(); + } + + cy.get(".ant-table-tbody") + .find("tr") + .should("not.have.class", "ant-table-placeholder"); + + cy.get(".ant-table-row").find("a").contains("N/A").first().click(); + }); + }); + + it("shows the error messages of required fields", () => { + // Check if required fields are filled + cy.get('[data-cy="job-convert-button"]').click(); + cy.get('[data-cy="convert-button"]').click(); + + cy.antdFormSelect("", "Insurance Company Name", () => { + cy.contains("Insurance Company Name is required.").should("exist"); + }); + cy.antdFormSelect("", "Referral Source", () => { + cy.contains("Referral Source is required.").should("exist"); + }); + cy.antdFormSelect("", "Customer Service Rep.", () => { + cy.contains("Customer Service Rep. is required.").should("exist"); + }); + cy.antdFormSelect("", "Category", () => { + cy.contains("Category is required.").should("exist"); + }); + }); + + it("converts a job and issue an RO number", () => { + cy.get('[data-cy="job-convert-button"]').click(); + + // Check if fields are present + cy.antdFormSelect("ins_co_nm", "Insurance Company Name"); + cy.antdFormSelect("referral_source", "Referral Source", () => { + cy.get('[data-cy="referral_source_extra"]').type("Twitter"); + }); + cy.antdFormSelect("employee_csr", "Customer Service Rep."); + cy.antdFormSelect("category", "Category"); + + cy.get("#ca_gst_registrant").should("have.class", "ant-switch").click(); + cy.get("#driveable").should("have.class", "ant-switch").click(); + cy.get("#towin").should("have.class", "ant-switch").click(); + + // cy.get('[data-cy="convert-button"]').click(); + + // cy.get(".ant-notification-notice-message").contains("successfully"); + }); + } +); diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index 843555c17..f41485e3a 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -49,3 +49,26 @@ Cypress.on("uncaught:exception", (err, runnable) => { // failing the test return false; }); + +Cypress.Commands.add("antdSelect", (selector) => { + cy.get(`.ant-select-${selector} > .ant-select-selector`).click(); + cy.get(`.ant-select-${selector} .ant-select-selection-search input`) + .invoke("attr", "id") + .then((selElm) => { + const dropDownSelector = `#${selElm}_list`; + cy.get(dropDownSelector) + .next() + .find(".ant-select-item-option-content") + .first() + .click(); + }); +}); + +Cypress.Commands.add("antdFormSelect", (name, text, cb) => { + cy.get(".ant-form-item-required").then(($field) => { + if ($field.text().includes(text)) { + if (name) cy.antdSelect(name); + cb?.(); + } + }); +}); diff --git a/client/src/components/jobs-convert-button/jobs-convert-button.component.jsx b/client/src/components/jobs-convert-button/jobs-convert-button.component.jsx index b48deb3b5..bdda76f18 100644 --- a/client/src/components/jobs-convert-button/jobs-convert-button.component.jsx +++ b/client/src/components/jobs-convert-button/jobs-convert-button.component.jsx @@ -108,7 +108,7 @@ export function JobsConvertButton({ }, ]} > - {bodyshop.md_ins_cos.map((s, i) => ( {s.name} @@ -127,7 +127,7 @@ export function JobsConvertButton({ }, ]} > - {bodyshop.md_classes.map((s) => ( {s} @@ -148,7 +148,7 @@ export function JobsConvertButton({ }, ]} > - {bodyshop.md_referral_sources.map((s) => ( {s} @@ -157,6 +157,7 @@ export function JobsConvertButton({ @@ -176,6 +177,7 @@ export function JobsConvertButton({ ]} > +