Skip to content

Commit c2e173a

Browse files
committed
test(e2e): add order tests
1 parent 6fea661 commit c2e173a

File tree

1 file changed

+374
-0
lines changed

1 file changed

+374
-0
lines changed
Lines changed: 374 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,374 @@
1+
import { test, expect } from "../../index"
2+
3+
test.describe("Account orders page tests", async () => {
4+
test.beforeEach(async ({ accountAddressesPage }) => {
5+
await accountAddressesPage.goto()
6+
await accountAddressesPage.newAddressButton.click()
7+
await test.step("Add default address", async () => {
8+
const modal = accountAddressesPage.addAddressModal
9+
await modal.container.waitFor({ state: "visible" })
10+
await modal.firstNameInput.fill("First")
11+
await modal.lastNameInput.fill("Last")
12+
await modal.companyInput.fill("FirstCorp")
13+
await modal.address1Input.fill("123 Fake Street")
14+
await modal.address2Input.fill("Apt 1")
15+
await modal.postalCodeInput.fill("11111")
16+
await modal.cityInput.fill("City")
17+
await modal.stateInput.fill("Colorado")
18+
await modal.countrySelect.selectOption({
19+
label: "United States",
20+
})
21+
await modal.phoneInput.fill("1112223333")
22+
await modal.saveButton.click()
23+
await modal.container.waitFor({ state: "hidden" })
24+
})
25+
})
26+
27+
test("Verify account orders page displays empty container", async ({
28+
accountOrdersPage,
29+
}) => {
30+
await accountOrdersPage.goto()
31+
await expect(accountOrdersPage.noOrdersContainer).toBeVisible()
32+
})
33+
34+
test("Order shows up after checkout flow", async ({
35+
accountOrdersPage,
36+
accountOrderPage,
37+
cartPage,
38+
checkoutPage,
39+
orderPage: publicOrderPage,
40+
productPage,
41+
storePage,
42+
}) => {
43+
await test.step("Navigate to a product page", async () => {
44+
await storePage.goto()
45+
const product = await storePage.getProduct("Sweatshirt")
46+
await product.locator.highlight()
47+
await product.locator.click()
48+
await productPage.container.waitFor({ state: "visible" })
49+
})
50+
51+
await test.step("Add the product to the cart and goto checkout", async () => {
52+
await productPage.selectOption("M")
53+
await productPage.clickAddProduct()
54+
await productPage.cartDropdown.navCartLink.click()
55+
await productPage.cartDropdown.goToCartButton.click()
56+
await cartPage.container.waitFor({ state: "visible" })
57+
await cartPage.checkoutButton.click()
58+
await checkoutPage.container.waitFor({ state: "visible" })
59+
})
60+
61+
await test.step("Enter in the first step of the checkout process", async () => {
62+
await checkoutPage.selectSavedAddress("123 Fake Street")
63+
await checkoutPage.shippingEmailInput.fill("[email protected]")
64+
await checkoutPage.shippingPhoneInput.fill("3031112222")
65+
await checkoutPage.submitAddressButton.click()
66+
await checkoutPage.deliveryOptionsContainer.waitFor({ state: "visible" })
67+
})
68+
69+
await test.step("Complete the rest of the payment process", async () => {
70+
await checkoutPage.selectDeliveryOption("FakeEx Standard")
71+
await checkoutPage.submitDeliveryOptionButton.click()
72+
await checkoutPage.submitPaymentButton.click()
73+
await checkoutPage.submitOrderButton.click()
74+
await publicOrderPage.container.waitFor({ state: "visible" })
75+
})
76+
77+
let orderId = ""
78+
await test.step("Verify the order page information is correct", async () => {
79+
orderId = (await publicOrderPage.orderId.textContent()) || ""
80+
81+
await test.step("Verify the products ordered are correct", async () => {
82+
const product = await publicOrderPage.getProduct("Sweatshirt", "M")
83+
await expect(product.name).toContainText("Sweatshirt")
84+
await expect(product.variant).toContainText("M")
85+
await expect(product.quantity).toContainText("1")
86+
})
87+
88+
await test.step("Verify the shipping info is correct", async () => {
89+
const address = publicOrderPage.shippingAddressSummary
90+
await expect(address).toContainText("First")
91+
await expect(address).toContainText("Last")
92+
await expect(address).toContainText("123 Fake Street")
93+
await expect(address).toContainText("11111")
94+
await expect(address).toContainText("City")
95+
await expect(address).toContainText("US")
96+
97+
const contact = publicOrderPage.shippingContactSummary
98+
await expect(contact).toContainText("[email protected]")
99+
await expect(contact).toContainText("3031112222")
100+
101+
const method = publicOrderPage.shippingMethodSummary
102+
await expect(method).toContainText("FakeEx Standard")
103+
})
104+
})
105+
106+
await test.step("Verify the account orders page displays a result", async () => {
107+
await accountOrdersPage.goto()
108+
const order = await accountOrdersPage.getOrderById(orderId)
109+
expect(order.items.length).toBe(1)
110+
expect(order.items[0].title).toContainText("Sweatshirt")
111+
expect(order.items[0].quantity).toHaveText("1")
112+
await order.detailsLink.click()
113+
await accountOrderPage.container.waitFor({ state: "visible" })
114+
})
115+
116+
await test.step("Verify the order page displays the correct information", async () => {
117+
await test.step("Verify the order id is correct", async () => {
118+
await expect(accountOrderPage.orderId).toHaveText(orderId)
119+
})
120+
121+
await test.step("Verify the products ordered are correct", async () => {
122+
const product = await accountOrderPage.getProduct("Sweatshirt", "M")
123+
await expect(product.name).toContainText("Sweatshirt")
124+
await expect(product.variant).toContainText("M")
125+
await expect(product.quantity).toContainText("1")
126+
})
127+
128+
await test.step("Verify the shipping info is correct", async () => {
129+
const address = accountOrderPage.shippingAddressSummary
130+
await expect(address).toContainText("First")
131+
await expect(address).toContainText("Last")
132+
await expect(address).toContainText("123 Fake Street")
133+
await expect(address).toContainText("11111")
134+
await expect(address).toContainText("City")
135+
await expect(address).toContainText("US")
136+
137+
const contact = accountOrderPage.shippingContactSummary
138+
await contact.highlight()
139+
await expect(contact.getByText("[email protected]")).toBeVisible()
140+
await expect(contact.getByText("3031112222")).toBeVisible()
141+
142+
const method = accountOrderPage.shippingMethodSummary
143+
await method.highlight()
144+
await expect(method).toContainText("FakeEx Standard")
145+
})
146+
})
147+
148+
await test.step("Navigate back to the orders page, verifying back button works", async () => {
149+
await accountOrderPage.backToOverviewButton.click()
150+
await accountOrdersPage.container.waitFor({ state: "visible" })
151+
})
152+
})
153+
154+
test("Order preserves item count, and variants", async ({
155+
accountOrdersPage,
156+
accountOrderPage,
157+
cartPage,
158+
checkoutPage,
159+
orderPage: publicOrderPage,
160+
productPage,
161+
storePage,
162+
}) => {
163+
await test.step("Add first batch or products to the cart", async () => {
164+
await test.step("Navigate to the sweatshirt product page", async () => {
165+
await storePage.goto()
166+
const product = await storePage.getProduct("Sweatshirt")
167+
await product.locator.highlight()
168+
await product.locator.click()
169+
await productPage.container.waitFor({ state: "visible" })
170+
})
171+
172+
await test.step("Add the product to the cart and goto checkout", async () => {
173+
await productPage.selectOption("M")
174+
await productPage.clickAddProduct()
175+
await productPage.cartDropdown.close()
176+
await productPage.selectOption("M")
177+
await productPage.clickAddProduct()
178+
await productPage.cartDropdown.close()
179+
})
180+
})
181+
182+
await test.step("Add second batch of products to the cart", async () => {
183+
await test.step("Navigate to the sweatshirt product page", async () => {
184+
await storePage.goto()
185+
const product = await storePage.getProduct("Sweatpants")
186+
await product.locator.highlight()
187+
await product.locator.click()
188+
await productPage.container.waitFor({ state: "visible" })
189+
})
190+
191+
await test.step("Add the product to the cart and goto checkout", async () => {
192+
await productPage.selectOption("S")
193+
await productPage.clickAddProduct()
194+
await productPage.cartDropdown.close()
195+
await productPage.selectOption("M")
196+
await productPage.clickAddProduct()
197+
})
198+
199+
await test.step("Navigate to the checkout process", async () => {
200+
await productPage.cartDropdown.goToCartButton.click()
201+
await productPage.cartDropdown.close()
202+
await cartPage.container.waitFor({ state: "visible" })
203+
await cartPage.checkoutButton.click()
204+
await checkoutPage.container.waitFor({ state: "visible" })
205+
})
206+
})
207+
208+
let orderId = ""
209+
await test.step("Checkout process", async () => {
210+
await test.step("Enter in the first step of the checkout process", async () => {
211+
await checkoutPage.selectSavedAddress("123 Fake Street")
212+
await checkoutPage.shippingEmailInput.fill("[email protected]")
213+
await checkoutPage.shippingPhoneInput.fill("3031112222")
214+
await checkoutPage.submitAddressButton.click()
215+
await checkoutPage.deliveryOptionsContainer.waitFor({
216+
state: "visible",
217+
})
218+
})
219+
220+
await test.step("Complete the rest of the payment process", async () => {
221+
await checkoutPage.selectDeliveryOption("FakeEx Standard")
222+
await checkoutPage.submitDeliveryOptionButton.click()
223+
await checkoutPage.submitPaymentButton.click()
224+
await checkoutPage.submitOrderButton.click()
225+
await publicOrderPage.container.waitFor({ state: "visible" })
226+
orderId = (await publicOrderPage.orderId.textContent()) || ""
227+
})
228+
})
229+
230+
await test.step("Verify the order page information is correct", async () => {
231+
await test.step("Navigate to the account orders page, verify information, and navigate to the order page", async () => {
232+
await accountOrdersPage.goto()
233+
const order = await accountOrdersPage.getOrderById(orderId)
234+
expect(order.itemsLocator).toHaveCount(3)
235+
expect(
236+
order.itemsLocator.filter({ hasText: "Sweatpants" })
237+
).toHaveCount(2)
238+
expect(
239+
order.itemsLocator.filter({ hasText: "Sweatshirt" })
240+
).toHaveCount(1)
241+
await order.detailsLink.click()
242+
await accountOrderPage.container.waitFor({ state: "visible" })
243+
})
244+
245+
await test.step("Verify information on the order page", async () => {
246+
const sweatshirt = await accountOrderPage.getProduct("Sweatshirt", "M")
247+
await expect(sweatshirt.name).toContainText("Sweatshirt")
248+
await expect(sweatshirt.variant).toContainText("M")
249+
await expect(sweatshirt.quantity).toContainText("2")
250+
251+
const smallSweatpants = await accountOrderPage.getProduct(
252+
"Sweatpants",
253+
"S"
254+
)
255+
await expect(smallSweatpants.name).toContainText("Sweatpants")
256+
await expect(smallSweatpants.variant).toContainText("S")
257+
await expect(smallSweatpants.quantity).toContainText("1")
258+
259+
const mediumSweatpants = await accountOrderPage.getProduct(
260+
"Sweatpants",
261+
"M"
262+
)
263+
await expect(mediumSweatpants.name).toContainText("Sweatpants")
264+
await expect(mediumSweatpants.variant).toContainText("M")
265+
await expect(mediumSweatpants.quantity).toContainText("1")
266+
})
267+
})
268+
})
269+
270+
test("Multiple orders are stored correctly", async ({
271+
accountOrdersPage,
272+
cartPage,
273+
checkoutPage,
274+
orderPage: publicOrderPage,
275+
productPage,
276+
storePage,
277+
}) => {
278+
let firstOrderId = ""
279+
let secondOrderId = ""
280+
await test.step("Make the first order", async () => {
281+
await test.step("Navigate to a product page", async () => {
282+
await storePage.goto()
283+
const product = await storePage.getProduct("Sweatshirt")
284+
await product.locator.highlight()
285+
await product.locator.click()
286+
await productPage.container.waitFor({ state: "visible" })
287+
})
288+
289+
await test.step("Add the product to the cart and goto checkout", async () => {
290+
await productPage.selectOption("M")
291+
await productPage.clickAddProduct()
292+
await productPage.cartDropdown.navCartLink.click()
293+
await productPage.cartDropdown.goToCartButton.click()
294+
await cartPage.container.waitFor({ state: "visible" })
295+
await cartPage.checkoutButton.click()
296+
await checkoutPage.container.waitFor({ state: "visible" })
297+
})
298+
299+
await test.step("Enter in the first step of the checkout process", async () => {
300+
await checkoutPage.selectSavedAddress("123 Fake Street")
301+
await checkoutPage.shippingEmailInput.fill("[email protected]")
302+
await checkoutPage.shippingPhoneInput.fill("3031112222")
303+
await checkoutPage.submitAddressButton.click()
304+
await checkoutPage.deliveryOptionsContainer.waitFor({
305+
state: "visible",
306+
})
307+
})
308+
309+
await test.step("Complete the rest of the payment process", async () => {
310+
await checkoutPage.selectDeliveryOption("FakeEx Standard")
311+
await checkoutPage.submitDeliveryOptionButton.click()
312+
await checkoutPage.submitPaymentButton.click()
313+
await checkoutPage.submitOrderButton.click()
314+
await publicOrderPage.container.waitFor({ state: "visible" })
315+
firstOrderId = (await publicOrderPage.orderId.textContent()) || ""
316+
})
317+
})
318+
319+
await test.step("Make the second order", async () => {
320+
await test.step("Navigate to a product page", async () => {
321+
await storePage.goto()
322+
const product = await storePage.getProduct("Sweatpants")
323+
await product.locator.highlight()
324+
await product.locator.click()
325+
await productPage.container.waitFor({ state: "visible" })
326+
})
327+
328+
await test.step("Add the product to the cart and goto checkout", async () => {
329+
await productPage.selectOption("S")
330+
await productPage.clickAddProduct()
331+
await productPage.cartDropdown.navCartLink.click()
332+
await productPage.cartDropdown.goToCartButton.click()
333+
await cartPage.container.waitFor({ state: "visible" })
334+
await cartPage.checkoutButton.click()
335+
await checkoutPage.container.waitFor({ state: "visible" })
336+
})
337+
338+
await test.step("Enter in the first step of the checkout process", async () => {
339+
await checkoutPage.selectSavedAddress("123 Fake Street")
340+
await checkoutPage.shippingEmailInput.fill("[email protected]")
341+
await checkoutPage.shippingPhoneInput.fill("3031112222")
342+
await checkoutPage.submitAddressButton.click()
343+
await checkoutPage.deliveryOptionsContainer.waitFor({
344+
state: "visible",
345+
})
346+
})
347+
348+
await test.step("Complete the rest of the payment process", async () => {
349+
await checkoutPage.selectDeliveryOption("FakeEx Standard")
350+
await checkoutPage.submitDeliveryOptionButton.click()
351+
await checkoutPage.submitPaymentButton.click()
352+
await checkoutPage.submitOrderButton.click()
353+
await publicOrderPage.container.waitFor({ state: "visible" })
354+
secondOrderId = (await publicOrderPage.orderId.textContent()) || ""
355+
})
356+
})
357+
358+
await test.step("Verify there are distinct orders on the orders page", async () => {
359+
await accountOrdersPage.goto()
360+
await test.step("Verify the first order info", async () => {
361+
const order = await accountOrdersPage.getOrderById(firstOrderId)
362+
await expect(order.itemsLocator).toHaveCount(1)
363+
await expect(order.items[0].title).toContainText("Sweatshirt")
364+
await expect(order.items[0].quantity).toHaveText("1")
365+
})
366+
await test.step("Verify the second order info", async () => {
367+
const order = await accountOrdersPage.getOrderById(secondOrderId)
368+
await expect(order.itemsLocator).toHaveCount(1)
369+
await expect(order.items[0].title).toContainText("Sweatpants")
370+
await expect(order.items[0].quantity).toHaveText("1")
371+
})
372+
})
373+
})
374+
})

0 commit comments

Comments
 (0)