Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkluth committed Nov 1, 2023
1 parent fc7370d commit 71e7fee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/shared-ui/components/cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Cart = ({ onMobileNavClose, children }: React.PropsWithChildren<Car
onMobileNavClose();
toggleCartOpen(true);
}}
data-testid="cart"
>
<span className="hidden sm:block">Cart</span>
<AnimatePresence mode="popLayout">
Expand Down
1 change: 0 additions & 1 deletion packages/shared-ui/components/cart/CartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const CartProvider = ({ children, ...props }: React.PropsWithChildren<Pro
const updateCart = React.useCallback(
(changeSet: CartUpdate) => {
if (isManaged) {
console.log("calling actions");
props.onCartUpdate(changeSet);
}

Expand Down
15 changes: 13 additions & 2 deletions packages/shared-ui/components/cart/stories/Cart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { CartContent } from "../CartContent";
import { CartItem, CartProvider, useCart } from "../CartContext";
import { action } from "@storybook/addon-actions";

import { userEvent, within, waitFor } from "@storybook/testing-library";
import { expect } from "@storybook/jest";

const meta: Meta<typeof Cart> = {
component: Cart,
title: "Cart",
Expand Down Expand Up @@ -95,8 +98,8 @@ export const API: StoryObj<typeof Cart> = {
const onCartFetch = () => {
const items: CartItem[] = [
{
_id: "Product 1",
name: "Product 1",
_id: "product 1",
name: "product 1",
quantity: 1,
price: 2,
},
Expand All @@ -118,4 +121,12 @@ export const API: StoryObj<typeof Cart> = {
);
},
],
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await waitFor(async () => {
await userEvent.click(canvas.getByRole("button", { name: /product1/i }));
await userEvent.click(canvas.getByRole("button", { name: /product2/i }));
expect(canvas.getByTestId("cart")).toHaveTextContent("Cart3");
});
},
};

0 comments on commit 71e7fee

Please sign in to comment.