Feature: I want to be able to add items to a shopping cart so that I can purchase them
Scenario: Adding a new item to an empty cart
Given the cart is empty
When I add item 123 to the cart
Then the cart should contain item 123
And the quantity should be 1
Scenario: Increasing quantity for an item already in the cart
Given the cart contains item 123 with quantity 1
When I add same item again
Then the quantity should be 2
import { Cart } from '../src/cart'; // adjust path as needed
describe('Shopping Cart', () => {
describe('Adding a new item to an empty cart', () => {
let cart;
beforeEach(() => {
cart = new Cart();
});
it('should contain item 123 after adding it to an empty cart', () => {
cart.addItem(123);
expect(cart.contains(123)).toBe(true);
});
it('should set quantity to 1 when the item is added for the first time', () => {
cart.addItem(123);
expect(cart.getQuantity(123)).toBe(1);
});
});
describe('Increasing quantity for an item already in the cart', () => {
let cart;
beforeEach(() => {
cart = new Cart();
cart.addItem(123); // quantity = 1
});
it('should increase the quantity to 2 when the same item is added again', () => {
cart.addItem(123); // quantity becomes 2
expect(cart.getQuantity(123)).toBe(2);
});
});
});