Task Description: Implement a Shopping Cart System
You are required to create a shopping cart system that allows users to add items to their cart, view the contents of their cart, and calculate the total cost of the items. The implementation should fulfill the following requirements:
ShoppingCart Class: Create a ShoppingCart class located in the /app/ directory.
The class should have the following properties and methods:
items: An array that stores the items added to the cart. Each item is an object with name, price, and quantity attributes.
addItem(name: string, price: number, quantity: number): A method to add an item to the cart. If the item already exists in the cart, it should update the quantity.
removeItem(name: string): A method to remove an item from the cart by its name.
viewCart(): A method that returns the current items in the cart, including the name, price, quantity, and total price for each item.
calculateTotal(): A method that returns the total price of all items in the cart, which should account for the price multiplied by the quantity for each item.
Functionality Requirements:
When adding an item, if the item already exists in the cart, its quantity should increase, and the total price for that item should be recalculated.
The removeItem(name) method should remove the item from the cart if it exists, regardless of its quantity.
The viewCart() method should return an array of objects, where each object represents an item with the keys name, price, quantity, and totalPrice, which is calculated as price * quantity.
The calculateTotal() method should return a single numerical value that is the sum of all the total prices of items in the cart.
Testing Requirements: Ensure that the implementation passes the following tests:
The ability to add new items and ensure they are stored correctly.
The ability to update quantities of existing items.
The ability to remove items from the cart.
The accuracy of the total price calculated for the cart.
You should ensure your implementation is properly encapsulated within the ShoppingCart class and that the methods function as specified. Once completed, the tests associated with the shopping cart functionality should pass successfully.