155 lines
4.5 KiB
JavaScript
155 lines
4.5 KiB
JavaScript
import random from "lodash/random";
|
|
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");
|
|
|
|
// TODO add bodyshop query to get the employees data for labor
|
|
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(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 });
|
|
|
|
// TODO select employee from the bodyshop
|
|
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", () => {
|
|
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) => {
|
|
const hours = random(diff);
|
|
const actualHrs = random(hours);
|
|
|
|
cy.get('[data-cy="form-timeticket-productivehrs"]').type(
|
|
hours.toFixed(1)
|
|
);
|
|
|
|
cy.get('[data-cy="form-timeticket-actualhrs"]').type(
|
|
actualHrs.toFixed(1)
|
|
);
|
|
});
|
|
|
|
cy.antdSelect("timeticket-employee");
|
|
|
|
cy.antdSelect("cost-center");
|
|
|
|
cy.get('[data-cy="form-timeticket-memo"]').type(uuid());
|
|
|
|
cy.get('[data-cy="timeticket-save-button"]').first().click();
|
|
|
|
// TODO check if hours are calculated to the allocations table
|
|
// cy.get('[data-cy="tab-labor"]').should("be.visible").click();
|
|
});
|
|
|
|
it("checks the job costing calculations", () => {
|
|
cy.get('[data-cy="job-actions-button"]').click();
|
|
|
|
cy.get('[data-cy="actions-timetickets"]')
|
|
.should("be.visible")
|
|
.and("not.be.disabled")
|
|
.click();
|
|
|
|
// TODO check if labors are calculated correctly
|
|
});
|
|
|
|
it("clocks in and out of the tech page for the timeticket", () => {
|
|
// TODO go to tech page for the clock in and out
|
|
});
|
|
}
|
|
);
|