Skip to content

Commit

Permalink
[P4PU-24] add tests for item addition and deletion in cart store
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoivandiluccio committed Feb 13, 2025
1 parent 43733f5 commit f20d70a
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/store/CartStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
cartState,
toggleCartDrawer,
addItem,
deleteItem,
resetCart,
getCartItems,
getTotalAmout,
Expand All @@ -15,11 +16,8 @@ describe('cartStore', () => {

it('toggles the cart drawer state', () => {
toggleCartDrawer();

expect(cartState.value.isOpen).toBeTruthy();

toggleCartDrawer();

expect(cartState.value.isOpen).toBeFalsy();
});

Expand Down Expand Up @@ -75,6 +73,28 @@ describe('cartStore', () => {
expect(getTotalAmout()).toBe(item.amount);
});

it('does not add item to the cart if already present', () => {
const item: CartItem = {
amount: 100,
paFullName: 'ACI',
paTaxCode: '77777777',
nav: '00001',
iuv: '00001',
description: 'A nice description'
};
addItem(item);

expect(getCartItems()).toStrictEqual([item]);
expect(getCartItems().length).toBe(1);
expect(getTotalAmout()).toBe(item.amount);

addItem(item);

expect(getCartItems()).toStrictEqual([item]);
expect(getCartItems().length).toBe(1);
expect(getTotalAmout()).toBe(item.amount);
});

it('does not add more the 5 item to the cart', () => {
const item: CartItem = {
amount: 100,
Expand Down Expand Up @@ -117,6 +137,21 @@ describe('cartStore', () => {
expect(getTotalAmout()).toBe(0);
});

it('does nothing when empty and trying to remove an element', () => {
const item: CartItem = {
amount: 100,
paFullName: 'ACI',
paTaxCode: '77777777',
nav: '00001',
iuv: '00001',
description: 'A nice description'
};
resetCart();
deleteItem(item.iuv);
expect(getCartItems().length).toBe(0);
expect(getTotalAmout()).toBe(0);
});

it('checks the item presence correctly', () => {
const item: CartItem = {
amount: 100,
Expand Down

0 comments on commit f20d70a

Please sign in to comment.