import job from "../../fixtures/jobs/job-3.json"; import job2 from "../../fixtures/jobs/job-4.json"; import jobSupplement from "../../fixtures/jobs/job-3-supplement.json"; import jobMetadata from "../../fixtures/jobs/job-3-jobmetadata.json"; import jobSupplementMetadata from "../../fixtures/jobs/job-3-supplment-jobmetadata.json"; import Dinero from "dinero.js"; const createJobEstimate = (job, bodyshopid) => { return { owner: { data: { shopid: bodyshopid, ...job.owner.data, }, }, vehicle: { data: { shopid: bodyshopid, ...job.vehicle.data, }, }, shopid: bodyshopid, ...job, }; }; describe( "Importing an available job", { defaultCommandTimeout: 10000, requestTimeout: 10000, }, () => { // assuming that user is logged in beforeEach(() => { cy.visit("/manage/available"); // intercept bodyshop query for id cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_BODYSHOP") { req.alias = "bodyshop"; } }); cy.wait("@bodyshop").then(({ response }) => { const id = response.body.data.bodyshops[0].id; cy.wrap(id).as("bodyshopid"); }); }); it("Enters a job programatically", () => { cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } }); cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; cy.get("@bodyshopid").then((bodyshopid) => { const job_est_data = createJobEstimate(job, bodyshopid); cy.insertAvailableJob({ bodyshopid, job, token, job_est_data, }); }); }); }); it("creates a new owner record for the job", () => { cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } }); cy.wait("@availableJobs"); cy.get('[data-cy="available-jobs-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .contains(job.clm_no) .parent() .as("row"); cy.get("@row") .find('[data-cy="add-job-as-new-button"]') .should("be.enabled") .click(); cy.get('[data-cy="new_owner_checkbox"]').should("be.checked"); cy.get('[data-cy="existing-owners-ok-button"]') .should("be.enabled") .click(); cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "INSERT_JOB") { req.alias = "insertJob"; } }); cy.wait("@insertJob").then(({ response }) => { const id = response.body.data.insert_jobs.returning[0].id; cy.get(".ant-notification-notice-message") .contains("Job created successfully. Click to view.") .click(); cy.url().should("include", `/manage/jobs/${id}`); }); cy.get('[data-cy="tab-totals"]').should("be.visible").click(); cy.get('[data-cy="job-totals-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("totals-table") .should("not.have.class", "ant-table-placeholder"); cy.get("@totals-table") .eq(0) .find("td:not(.ant-table-selection-column)") .eq(1) .invoke("text") .should( "be.equal", Dinero({ amount: jobMetadata.totals.subtotal.amount, }).toFormat() ); }); it("imports a supplement for an existing job", () => { cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } }); cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; cy.get("@bodyshopid").then((bodyshopid) => { const job_est_data = createJobEstimate(jobSupplement, bodyshopid); cy.insertAvailableJob({ bodyshopid, job: jobSupplement, token, job_est_data, }); }); }); cy.get('[data-cy="refetch-available-jobs-button"]') .should("not.be.disabled") .click(); cy.get('[data-cy="available-jobs-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .contains(jobSupplement.clm_no) .parent() .as("row"); cy.get('[data-cy="add-job-as-supplement"]').should("be.enabled").click(); cy.get('[data-cy="existing-jobs-table"]') .find(".ant-table-tbody tr") .should("not.have.class", "ant-table-placeholder") .first() .click(); cy.get('[data-cy="existing-jobs-ok-button"]') .should("not.be", "disabled") .click(); cy.get(".ant-notification-notice-message") .contains("Job supplemented successfully.") .click(); cy.url().should("include", "/manage/jobs"); cy.get('[data-cy="tab-totals"]').should("be.visible").click(); cy.get('[data-cy="job-totals-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("totals-table") .should("not.have.class", "ant-table-placeholder"); cy.get("@totals-table") .eq(0) .find("td:not(.ant-table-selection-column)") .eq(1) .invoke("text") .should( "be.equal", Dinero({ amount: jobSupplementMetadata.totals.subtotal.amount, }).toFormat() ); }); it("imports a supplement and override estimate header", () => { cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } }); cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; cy.get("@bodyshopid").then((bodyshopid) => { const job_est_data = createJobEstimate(jobSupplement, bodyshopid); cy.insertAvailableJob({ bodyshopid, job: jobSupplement, token, job_est_data, }); }); }); cy.get('[data-cy="refetch-available-jobs-button"]') .should("not.be.disabled") .click(); cy.get('[data-cy="available-jobs-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .contains(jobSupplement.clm_no) .parent() .as("row"); cy.get('[data-cy="add-job-as-supplement"]').should("be.enabled").click(); cy.get('[data-cy="existing-jobs-table"]') .find(".ant-table-tbody tr") .should("not.have.class", "ant-table-placeholder") .first() .click(); // click override cy.get('[data-cy="override-header-checkbox"]').check(); cy.get('[data-cy="existing-jobs-ok-button"]') .should("not.be", "disabled") .click(); cy.get(".ant-notification-notice-message") .contains("Job supplemented successfully.") .click(); cy.url().should("include", "/manage/jobs"); cy.get('[data-cy="tab-totals"]').should("be.visible").click(); cy.get('[data-cy="job-totals-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("totals-table") .should("not.have.class", "ant-table-placeholder"); cy.get("@totals-table") .eq(0) .find("td:not(.ant-table-selection-column)") .eq(1) .invoke("text") .should( "be.equal", Dinero({ amount: jobSupplementMetadata.totals.subtotal.amount, }).toFormat() ); }); it("imports a job with an existing owner", () => { cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } }); cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; cy.get("@bodyshopid").then((bodyshopid) => { const job_est_data = createJobEstimate(job2, bodyshopid); cy.insertAvailableJob({ bodyshopid, job: job2, token, job_est_data, }); }); }); cy.get('[data-cy="refetch-available-jobs-button"]') .should("not.be.disabled") .click(); cy.get('[data-cy="add-job-as-new-button"]').should("be.enabled").click(); cy.get('[data-cy="existing-owner-table"]', { timeout: 20000 }) .find(".ant-table-tbody tr") .should("not.have.class", "ant-table-placeholder") .then(($table) => { cy.wrap($table).first().click(); cy.get('[data-cy="new_owner_checkbox"]').should("not.be", "checked"); }); cy.get('[data-cy="existing-owners-ok-button"]').click(); cy.get(".ant-notification-notice-message").contains( "Job created successfully. Click to view." ); cy.visit("/manage/owners"); // Navigate to owner records cy.get('[data-cy="owners-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("owners-table") .should("not.have.class", "ant-table-placeholder"); // Get owner name cy.get("@owners-table") .contains(`${job2.owner.data.ownr_fn} ${job2.owner.data.ownr_ln}`) .click(); // check list if claim number is there cy.get('[data-cy="owner-jobs-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("owner-jobs-table") .should("not.have.class", "ant-table-placeholder"); // Get owner name cy.get("@owner-jobs-table").contains(job2.clm_no).should("exist"); }); } ); const errorMessages = { class: "Class is required. ", referral_source: "Referral Source is required. ", employee_csr: "Customer Service Rep. is required. ", category: "Category is required. ", }; describe( "Converting an active job", { defaultCommandTimeout: 10000, }, () => { beforeEach(() => { cy.visit("/manage/jobs"); cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_BODYSHOP") { req.alias = "bodyshop"; } }); cy.get('[data-cy="active-jobs-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") .as("active-jobs-table") .should("not.have.class", "ant-table-placeholder"); cy.get("@active-jobs-table") .contains(job.clm_no) .first() .parent() .find('[data-cy="active-job-link"]') .click(); cy.get('[data-cy="job-convert-button"]').click(); }); it("shows the error messages of required fields", () => { cy.wait("@bodyshop").then(({ response }) => { const bodyshop = response.body.data.bodyshops[0]; const data = { ins_cos: bodyshop.md_ins_cos, config: { class: bodyshop.enforce_class, referral_source: bodyshop.enforce_referral, employee_csr: bodyshop.enforce_conversion_csr, category: bodyshop.enforce_conversion_category, }, }; cy.get('[data-cy="convert-button"]').click(); cy.get("#ins_co_nm_help") .find(".ant-form-item-explain-error") .should("have.text", "Insurance Company Name is required. "); for (const id in data.config) { if (data.config[id]) { cy.get(`#${id}_help`) .find(".ant-form-item-explain-error") .should("have.text", errorMessages[id]); } } }); }); it("shows error of required fields when insurance company is selected", () => { cy.wait("@bodyshop").then(({ response }) => { const bodyshop = response.body.data.bodyshops[0]; const data = { ins_cos: bodyshop.md_ins_cos, config: { class: bodyshop.enforce_class, referral_source: bodyshop.enforce_referral, employee_csr: bodyshop.enforce_conversion_csr, category: bodyshop.enforce_conversion_category, }, }; cy.get(".ant-select-selection-search").find("#ins_co_nm").click(); cy.get("#ins_co_nm_list") .next() .find(".ant-select-item-option-content") .first() .click(); 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(); for (const id in data.config) { if (data.config[id]) { cy.get(`#${id}_help`) .find(".ant-form-item-explain-error") .should("have.text", errorMessages[id]); } } }); }); it("checks for the job to convert", () => { cy.wait("@bodyshop").then(({ response }) => { const bodyshop = response.body.data.bodyshops[0]; const data = { ins_cos: bodyshop.md_ins_cos, config: { class: bodyshop.enforce_class, referral_source: bodyshop.enforce_referral, employee_csr: bodyshop.enforce_conversion_csr, category: bodyshop.enforce_conversion_category, }, }; cy.get(".ant-select-selection-search").find("#ins_co_nm").click(); cy.get("#ins_co_nm_list") .next() .find(".ant-select-item-option-content") .first() .click(); for (const id in data.config) { if (data.config[id]) { cy.get(".ant-select-selection-search").find(`#${id}`).click(); cy.get(`#${id}_list`) .next() .find(".ant-select-item-option-content") .first() .click(); } } 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( "Job converted successfully." ); }); }); } );