357 lines
10 KiB
JavaScript
357 lines
10 KiB
JavaScript
import job from "../../downloads/jobs/job-3.json";
|
|
import job2 from "../../downloads/jobs/job-4.json";
|
|
import jobSupplement from "../../downloads/jobs/job-3-supplement.json";
|
|
import jobMetadata from "../../downloads/jobs/job-3-jobmetadata.json";
|
|
import jobSupplementMetadata from "../../downloads/jobs/job-3-supplment-jobmetadata.json";
|
|
import Dinero from "dinero.js";
|
|
|
|
const query = `mutation INSERT_AVAILABLE_JOB($job: available_jobs_insert_input!) {
|
|
insert_available_jobs_one(object: $job) {
|
|
id
|
|
}
|
|
}`;
|
|
|
|
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");
|
|
});
|
|
}
|
|
);
|