diff --git a/__tests__/STF_01.spec.ts b/__tests__/STF_01.spec.ts index 6f2649d5d..f7f0936fd 100644 --- a/__tests__/STF_01.spec.ts +++ b/__tests__/STF_01.spec.ts @@ -21,8 +21,9 @@ test("STF_01: Add items to the basket", async ({ page }) => { await openCart({ page }); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toHaveCount(1); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(product.name); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(`Qty: 1`); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(price.toFixed(2)); + const productInCart = page.getByTestId("CartProductList").getByRole("listitem"); + await expect(productInCart).toHaveCount(1); + await expect(productInCart).toContainText(product.name); + await expect(productInCart).toContainText(`Qty: 1`); + await expect(productInCart).toContainText(price.toFixed(2)); }); diff --git a/__tests__/STF_03.spec.ts b/__tests__/STF_03.spec.ts index 3d5a32a47..9b5113a7f 100644 --- a/__tests__/STF_03.spec.ts +++ b/__tests__/STF_03.spec.ts @@ -24,8 +24,9 @@ test("STF_03: Check if price are calculating correctly", async ({ page }) => { await openCart({ page }); const totalPrice = (price * 2).toFixed(2); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toHaveCount(1); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(product.name); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(`Qty: 2`); - await expect(page.getByTestId("CartProductList").getByRole("listitem")).toContainText(totalPrice); + const productInCart = page.getByTestId("CartProductList").getByRole("listitem"); + await expect(productInCart).toHaveCount(1); + await expect(productInCart).toContainText(product.name); + await expect(productInCart).toContainText(`Qty: 2`); + await expect(productInCart).toContainText(totalPrice); }); diff --git a/package.json b/package.json index 1566f1232..f2b7b79a8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@adyen/adyen-web": "5.53.2", "@adyen/api-library": "14.3.0", "@headlessui/react": "1.7.17", + "@stripe/react-stripe-js": "2.3.1", + "@stripe/stripe-js": "2.1.10", "@saleor/auth-sdk": "0.14.0", "clsx": "2.0.0", "editorjs-html": "3.4.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d546dace1..90d895b74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,12 @@ dependencies: '@saleor/auth-sdk': specifier: 0.14.0 version: 0.14.0(next@14.0.0)(react-dom@18.2.0)(react@18.2.0)(urql@4.0.5) + '@stripe/react-stripe-js': + specifier: 2.3.1 + version: 2.3.1(@stripe/stripe-js@2.1.10)(react-dom@18.2.0)(react@18.2.0) + '@stripe/stripe-js': + specifier: 2.1.10 + version: 2.1.10 clsx: specifier: 2.0.0 version: 2.0.0 @@ -1812,6 +1818,23 @@ packages: urql: 4.0.5(graphql@16.8.1)(react@18.2.0) dev: false + /@stripe/react-stripe-js@2.3.1(@stripe/stripe-js@2.1.10)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-vXiwcG2ZjAF4AezjP7DJ8jiwxfCWCen/X2rBhyXaKrfQ7+pwmXhsoUlKRa0eLWioY1oelOQOafauNUiwTwFHgQ==} + peerDependencies: + '@stripe/stripe-js': ^1.44.1 || ^2.0.0 + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + dependencies: + '@stripe/stripe-js': 2.1.10 + prop-types: 15.8.1 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + + /@stripe/stripe-js@2.1.10: + resolution: {integrity: sha512-h79zhwvxAJVAvtVjtMoz++DtwI7GdcEItmTC0P2gciZoFUeAO6XX9DL+UXm9uADiEaUvTKqrExYwtBTlMYAaPA==} + dev: false + /@swc/helpers@0.5.2: resolution: {integrity: sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==} dependencies: @@ -5146,7 +5169,6 @@ packages: loose-envify: 1.4.0 object-assign: 4.1.1 react-is: 16.13.1 - dev: true /property-expr@2.0.6: resolution: {integrity: sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==} diff --git a/src/app/(main)/cart/CheckoutLink.tsx b/src/app/(main)/cart/CheckoutLink.tsx index 3701257c8..b5ec40885 100644 --- a/src/app/(main)/cart/CheckoutLink.tsx +++ b/src/app/(main)/cart/CheckoutLink.tsx @@ -3,15 +3,16 @@ type Props = { disabled?: boolean; checkoutId?: string; + className?: string; }; -export const CheckoutLink = ({ disabled, checkoutId }: Props) => { +export const CheckoutLink = ({ disabled, checkoutId, className = "" }: Props) => { return ( disabled && e.preventDefault()} href={`/checkout?checkout=${checkoutId}`} - className="w-full rounded border border-transparent bg-neutral-900 px-6 py-3 text-center font-medium text-neutral-50 hover:bg-neutral-800 aria-disabled:cursor-not-allowed aria-disabled:bg-neutral-500 sm:col-start-2" + className={`inline-block max-w-full rounded border border-transparent bg-neutral-900 px-6 py-3 text-center font-medium text-neutral-50 hover:bg-neutral-800 aria-disabled:cursor-not-allowed aria-disabled:bg-neutral-500 sm:px-16 ${className}`} > Checkout diff --git a/src/app/(main)/cart/page.tsx b/src/app/(main)/cart/page.tsx index 4a03e8731..57ae3fb38 100644 --- a/src/app/(main)/cart/page.tsx +++ b/src/app/(main)/cart/page.tsx @@ -14,55 +14,70 @@ export default async function Page() { const checkoutId = cookies().get("checkoutId")?.value || ""; const checkout = await Checkout.find(checkoutId); - const lines = checkout ? checkout.lines : []; + + if (!checkout) { + return ( +
+

Your Shopping Cart is empty

+

+ Looks like you haven’t added any items to the cart yet. +

+ + Go back + +
+ ); + } return (

Your Shopping Cart

-
-
    - {lines.map((item) => ( -
  • -
    - {item.variant?.product?.thumbnail?.url && ( - {item.variant.product.thumbnail.alt - )} -
    -
    -
    -
    - -

    {item.variant?.product?.name}

    - -

    {item.variant?.product?.category?.name}

    - {item.variant.name !== item.variant.id && Boolean(item.variant.name) && ( -

    Variant: {item.variant.name}

    - )} -
    -

    - {formatMoney(item.totalPrice.gross.amount, item.totalPrice.gross.currency)} -

    -
    -
    -
    Qty: {item.quantity}
    - +
      + {checkout.lines.map((item) => ( +
    • +
      + {item.variant?.product?.thumbnail?.url && ( + {item.variant.product.thumbnail.alt + )} +
      +
      +
      +
      + +

      {item.variant?.product?.name}

      + +

      {item.variant?.product?.category?.name}

      + {item.variant.name !== item.variant.id && Boolean(item.variant.name) && ( +

      Variant: {item.variant.name}

      + )}
      +

      + {formatMoney(item.totalPrice.gross.amount, item.totalPrice.gross.currency)} +

      -
    • - ))} -
    -
    +
    +
    Qty: {item.quantity}
    + +
    +
    +
  • + ))} +
+
@@ -71,13 +86,12 @@ export default async function Page() {

Shipping will be calculated in the next step

- {checkout && - formatMoney(checkout.totalPrice.gross.amount, checkout.totalPrice.gross.currency)} + {formatMoney(checkout.totalPrice.gross.amount, checkout.totalPrice.gross.currency)}
-
- +
+
diff --git a/src/app/(main)/layout.tsx b/src/app/(main)/layout.tsx index 16cb0dbbb..84c0547c0 100644 --- a/src/app/(main)/layout.tsx +++ b/src/app/(main)/layout.tsx @@ -11,8 +11,10 @@ export default function RootLayout(props: { children: ReactNode }) { return ( <>
-
{props.children}
-