Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlkluth committed Nov 1, 2023
1 parent 71e7fee commit a78afbe
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/shared-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const config = {
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
"@storybook/addon-a11y",
],
docs: {
autodocs: "tag",
Expand Down
4 changes: 3 additions & 1 deletion packages/shared-ui/components/cart/CartContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const CartContent = ({ ProductListLink }: CartContentProps) => {
<div className="flex flex-col gap-3">
<div className="flex justify-between items-center text-h6">
<span>Total</span>
<span className="font-bold font-jeanLuc">{isLoading ? "..." : currencyFormatter.format(totalPrice)}</span>
<span className="font-bold font-jeanLuc" data-testid="total">
{isLoading ? "..." : currencyFormatter.format(totalPrice)}
</span>
</div>
<Button variant="primary" as="button" onClick={notifyWeDontSellBread}>
Checkout
Expand Down
1 change: 1 addition & 0 deletions packages/shared-ui/components/cart/CartItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const CartLineItem = ({ item }: CartItemProps) => {
value={desiredQty}
name="amount"
type="number"
aria-label={`${item.name} quantity`}
placeholder="1"
min={1}
max={100}
Expand Down
19 changes: 16 additions & 3 deletions packages/shared-ui/components/cart/stories/Cart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const AddToCartButtons = () => {
>
Add product2
</button>
<button type="button" className="bg-red text-white hover:bg-red/90 mr-2 p-2" onClick={clearCart}>
<button type="button" className="border-black border hover:bg-red/90 mr-2 p-2" onClick={clearCart}>
Clear Cart
</button>
</div>
Expand Down Expand Up @@ -121,12 +121,25 @@ export const API: StoryObj<typeof Cart> = {
);
},
],
play: async ({ canvasElement }) => {
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
await waitFor(async () => {
await step("add to cart", 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");
});

await step("open cart and modify quantity", async () => {
await userEvent.click(canvas.getByTestId("cart"));
await userEvent.type(canvas.getByLabelText("product 1 quantity"), "{backspace}9");
await waitFor(() => expect(canvas.getByTestId("total")).toHaveTextContent("$20.00"));
});

await step("clear cart", async () => {
await userEvent.click(canvas.getByRole("button", { name: /close/i }));
expect(canvas.getByTestId("cart")).toHaveTextContent("Cart10");
await userEvent.click(canvas.getByRole("button", { name: /clear/i }));
expect(canvas.getByTestId("cart")).toHaveTextContent("Cart0");
});
},
};
2 changes: 2 additions & 0 deletions packages/shared-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
"react-dom": ">=18.0.0"
},
"devDependencies": {
"@storybook/addon-a11y": "^7.5.2",
"@storybook/addon-actions": "^7.5.2",
"@storybook/react-vite": "^7.5.2",
"http-server": "^14.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"tsup": "^7.2.0"
Expand Down
56 changes: 56 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a78afbe

Please sign in to comment.