Skip to content

Commit

Permalink
Update basket test
Browse files Browse the repository at this point in the history
  • Loading branch information
richpjames authored and richpjames committed Aug 5, 2024
1 parent 3f60bea commit 381e997
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions cypress/integration/pages/basket.spec.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,95 @@
const sku = "price_1Of9a3Js9ciiqN7OIoARpxNk";
const sku = "price_1JrA8nJs9ciiqN7ONSoey4is";
const siblingsPrice = 12;
const defaultShippingPrice = 2.5;

describe("Basket", () => {
beforeEach(() =>
cy
.fixture("initialisedState")
.then((initialisedState) => cy.visit("/basket"))
cy.visit("/basket", {
onBeforeLoad: (win) => {
win.localStorage.setItem(
"basket",
JSON.stringify([["price_1Of9a3Js9ciiqN7OIoARpxNk", 1]])
);
},
})
);

it("shows empty basket message", () => {
cy.visit("/basket", {
onBeforeLoad: (win) => {
win.localStorage.setItem("basket", JSON.stringify([]));
},
});
cy.get("#empty-basket-message");
});

it("correct items are shown in basket", () => {
cy.window().its("ctx").invoke("add", "sku");
cy.get("#anthology-title")
.contains("Various")
.get("#anthology-subtitle")
.contains("Murmur Anthology #1")
.get("#anthology-quantity-panel")
.get("#anthology-price")
.contains("£10")
cy.get("#siblings-basket-item")
.contains("Jay Bernard, Mary Jean Chan, Will Harris, Nisha Ramayya")
.get("#siblings-subtitle")
.contains("Siblings")
.get("#siblings-quantity-panel")
.get("#siblings-price")
.contains(${siblingsPrice}`)
.contains("1")
.percySnapshot();
});

it("increasing quantity of a book increases the price accordingly", () => {
cy.window().its("ctx").invoke("add", "sku");
cy.get("#basket-total")
.contains("£12")
.get("#anthology-increase-quantity-button")
.contains(${siblingsPrice + defaultShippingPrice}`)
.get("#siblings-increase-quantity-button")
.click()
.get("#basket-total")
.contains("£22")
.contains(${siblingsPrice * 2 + defaultShippingPrice}`)
.percySnapshot();
});

it("decreasing quantity of a book increases the price accordingly", () => {
cy.window().its("ctx").invoke("add", "sku");
cy.get("#basket-total")
.contains("£12")
.get("#anthology-decrease-quantity-button")
.contains(${siblingsPrice + defaultShippingPrice}`)
.get("#siblings-decrease-quantity-button")
.click()
.get("#basket-total")
.contains("£2.50")
.contains(${defaultShippingPrice}`)
.percySnapshot();
});

it("test that when quantity is 0 decreasing is disabled and quantity is 0", () => {
cy.window().its("ctx").invoke("add", "sku");
cy.get("#basket-total")
.contains("£12")
.get("#anthology-decrease-quantity-button")
.contains(${siblingsPrice + defaultShippingPrice}`)
.get("#siblings-decrease-quantity-button")
.click()
.get("#basket-total")
.contains("£2.50")
.get("#anthology-quantity")
.contains(${defaultShippingPrice}`)
.get("#siblings-quantity")
.eq("0")
.get("#anthology-decrease-quantity-button")
.get("#siblings-decrease-quantity-button")
.should("be.disabled");
});

it("changes to the postal region are show in the shipping price and basket total", () => {
cy.window().its("ctx").invoke("add", "sku");
const europeanShippingPrice = 4.5;
const restOfTheWorldShippingPrice = 6.5;

cy.get("#shipping-selector")
.select("Europe")
.get("#shipping-cost")
.contains("£4")
.contains(${europeanShippingPrice}0`)
.get("#basket-total")
.contains("£14")
.contains(${siblingsPrice + europeanShippingPrice}`)
.get("#shipping-selector")
.select("Rest Of The World")
.get("#shipping-cost")
.contains("£5")
.contains(${restOfTheWorldShippingPrice}0`)
.get("#basket-total")
.contains("£15")
.contains(${siblingsPrice + restOfTheWorldShippingPrice}`)
.get("#shipping-selector")
.select("UK")
.get("#shipping-cost")
.contains("£2.50")
.contains(${defaultShippingPrice}0`)
.get("#basket-total")
.contains("£12.50")
.contains(${siblingsPrice + defaultShippingPrice}`)
.percySnapshot();
});
});

0 comments on commit 381e997

Please sign in to comment.