IO-2327 timetickets test cases

This commit is contained in:
swtmply
2023-08-25 11:56:24 +08:00
parent c4a961fc03
commit 623b27dbab
4 changed files with 116 additions and 25 deletions

View File

@@ -1,4 +1,3 @@
import random from "lodash/random";
import moment from "moment";
import job2 from "../../fixtures/jobs/job-4.json";
@@ -15,19 +14,18 @@ describe(
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.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()
@@ -55,7 +53,6 @@ describe(
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");
@@ -86,7 +83,7 @@ describe(
});
});
it("adds new time ticket to a job", () => {
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"]')
@@ -112,31 +109,27 @@ describe(
.invoke("text")
.as("bodyDiff")
.then((diff) => {
const hours = random(diff);
const actualHrs = random(hours);
cy.get('[data-cy="form-timeticket-productivehrs"]').type(1);
cy.get('[data-cy="form-timeticket-productivehrs"]').type(
hours.toFixed(1)
);
cy.get('[data-cy="form-timeticket-actualhrs"]').type(
actualHrs.toFixed(1)
);
cy.get('[data-cy="form-timeticket-actualhrs"]').type(1);
});
cy.antdSelect("timeticket-employee");
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();
// 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", () => {
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"]')
@@ -144,7 +137,85 @@ describe(
.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", () => {

View File

@@ -74,6 +74,22 @@ Cypress.Commands.add("antdSelect", (selector, filter) => {
});
});
Cypress.Commands.add("antdSelectValue", (selector, filter) => {
cy.get(`.ant-select-${selector} > .ant-select-selector`).click();
cy.get(`.ant-select-${selector} .ant-select-selection-search input`)
.invoke("attr", "id")
.then((selElm) => {
const dropDownSelector = `#${selElm}_list`;
cy.get(dropDownSelector)
.next()
.find(".ant-select-item-option-content")
.contains(filter)
.first()
.click({ force: true });
});
});
Cypress.Commands.add(
"insertAvailableJob",
({ bodyshopid, job, job_est_data, token }) => {

View File

@@ -23,6 +23,7 @@ export default function JobCostingPartsTable({ data, summaryData }) {
sorter: (a, b) => alphaSort(a.cost_center, b.cost_center),
sortOrder:
state.sortedInfo.columnKey === "cost_center" && state.sortedInfo.order,
render: (record) => <span data-cy="responsibilitycenter">{record}</span>,
},
{
title: t("jobs.labels.sales"),
@@ -42,6 +43,7 @@ export default function JobCostingPartsTable({ data, summaryData }) {
parseFloat(a.costs.substring(1)) - parseFloat(b.costs.substring(1)),
sortOrder:
state.sortedInfo.columnKey === "costs" && state.sortedInfo.order,
render: (record) => <span data-cy="cost">{record}</span>,
},
{

View File

@@ -226,7 +226,9 @@ export function LaborAllocationsTable({
{summary.hrs_total.toFixed(1)}
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.hrs_claimed.toFixed(1)}
<span data-cy="labor-total-hrs-claimed">
{summary.hrs_claimed.toFixed(1)}
</span>
</Table.Summary.Cell>
<Table.Summary.Cell>
{summary.adjustments.toFixed(1)}