Files
bodyshop/client/cypress/e2e/time-tickets/time-tickets.cy.js
2023-08-25 11:56:24 +08:00

226 lines
6.8 KiB
JavaScript

import moment from "moment";
import job2 from "../../fixtures/jobs/job-4.json";
const uuid = () => Cypress._.random(0, 1e6);
describe(
"Entering payment for the job",
{
defaultCommandTimeout: 5000,
},
() => {
const today = moment().format("YYYY-MM-DD");
beforeEach(() => {
cy.visit("/manage");
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.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => {
if (req.body.operationName === "QUERY_ACTIVE_EMPLOYEES") {
req.alias = "employees";
}
});
cy.get("@active-jobs-table")
.contains(job2.clm_no)
.first()
.parent()
.find('[data-cy="active-job-link"]')
.click();
cy.url().should("include", "/manage/jobs");
});
it("checks input validations", () => {
cy.get('[data-cy="job-actions-button"]').click();
cy.get('[data-cy="actions-timetickets"]')
.should("be.visible")
.and("not.be.disabled")
.click();
cy.get('[data-cy="timeticket-save-button"]').first().click();
cy.get('[data-cy="form-timeticket"]')
.find(".ant-form-item-explain-error")
.should("have.length", 4);
cy.get('[data-cy="form-timeticket-date"]').click();
cy.get(`[title="${today}"]`).should("be.visible").click({ force: true });
cy.antdSelect("timeticket-employee");
cy.antdSelect("cost-center");
cy.get('[data-cy="labor-allocations-table"]')
.find(".ant-table-tbody")
.find("> tr:not(.ant-table-measure-row)")
.as("labor-allocations")
.should("not.have.class", "ant-table-placeholder");
cy.get("@labor-allocations")
.eq(0)
.find("td:not(.ant-table-selection-column)")
.eq(4)
.find("strong")
.invoke("text")
.as("bodyDiff")
.then((diff) => {
// TODO dynamically select the employee prior to what is the labor and cost
cy.get('[data-cy="form-timeticket-productivehrs"]').type(
Number(diff) + 1
);
cy.get(".ant-form-item-explain-error").should(
"have.text",
"The number of hours entered is more than what is available for this cost center."
);
});
});
it("adds new time ticket to a job with flat rate", () => {
cy.get('[data-cy="job-actions-button"]').click();
cy.get('[data-cy="actions-timetickets"]')
.should("be.visible")
.and("not.be.disabled")
.click();
cy.get('[data-cy="labor-allocations-table"]')
.find(".ant-table-tbody")
.find("> tr:not(.ant-table-measure-row)")
.as("labor-allocations")
.should("not.have.class", "ant-table-placeholder");
// Get Difference for Body
cy.get('[data-cy="form-timeticket-date"]').click();
cy.get(`[title="${today}"]`).should("be.visible").click();
cy.get("@labor-allocations")
.eq(0)
.find("td:not(.ant-table-selection-column)")
.eq(4)
.find("strong")
.invoke("text")
.as("bodyDiff")
.then((diff) => {
cy.get('[data-cy="form-timeticket-productivehrs"]').type(1);
cy.get('[data-cy="form-timeticket-actualhrs"]').type(1);
});
cy.wait("@employees").then(({ response }) => {
const employees = response.body.data.employees;
const employee = employees[0];
const employee_name = `${employee.first_name} ${employee.last_name}`;
cy.antdSelectValue("timeticket-employee", employee_name);
});
cy.antdSelect("cost-center");
cy.get('[data-cy="form-timeticket-memo"]').type(uuid());
cy.get('[data-cy="timeticket-save-button"]').first().click();
});
it("adds new time ticket to a job with straight rate", () => {
cy.get('[data-cy="job-actions-button"]').click();
cy.get('[data-cy="actions-timetickets"]')
.should("be.visible")
.and("not.be.disabled")
.click();
cy.get('[data-cy="labor-allocations-table"]')
.find(".ant-table-tbody")
.find("> tr:not(.ant-table-measure-row)")
.as("labor-allocations")
.should("not.have.class", "ant-table-placeholder");
// Get Difference for Body
cy.get('[data-cy="form-timeticket-date"]').click();
cy.get(`[title="${today}"]`).should("be.visible").click();
cy.get("@labor-allocations")
.eq(0)
.find("td:not(.ant-table-selection-column)")
.eq(4)
.find("strong")
.invoke("text")
.as("bodyDiff")
.then((diff) => {
cy.get('[data-cy="form-timeticket-productivehrs"]').type(1);
cy.get('[data-cy="form-timeticket-actualhrs"]').type(1);
});
cy.wait("@employees").then(({ response }) => {
const employees = response.body.data.employees;
const employee = employees[1];
const employee_name = `${employee.first_name} ${employee.last_name}`;
cy.antdSelectValue("timeticket-employee", employee_name);
});
cy.antdSelect("cost-center");
cy.get('[data-cy="form-timeticket-memo"]').type(uuid());
cy.get('[data-cy="timeticket-save-button"]').first().click();
});
it("checks hours calculated to the allocations table", () => {
cy.get('[data-cy="tab-labor"]').should("be.visible").click();
cy.get('[data-cy="labor-allocations-table"]')
.find(".ant-table-tbody")
.find("> tr:not(.ant-table-measure-row)")
.as("labor-allocations")
.should("not.have.class", "ant-table-placeholder");
cy.get('[data-cy="labor-total-hrs-claimed"]')
.invoke("text")
.then((hours) => {
cy.wrap(hours).should("not.equal", "0");
});
});
it.only("checks the job costing calculations", () => {
cy.get('[data-cy="job-actions-button"]').click();
cy.get('[data-cy="actions-jobcosting"]')
.should("be.visible")
.and("not.be.disabled")
.click();
// TODO check if labors are calculated correctly
cy.wait("@employees").then(({ response }) => {
const employees = response.body.data.employees;
const employee_body_rates = employees.map((emp) => {
return emp.rates.filter((rate) => rate.cost_center === "Body")[0]
.rate;
});
cy.log(employee_body_rates);
cy.get('[data-cy="responsibilitycenter"]')
.contains("Body")
.parent()
.parent()
.find('[data-cy="cost"]');
});
});
it("clocks in and out of the tech page for the timeticket", () => {
// TODO go to tech page for the clock in and out
});
}
);