Skip to content

Commit

Permalink
Order Card and detail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danieladov committed May 2, 2022
1 parent 6d86864 commit 5dc56da
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
46 changes: 46 additions & 0 deletions webapp/src/components/user/OrderCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


/**
* Test that the OrderAdminCard component is working as expected with a product.
*/

import { render } from "@testing-library/react";
import { ItemCart, Order, Product } from "../../shared/shareddtypes";
import OrderCard from "./OrderCard";


test('order admin card component can be rendered with a product', async () => {
const order:Order = {
userId: "1",
products: [{
productId: "1",
product: {
id: "1",
name: "Product 1",
description: "Product 1 description",
price: 10,
image: "",
category: "Test",
reviews: [],
product: {} as Product,
_id: "1",
quantity: 2
},
reviewed: false,
quantity: 1,
price:79.99
}],
subTotal: 69.99,
deliveryPrice: 30,
address: "Test address",
createdAt: new Date("2022-05-02T16:13:17.026+00:00"),
id: "1",
}

const { getByText } = render(<OrderCard order={order} />);
expect(getByText("Order Mon May 02")).toBeInTheDocument();
expect(getByText("Total: 69.99 €")).toBeInTheDocument();
expect(getByText("Shipping cost: 30 €")).toBeInTheDocument();
}
, 30000);

32 changes: 32 additions & 0 deletions webapp/src/components/user/OrderDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

/**
* Check that orderAdminDetails component can be rendered without any error.
*/

import { getByText, render } from "@testing-library/react";
import { Product } from "../../shared/shareddtypes";
import OrderDetails from "./OrderDetails";

test('orderAdminDetails component can be rendered', async () => {
const product = {
productId: "1",
product: {
id: "1",
name: "Product 1",
description: "Product 1 description",
price: 79.99,
image: "",
category: "Test",
reviews: [],
product: {} as Product,
_id: "1",
quantity: 3
},
reviewed: false,
quantity: 3,
price:79.99
}
const { getByText } = render(<OrderDetails productOrdered={product} orderId={"1"}/>);
expect(getByText("Product 1")).toBeInTheDocument();
expect(getByText("79.99€/unit - 3 units")).toBeInTheDocument();
})

0 comments on commit 5dc56da

Please sign in to comment.