Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative totals calculation in cart for USA locale display in format n,nnn.nn #42

Open
ProxiBlue opened this issue Mar 7, 2022 · 0 comments

Comments

@ProxiBlue
Copy link

Is your feature request related to a problem? Please describe.
Defined in cart.spec.js test 'displays the correct product prices and totals' the totals calculations seem off, or likely don;t cater for USA locale price display format of x,xxx.xx

The tests as is always fail not being able to compare price values/totals are correct, and it seems it only uses the thousands as a single int. In example below '2' from a total of 2,254.97 is definitely not equal to 48 (2 + 46) of the line items totals

image

Describe the solution you'd like
I have created an alternative test block, that properly works out the totals, as is, not just the first digits of the toatls, as what seems to be happening.
I did not do a MR, as I am unsure if these will work for other locales, and shouls likely just be in some form of docs for others to be able to use, and tweak to their needs. No need for others to work this out as well. Also, i am not a JS expert, so my code could likely be refined.

    it.only('displays the correct product prices and totals', () => {
        cy.visit(cart.url.product1Url)

        //check if product price matches with price in cart
        cy.get(cart.product.productPrice).then(($productPrice) => {
            const productPrice = Number($productPrice[0].textContent.replace(/[^0-9\.-]+/g, ""))
            Cart.addProductToCart(cart.url.product2Url)
            cy.visit(cart.url.cartUrl)
            cy.wait(3000)
            cy.get(cart.product1Price).then((itemPrice) => {
                let cartItemPrice = Number(itemPrice.text().replace(/[^0-9\.-]+/g, ""));
                cy.log(cartItemPrice)
                expect(productPrice).to.eq(cartItemPrice)
            })

            //change the qty value
            cy.get(cart.qtyInputField).eq(0).type('{backspace}2{enter}').then(($qty) => {
                const qty = parseInt($qty.val())
                cy.wait(3000)
                //check if qty * product subtotal displays the correct amount
                cy.get(cart.product1Subtotal).then(($subTotal) => {
                    const subTotal = Number($subTotal[0].textContent.replace(/[^0-9\.-]+/g, ""))
                    expect(productPrice * qty).to.equal(subTotal)

                })
            })
        })

        //check if the grand total is correct
        cy.get(cart.product1Subtotal).then(($total1) => {
            const subTotal1 = Number($total1[0].textContent.replace(/[^0-9\.-]+/g, "")).toFixed(2)
            cy.log(subTotal1)
            cy.get(cart.product2Subtotal).then(($total2) => {
                const subTotal2 = Number($total2[0].textContent.replace(/[^0-9\.-]+/g, "")).toFixed(2)
                cy.log(subTotal2)
                const calcTotal = Number(subTotal1) + Number(subTotal2)
                cy.log(calcTotal)
                cy.get(cart.grandTotal).then(($grandTotal) => {
                    const grandTotal = Number($grandTotal[0].textContent.replace(/[^0-9\.-]+/g, "")).toFixed(2)
                    cy.log(grandTotal)
                    expect(grandTotal).to.equal(calcTotal.toFixed(2))
                })
            })
        })
    })

image

Describe alternatives you've considered
See above

Additional context
None, see above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants