generated from Arquisoft/dede_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from Arquisoft/develop
Develop - Integrate checkout testing - address form test
- Loading branch information
Showing
8 changed files
with
201 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { screen, render } from "@testing-library/react"; | ||
import { ItemCart, Product } from "../../shared/shareddtypes"; | ||
import Checkout from "./Checkout"; | ||
|
||
|
||
let itemcart1:ItemCart = { | ||
product: { | ||
id: "1", | ||
name: "Product 1", | ||
description: "Product 1 description", | ||
price: 10, | ||
image: "", | ||
category: "Test", | ||
reviews: [], | ||
product: {} as Product, | ||
_id: "1", | ||
quantity: 2 | ||
}, | ||
quantity: 2 | ||
} | ||
|
||
/** | ||
* Test that the checkout component can be rendered without any error using one productOrdered in the cart. | ||
*/ | ||
|
||
test('checkout component can be rendered', async () => { | ||
const cart:ItemCart[] = [itemcart1]; | ||
const { getByText } = render(<Checkout items={cart} />); | ||
expect(screen.getByText("Checkout")).toBeInTheDocument(); | ||
expect(screen.getByText("Cart Totals:")).toBeInTheDocument(); | ||
expect(getByText("Price: 10 €")).toBeInTheDocument(); | ||
expect(getByText("Product 1")).toBeInTheDocument(); | ||
expect(getByText("2 Unit(s)")).toBeInTheDocument(); | ||
expect(getByText("20.00 €")).toBeInTheDocument(); | ||
expect(screen.getByText("Shipping")).toBeInTheDocument(); | ||
|
||
}); | ||
|
||
/** | ||
* Test that the checkout component can be rendered without any error using multiple productsOrdered in the cart. | ||
*/ | ||
|
||
test('checkout component can be rendered with multiple products', async () => { | ||
const fakeProd: Product = {} as Product; | ||
const cart:ItemCart[] = [itemcart1,{ | ||
product: { | ||
id: "2", | ||
name: "Product 2", | ||
description: "Product 2 description", | ||
price: 20, | ||
image: "", | ||
category: "Test", | ||
reviews: [], | ||
product: fakeProd, | ||
_id: "2", | ||
quantity: 1 | ||
}, | ||
quantity: 1 | ||
}]; | ||
const { getByText } = render(<Checkout items={cart} />); | ||
//total price | ||
expect(getByText("40.00 €")).toBeInTheDocument(); | ||
//product 1 | ||
expect(getByText("Product 1")).toBeInTheDocument(); | ||
expect(getByText("2 Unit(s)")).toBeInTheDocument(); | ||
expect(getByText("Price: 10 €")).toBeInTheDocument(); | ||
//product 2 | ||
expect(getByText("Product 2")).toBeInTheDocument(); | ||
expect(getByText("1 Unit(s)")).toBeInTheDocument(); | ||
expect(getByText("Price: 20 €")).toBeInTheDocument(); | ||
|
||
}); | ||
|
||
test('checkout component is rendered without letting user go to shipping if the cart is empty', async () => { | ||
|
||
const { getByText } = render(<Checkout items={[]} />); | ||
expect(screen.getByText("Checkout")).toBeInTheDocument(); | ||
expect(screen.getByText("Cart Totals:")).toBeInTheDocument(); | ||
|
||
expect(getByText("0.00 €")).toBeInTheDocument(); | ||
expect(screen.queryByText("Shipping")).toBeNull(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
webapp/src/components/checkout-shipping/CheckoutItem.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { render } from "@testing-library/react"; | ||
import { ItemCart, Product } from "../../shared/shareddtypes"; | ||
import CheckoutItem from "./CheckoutItem"; | ||
|
||
|
||
/** | ||
* Chek that the CheckoutItem component is working as expected with a product. | ||
*/ | ||
|
||
|
||
test('checkout item component can be rendered with a product', async () => { | ||
const fakeProd: Product = {} as Product; | ||
const cart:ItemCart[] = [{ | ||
product: { | ||
id: "1", | ||
name: "Product 1", | ||
description: "Product 1 description", | ||
price: 69.99, | ||
image: "", | ||
category: "Test", | ||
reviews: [], | ||
product: fakeProd, | ||
_id: "1", | ||
quantity: 1 | ||
}, | ||
quantity: 1 | ||
}]; | ||
const { getByText } = render(<CheckoutItem item={cart[0]} />); | ||
expect(getByText("Product 1")).toBeInTheDocument(); | ||
expect(getByText("1 Unit(s)")).toBeInTheDocument(); | ||
expect(getByText("Price: 69.99 €")).toBeInTheDocument(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { screen, render, queryByText, waitForElementToBeRemoved } from "@testing-library/react"; | ||
|
||
import AddressForm from './AddressForm'; | ||
|
||
import userEvent from "@testing-library/user-event"; | ||
|
||
import { ReactNotifications } from "react-notifications-component"; | ||
/** | ||
* Chek that the CheckoutItem component is working as expected with a product. | ||
*/ | ||
|
||
|
||
test('Check alert is shown when an address field is missing', async () => { | ||
|
||
render(<div><ReactNotifications/><div><AddressForm/></div></div>); | ||
expect(screen.getByTestId("street-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("locality-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("zipcode-input")).toBeInTheDocument(); | ||
expect(screen.getByTestId("country-input")).toBeInTheDocument(); | ||
expect(screen.getByText("Example: Valdés Salas.")).toBeInTheDocument(); | ||
expect(screen.getByText("Example: Oviedo.")).toBeInTheDocument(); | ||
expect(screen.getByText("Example: 33007.")).toBeInTheDocument(); | ||
expect(screen.getByText("Example: Spain.")).toBeInTheDocument(); | ||
expect(screen.getByText('Set Address')).toBeInTheDocument(); | ||
userEvent.click(screen.getByText('Set Address')); | ||
expect(screen.getByText('Attention!')).toBeInTheDocument(); | ||
expect(screen.getByText('Please, fill all form fields.')).toBeInTheDocument(); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters