Adding items to the shopping cart
Once we have the basic structure of the ShoppingCart
component, we need to add a few more assertions to verify it works. We will start by adding one item to the cart, which can be done with the following code:
it('adds menu item to shopping cart', () => { render(<PizzaShopApp />); const menuList = screen.getByRole('list'); const menuItems = within(menuList).getAllByRole('listitem'); const addButton = within(menuItems[0]).getByRole('button'); userEvent.click(addButton); const shoppingCartContainer = screen.getByTestId('shopping-cart'); const placeOrderButton = within(shoppingCartContainer). getByRole('button'); expect(within(shoppingCartContainer).getByText('Margherita Pizza')). toBeInTheDocument(); expect(placeOrderButton).toBeEnabled...