Files
bodyshop/client/cypress/e2e/intake/intake-checklist.cy.js
2023-08-02 11:56:03 +08:00

233 lines
8.0 KiB
JavaScript

import moment from "moment";
import job from "../../fixtures/jobs/job-3.json";
describe(
"Adding job to checklist",
{
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();
});
it("adds checklists to the job and set the job to production", () => {
const tomorrow = moment(new Date()).format("YYYY-MM-DD");
cy.get('[data-cy="job-actions-button"]').click();
// Go to intake
cy.get('[data-cy="job-intake-button"]').should("not.be.disabled").click();
cy.url().should("include", "/intake");
// Fill out the form
cy.get('[data-cy="checklist-form"]').should("be.visible");
cy.wait("@bodyshop").then(({ response }) => {
const bodyshop = response.body.data.bodyshops[0];
// intakechecklist
const checklists = bodyshop.intakechecklist.form;
checklists.forEach((item, index) => {
if (item.type === "text") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:text")
.type("Random Word");
} else if (item.type === "textarea") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("textarea")
.type("Random Word");
} else if (item.type === "checkbox") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:checkbox")
.check();
} else if (item.type === "slider") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-slider-dot:eq(1)")
.click({ force: true });
} else if (item.type === "rate") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-rate > li")
.eq(3)
.find("div[role='radio']")
.click({ force: true });
}
});
});
// Check if `Add Job to Production` is switched to on
cy.get('[data-cy="add-to-production-switch"]').should(
"have.attr",
"aria-checked",
"true"
);
// Select dates for completion and delivery
cy.get("#scheduled_completion").find(".ant-picker-input").first().click();
cy.get(`[title="${tomorrow}"]`).should("be.visible").click();
// Add time selection
cy.get("#scheduled_delivery").find(".ant-picker-input").first().click();
cy.get(`[title="${tomorrow}"]`)
.should("be.visible")
.click({ multiple: true, force: true });
// Add time selection
// Add note
cy.get('[data-cy="checklist-production-note"]').type("automated testing");
// Submit the form
cy.get('[data-cy="checklist-submit-button"]').click();
cy.url().should("include", "/manage/jobs");
cy.contains("In Production");
});
it("adds checklists to the job and remove the job to production", () => {
const tomorrow = moment(new Date()).format("YYYY-MM-DD");
cy.get('[data-cy="job-actions-button"]').click();
// Go to deliver
cy.get('[data-cy="job-deliver"]').should("not.be.disabled").click();
cy.url().should("include", "/deliver");
// Fill out the form
cy.get('[data-cy="checklist-form"]').should("be.visible");
cy.wait("@bodyshop").then(({ response }) => {
const bodyshop = response.body.data.bodyshops[0];
// deliverchecklist
const checklists = bodyshop.deliverchecklist.form;
checklists.forEach((item, index) => {
if (item.type === "text") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:text")
.type("Random Word");
} else if (item.type === "textarea") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("textarea")
.type("Random Word");
} else if (item.type === "checkbox") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:checkbox")
.check();
} else if (item.type === "slider") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-slider-dot:eq(1)")
.click({ force: true });
} else if (item.type === "rate") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-rate > li")
.eq(3)
.find("div[role='radio']")
.click({ force: true });
}
});
});
// Select dates for completion and delivery
cy.get("#actual_completion").find(".ant-picker-input").first().click();
cy.get(`[title="${tomorrow}"]`).should("be.visible").click();
cy.get("#actual_delivery").find(".ant-picker-input").first().click();
cy.get(`[title="${tomorrow}"]`)
.should("be.visible")
.click({ multiple: true, force: true });
cy.get('[data-cy="remove-from-production"]').should(
"have.attr",
"aria-checked",
"true"
);
// Submit the form
cy.get('[data-cy="checklist-submit-button"]').click();
// Job checklist completed.
cy.url().should("include", "/manage/jobs");
cy.contains("Delivered");
});
it("renders and check the checklists correctly", () => {
// Click the actions button
cy.get('[data-cy="job-actions-button"]').click();
// Go to checklists
cy.get('[data-cy="job-checklist"]').should("not.be.disabled").click();
cy.wait("@bodyshop").then(({ response }) => {
const bodyshop = response.body.data.bodyshops[0];
// intakechecklist
const intakechecklist = bodyshop.intakechecklist.form;
// deliverchecklist
const deliverchecklist = bodyshop.deliverchecklist.form;
const checklists = [...intakechecklist, ...deliverchecklist];
cy.get('[data-cy="intake-checklist"]')
.should("be.visible")
.find("input")
.should("be.disabled");
cy.get('[data-cy="deliver-checklist"]')
.should("be.visible")
.find("input")
.should("be.disabled");
checklists.forEach((item, index) => {
if (item.type === "text") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:text")
.should("have.value", "Random Word");
} else if (item.type === "textarea") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("textarea")
.should("have.value", "Random Word");
} else if (item.type === "checkbox") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find("input:checkbox")
.should("be.checked");
} else if (item.type === "slider") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-slider-handle")
.should("have.attr", "aria-valuenow", item.max / 2);
} else if (item.type === "rate") {
cy.get('[data-cy="config-form-components"] > div')
.eq(index)
.find(".ant-rate > .ant-rate-star-full")
.should("have.length", 3);
}
});
});
});
}
);