2026-05-05
This commit is contained in:
parent
6102b77ac7
commit
cf5012b1e3
4 changed files with 71 additions and 22 deletions
|
|
@ -1,38 +1,34 @@
|
|||
/** @effect-diagnostics asyncFunction:skip-file */
|
||||
import type { APIRequestContext, Locator, Page, Response } from "@playwright/test";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { Effect, ManagedRuntime } from "effect";
|
||||
import { ATTRIBUT_PAGE } from "../../web/app/themes/haiku-atelier-2024/src/scripts/constantes/dom.ts";
|
||||
import type { WCV3Products } from "../../web/app/themes/haiku-atelier-2024/src/scripts/lib/types/api/v3/products";
|
||||
import ShopPageRuntime from "../../web/app/themes/haiku-atelier-2024/src/scripts/page-boutique/runtime.ts";
|
||||
import ShopPageElements from "../../web/app/themes/haiku-atelier-2024/src/scripts/page-boutique/service-elements.ts";
|
||||
import type { BackendHeaders } from "./utils.ts";
|
||||
import { getBackendHeadersFromHtml } from "./utils.ts";
|
||||
import { APIClient } from "../../web/app/themes/haiku-atelier-2024/src/scripts-effect/lib/api.ts";
|
||||
|
||||
test.describe.configure({ mode: "parallel", timeout: 60_000 });
|
||||
|
||||
test("can scroll to the end of the grid", async ({ page }): Promise<void> => {
|
||||
await scrollToGridsEnd(page);
|
||||
});
|
||||
/** _Runtime_ pour effectuer les appels API. */
|
||||
const TestRuntime = ManagedRuntime.make(APIClient.Live);
|
||||
|
||||
test("can access all Products' pages", async ({ page, request }): Promise<void> => {
|
||||
await page["goto"]("https://haikuatelier.gcch.local/shop/");
|
||||
const links = await getAllProductsLinks(page, request);
|
||||
test("can do stuff", async ({ page }) => {
|
||||
await page.goto("https://haikuatelier.gcch.local/shop/");
|
||||
|
||||
for (const link of links) {
|
||||
// Vérifie que le lien de la page retourne OK.
|
||||
const req = await request.get(link);
|
||||
await expect(req, "The Product's page is accessible").toBeOK();
|
||||
}
|
||||
});
|
||||
const doStuff = Effect.fn("doStuff")(function*() {
|
||||
const Elements = yield* ShopPageElements;
|
||||
|
||||
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: { Authorization: `Basic ${backendHeaders.authString}`, Nonce: backendHeaders.nonce },
|
||||
expect(Elements.ProductsGrid.getAttribute(ATTRIBUT_PAGE)).toBe(1);
|
||||
});
|
||||
const json = (await response.json()) as WCV3Products;
|
||||
return json.map(p => p.permalink);
|
||||
};
|
||||
|
||||
const scrollToGridsEnd = async (page: Page): Promise<void> => {
|
||||
await page["goto"]("https://haikuatelier.gcch.local/shop/");
|
||||
ShopPageRuntime.runSync(doStuff());
|
||||
});
|
||||
|
||||
test.skip("can scroll to the end of the grid", async ({ page }): Promise<void> => {
|
||||
await page.goto("https://haikuatelier.gcch.local/shop/");
|
||||
|
||||
let hasMoreProducts = true;
|
||||
let currentPageNumber = "1";
|
||||
|
|
@ -67,4 +63,24 @@ const scrollToGridsEnd = async (page: Page): Promise<void> => {
|
|||
hasMoreProducts = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test.skip("can access all Products' pages", async ({ page, request }): Promise<void> => {
|
||||
await page.goto("https://haikuatelier.gcch.local/shop/");
|
||||
const links = await getAllProductsLinks(page, request);
|
||||
|
||||
for (const link of links) {
|
||||
// Vérifie que le lien de la page retourne OK.
|
||||
const req = await request.get(link);
|
||||
await expect(req, "The Product's page is accessible").toBeOK();
|
||||
}
|
||||
});
|
||||
|
||||
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: { Authorization: `Basic ${backendHeaders.authString}`, Nonce: backendHeaders.nonce },
|
||||
});
|
||||
const json = (await response.json()) as WCV3Products;
|
||||
return json.map(p => p.permalink);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue