diff --git a/client/cypress/e2e/posting-bills/posting-bills.cy.js b/client/cypress/e2e/posting-bills/posting-bills.cy.js index d1bab7997..2cea4a214 100644 --- a/client/cypress/e2e/posting-bills/posting-bills.cy.js +++ b/client/cypress/e2e/posting-bills/posting-bills.cy.js @@ -367,7 +367,7 @@ describe.only( }); }); - it("returning item and validating statistics", () => { + it.only("returning item and validating statistics", () => { cy.get('[data-cy="bills-table"]') .find(".ant-table-tbody") .find("> tr:not(.ant-table-measure-row)") @@ -375,8 +375,14 @@ describe.only( .should("not.have.class", "ant-table-placeholder"); cy.get("@bills-table") + .find('[data-cy="credit-memo-checkbox"]') + .filter(":not(:checked)") .first() .should("not.be.disabled") + .parent() + .parent() + .parent() + .parent() .find('[data-cy="return-items-button"]') .click(); @@ -384,20 +390,26 @@ describe.only( cy.get('[data-cy="billline-return-items-ok-button"]').click(); cy.get('[data-cy="billline-actual-price"]') .find(".ant-form-item-control-input-content") - .invoke("text") - .then((value) => { - cy.get("#order-quantity").type("1", { force: true, multiple: true }); - cy.get('[data-cy="part-order-select-none"]').click({ - multiple: true, - force: true, + .then((prices) => { + const totals = prices + .toArray() + .map((el) => Number(el.innerText.substring(1))); + const sum = Cypress._.sum(totals); + + const price = Dinero({ + amount: sum * 100, + }).toFormat(); + + cy.get('[data-cy="order-quantity"]').each((input) => { + cy.wrap(input).type("1"); }); - cy.get('[data-cy="order-part-submit"]').click({ - multiple: true, - force: true, - }); - cy.get("#totalReturns").should("have.text", value); - cy.get("#calculatedcreditsnotreceived").should("have.text", value); - cy.get("#creditsnotreceived").should("have.text", value); + cy.get('[data-cy="part-order-select-none"]').click(); + + cy.get('[data-cy="order-part-submit"]').click(); + + cy.get("#totalReturns").should("have.text", price); + cy.get("#calculatedcreditsnotreceived").should("have.text", price); + cy.get("#creditsnotreceived").should("have.text", price); }); }); @@ -437,36 +449,57 @@ describe.only( }); cy.get('[data-cy="bill-line-actual-cost"]').then((cells) => { - const totals = cells.toArray().map((el) => Number(el.value)); - const sum = Cypress._.sum(totals); - - cy.get('[data-cy="bill-form-bill-total"]').type(sum); - - // Get taxes add it to the sum - cy.get('[data-cy="bill-form-tax"]').then((taxes) => { - const subtotals = taxes + cy.get('[data-cy="bill-line-actual-price"]').then((priceCells) => { + const totals = cells.toArray().map((el) => Number(el.value)); + const priceTotals = priceCells .toArray() - .map((el) => Number(el.innerText.substring(1))); - const totalTax = Cypress._.sum(subtotals); + .map((el) => Number(el.value)); + const sum = Cypress._.sum(totals); + const priceSum = Cypress._.sum(priceTotals); - const billAmount = sum + totalTax; + cy.get('[data-cy="bill-form-bill-total"]').type(sum); - cy.get('[data-cy="bill-form-bill-total"]') - .find("input") - .clear() - .type(billAmount); + // Get taxes add it to the sum + cy.get('[data-cy="bill-form-tax"]').then((taxes) => { + const subtotals = taxes + .toArray() + .map((el) => Number(el.innerText.substring(1))); + const totalTax = Cypress._.sum(subtotals); + + const billAmount = sum + totalTax; + + cy.get('[data-cy="bill-form-bill-total"]') + .find("input") + .clear() + .type(billAmount); + }); + + cy.get("#bill-form-discrepancy").should("have.text", "$0.00"); + + cy.get('[data-cy="bill-form-save-button"]').click(); + + cy.get("#totalReturns") + .invoke("text") + .then((value) => { + // TODO check if negative transform to 0 + const totalReturns = + Number(value.substring(1)) - priceSum < 0 + ? 0 + : Number(value.substring(1)) - priceSum; + + cy.get("#calculatedcreditsnotreceived").should( + "have.text", + Dinero({ + amount: totalReturns, + precision: 0, + }).toFormat() + ); + }); }); }); - - cy.get("#bill-form-discrepancy").should("have.text", "$0.00"); - - cy.get('[data-cy="bill-form-save-button"]').click(); - - // TODO add other totals to assert the posted CNR - cy.get("#calculatedcreditsnotreceived").should("have.text", "$0.00"); }); - it.only("receives credit memo with return part", () => { + it("receives credit memo with return part", () => { // Find the first row in the parts order cy.get('[data-cy="part-orders-table"]') .find(".ant-table-tbody")