2026-04-05

This commit is contained in:
gcch 2026-04-05 13:11:21 +02:00
commit 2971f5516d
62 changed files with 439 additions and 497 deletions

View file

@ -24,8 +24,8 @@ type ProductsFixture = {
type ProductsKinds = {
allProducts: WCV3Products;
simpleProducts: WCV3Products;
simpleProductsWithStock: WCV3Products;
simpleProductsWithoutStock: WCV3Products;
simpleProductsWithStock: WCV3Products;
};
export const test = base.extend<ProductsFixture>({
@ -34,7 +34,7 @@ export const test = base.extend<ProductsFixture>({
const backendHeaders: BackendHeaders = await getBackendHeadersFromHtml(page);
const response = await request.get("/wp-json/wc/v3/products?page=1&per_page=100&status=publish", {
headers: { Nonce: backendHeaders.nonce, Authorization: `Basic ${backendHeaders.authString}` },
headers: { Authorization: `Basic ${backendHeaders.authString}`, Nonce: backendHeaders.nonce },
});
expect(response.ok(), "The API returned the list of every Product").toBeTruthy();
@ -50,15 +50,15 @@ export const test = base.extend<ProductsFixture>({
const kinds = {
allProducts,
simpleProducts,
simpleProductsWithStock,
simpleProductsWithoutStock,
simpleProductsWithStock,
} satisfies ProductsKinds;
await use(kinds);
},
});
test("can add a Product without variation with stock to the Cart", async ({ products, page }) => {
test("can add a Product without variation with stock to the Cart", async ({ page, products }) => {
// Prend un produit au hasard.
const randomProductIndex = getRandomIntInclusive(0, products.simpleProductsWithStock.length - 1);
const randomProduct = products.simpleProductsWithStock.at(randomProductIndex);
@ -71,7 +71,7 @@ test("can add a Product without variation with stock to the Cart", async ({ prod
await page.goto(randomProduct.permalink);
// Vérifie le bon état du bouton de l'ajout au Panier.
const addToCartButton = page.getByRole("button", { name: "Add to cart", disabled: false });
const addToCartButton = page.getByRole("button", { disabled: false, name: "Add to cart" });
await addToCartButton.scrollIntoViewIfNeeded();
await expect(addToCartButton, "The add to cart button must be visible").toBeVisible();
await expect(addToCartButton, "The add to cart button must be enabled").toBeEnabled();
@ -91,7 +91,7 @@ test("can add a Product without variation with stock to the Cart", async ({ prod
expect(cartLink, "The cart items' indicator has been incremented").toBeDefined();
});
test("can't add a Product without variation without stock to the Cart", async ({ products, page }) => {
test("can't add a Product without variation without stock to the Cart", async ({ page, products }) => {
// Prend un produit au hasard.
const randomProductIndex = getRandomIntInclusive(0, products.simpleProductsWithoutStock.length - 1);
const randomProduct = products.simpleProductsWithoutStock.at(randomProductIndex);
@ -104,7 +104,7 @@ test("can't add a Product without variation without stock to the Cart", async ({
await page.goto(randomProduct.permalink);
// Vérifie le bon état du bouton de l'ajout au Panier.
const outOfStockButton = page.getByRole("button", { name: "Out of stock", disabled: true });
const outOfStockButton = page.getByRole("button", { disabled: true, name: "Out of stock" });
await outOfStockButton.scrollIntoViewIfNeeded();
await expect(outOfStockButton, "The add to cart button must be visible").toBeVisible();
await expect(outOfStockButton, "The add to cart button must be disabled").toBeDisabled();