Skip to content

Commit 04a6a74

Browse files
committed
feat: implement end-to-end test for order creation and update order confirmation component
1 parent f3639f7 commit 04a6a74

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/e2e/user-create-order.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("User can create an order", async ({ page }) => {
4+
await page.goto("http://localhost:5173/");
5+
6+
await page.getByRole("link", { name: "Iniciar sesión" }).click();
7+
8+
const loginForm = {
9+
"Correo electrónico": "[email protected]",
10+
Contraseña: "supersecret",
11+
};
12+
13+
for (const [key, value] of Object.entries(loginForm)) {
14+
const input = await page.getByRole("textbox", { name: key });
15+
await input.click();
16+
await input.fill(value);
17+
}
18+
19+
await page.getByRole("button", { name: "Iniciar sesión" }).click();
20+
21+
// Wait for the user to be logged in
22+
await expect(
23+
page.getByRole("button", { name: "Cerrar sesión" })
24+
).toBeVisible();
25+
26+
await page.getByRole("menuitem", { name: "Polos" }).click();
27+
await page.getByTestId("product-item").first().click();
28+
29+
await page.getByRole("button", { name: "Agregar al Carrito" }).click();
30+
await page.getByRole("link", { name: "Carrito de compras" }).click();
31+
32+
await page.getByRole("link", { name: "Continuar Compra" }).click();
33+
34+
const orderForm = {
35+
Nombre: "Testino",
36+
Apellido: "Diprueba",
37+
Compañia: "",
38+
Dirección: "Calle De Prueba 123",
39+
Ciudad: "Lima",
40+
"Provincia/Estado": "Lima",
41+
"Código Postal": "51111",
42+
Teléfono: "987456321",
43+
};
44+
45+
for (const [key, value] of Object.entries(orderForm)) {
46+
const input = await page.getByRole("textbox", { name: key });
47+
await input.click();
48+
await input.fill(value);
49+
}
50+
51+
await page.getByRole("combobox", { name: "País" }).selectOption("PE");
52+
53+
await page.getByRole("button", { name: "Confirmar Orden" }).click();
54+
55+
await expect(page.getByText("¡Muchas gracias por tu compra!")).toBeVisible();
56+
await expect(page.getByTestId("orderId")).toBeVisible();
57+
});

src/routes/order-confirmation/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ export default function OrderConfirmation({
2525
Llegaremos a la puerta de tu domicilio lo antes posible
2626
</p>
2727
<p className="text-sm font-medium mb-2">Código de seguimiento</p>
28-
<p className="text-sm font-medium text-accent-foreground">{orderId}</p>
28+
<p
29+
data-testid="orderId"
30+
className="text-sm font-medium text-accent-foreground"
31+
>
32+
{orderId}
33+
</p>
2934
</Container>
3035
</section>
3136
);

0 commit comments

Comments
 (0)