2026-04-05
This commit is contained in:
parent
5f835ca4e6
commit
949195caf8
71 changed files with 535 additions and 458 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { expect, type Page, test } from "@playwright/test";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
type TestPage = {
|
||||
pageName: string;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { test, expect, Page, Locator, Response, APIRequestContext } from "@playwright/test";
|
||||
import { APIRequestContext, expect, Locator, Page, Response, test } from "@playwright/test";
|
||||
import { WCV3Products } from "../../web/app/themes/haiku-atelier-2024/src/scripts/lib/types/api/v3/products";
|
||||
import { BackendHeaders, getBackendHeadersFromHtml } from "./utils.ts";
|
||||
|
||||
test.describe.configure({ mode: "parallel", timeout: 60000 });
|
||||
test.describe.configure({ mode: "parallel", timeout: 60_000 });
|
||||
|
||||
test("can scroll to the end of the grid", async ({ page }): Promise<void> => {
|
||||
await scrollToGridsEnd(page);
|
||||
|
|
@ -22,12 +22,10 @@ test.skip("can access all Products' pages", async ({ page, request }): Promise<v
|
|||
const getAllProductsLinks = async (page: Page, request: APIRequestContext): Promise<Array<string>> => {
|
||||
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 },
|
||||
});
|
||||
const json = (await response.json()) as WCV3Products;
|
||||
const links = json.map((p) => p.permalink);
|
||||
|
||||
return links;
|
||||
return json.map((p) => p.permalink);
|
||||
};
|
||||
|
||||
const scrollToGridsEnd = async (page: Page): Promise<void> => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue