Skip to content

Commit

Permalink
Fixes for E2E tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
amcaffee-ep committed Jan 23, 2025
1 parent 22a3058 commit ca10e25
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
17 changes: 11 additions & 6 deletions examples/commerce-essentials/e2e/models/d2c-product-detail-page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ElasticPath, ProductResponse } from "@elasticpath/js-sdk";
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { getSkuIdFromOptions } from "../../src/lib/product-helper";
import { getCartId } from "../util/get-cart-id";
import {
getProductById,
getSimpleProduct,
getVariationsProduct,
} from "../util/resolver-product-from-store";
import type {ElasticPath, ProductResponse } from "@elasticpath/js-sdk";
import { getCartId } from "../util/get-cart-id";
import { getSkuIdFromOptions } from "../../src/lib/product-helper";

const host = process.env.NEXT_PUBLIC_EPCC_ENDPOINT_URL;

Expand Down Expand Up @@ -110,16 +110,21 @@ async function selectOptions(
): Promise<string> {
/* select one of each variation option */
const options = baseProduct.meta.variations?.reduce((acc, variation) => {
return [...acc, ...([variation.options?.[0]] ?? [])];
const value = variation.options?.[0];
return [...acc, { ...variation, value }];
}, []);

if (options && baseProduct.meta.variation_matrix) {
for (const option of options) {
await page.click(`text=${option.name}`);
if (option.name.toLowerCase() === "color") {
await page.getByTitle(option.value.name).click();
} else {
await page.click(`text=${option.value.name}`);
}
}

const variationId = getSkuIdFromOptions(
options.map((x) => x.id),
options.map((x) => x.value.id),
baseProduct.meta.variation_matrix,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const ProductVariationColor = ({
>
<button
type="button"
title={o.name}
className={clsx(
colorLookup[o.name.toLowerCase()],
`bg-${colorLookup[o.name.toLowerCase()]}-500`,
"rounded-full border border-gray-200 p-4",
)}
onClick={() => updateOptionHandler(variation.id, o.id)}
Expand Down
2 changes: 2 additions & 0 deletions examples/commerce-essentials/src/lib/color-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const colorLookup: { [key: string]: string } = {
purple: "purple",
green: "green",
blue: "blue",
yellow: "yellow",
orange: "orange"
};
5 changes: 5 additions & 0 deletions examples/commerce-essentials/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import type { Config } from "tailwindcss";

export default {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
safelist: [
"bg-purple-500",
"bg-yellow-500",
"bg-orange-500"
],
theme: {
extend: {
maxWidth: {
Expand Down

0 comments on commit ca10e25

Please sign in to comment.