Skip to content

Commit

Permalink
fix card store tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NFriedo committed May 23, 2024
1 parent e0f375f commit ff6e00c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/modules/data/board/Card.store.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ describe("CardStore", () => {
const cardId = cards[0].id;
const card = cards[0];
card.elements = elements;
cardStore.cards[cardId] = card;
cardStore.fetchCardSuccess({ cards });

for (const card of cards) {
cardStore.cards[card.id] = card;
}

return { cardStore, cardId, elements };
};
Expand Down Expand Up @@ -151,7 +153,7 @@ describe("CardStore", () => {
const { cardStore } = setup();
const cards = cardResponseFactory.buildList(3);

cardStore.fetchCardSuccess({ cards });
cardStore.fetchCardSuccess({ cards, isOwnAction: true });

expect(cardStore.getCard(cards[0].id)).toEqual(cards[0]);
});
Expand Down Expand Up @@ -193,6 +195,7 @@ describe("CardStore", () => {

cardStore.deleteCardSuccess({
cardId: "unkownId",
isOwnAction: true,
});

expect(cardStore.cards).toEqual(oldCards);
Expand All @@ -203,6 +206,7 @@ describe("CardStore", () => {

cardStore.deleteCardSuccess({
cardId,
isOwnAction: true,
});

expect(cardStore.cards[cardId]).toBeUndefined();
Expand Down Expand Up @@ -245,6 +249,7 @@ describe("CardStore", () => {
cardStore.updateCardTitleSuccess({
cardId: "unkownId",
newTitle: NEW_TITLE,
isOwnAction: true,
});

expect(Object.values(cardStore.cards).map((card) => card.title)).toEqual(
Expand All @@ -258,6 +263,7 @@ describe("CardStore", () => {
cardStore.updateCardTitleSuccess({
cardId,
newTitle: NEW_TITLE,
isOwnAction: true,
});

expect(cardStore.cards[cardId].title).toEqual(NEW_TITLE);
Expand Down Expand Up @@ -300,6 +306,7 @@ describe("CardStore", () => {
cardStore.updateCardHeightSuccess({
cardId: "unkownId",
newHeight: NEW_HEIGHT,
isOwnAction: true,
});

expect(Object.values(cardStore.cards).map((card) => card.height)).toEqual(
Expand All @@ -313,6 +320,7 @@ describe("CardStore", () => {
cardStore.updateCardHeightSuccess({
cardId,
newHeight: NEW_HEIGHT,
isOwnAction: true,
});

expect(cardStore.cards[cardId].height).toEqual(NEW_HEIGHT);
Expand Down Expand Up @@ -381,6 +389,7 @@ describe("CardStore", () => {
cardId,
newElement,
toPosition,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements.length).toEqual(4);
Expand All @@ -397,6 +406,7 @@ describe("CardStore", () => {
type: ContentElementType.Drawing,
cardId,
newElement,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements.length).toEqual(4);
Expand All @@ -414,6 +424,7 @@ describe("CardStore", () => {
type: ContentElementType.Drawing,
cardId: "invalidId",
newElement,
isOwnAction: true,
});

expect(Object.keys(cardStore.cards).length).toEqual(3);
Expand All @@ -431,6 +442,7 @@ describe("CardStore", () => {
cardId,
newElement,
toPosition: 100,
isOwnAction: true,
});

expect(Object.keys(cardStore.cards).length).toEqual(3);
Expand Down Expand Up @@ -518,6 +530,7 @@ describe("CardStore", () => {
elementId: elements[0].id,
toCardId: "unknownId",
toPosition: 1,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements[0].id).toEqual(elementId);
Expand All @@ -532,6 +545,7 @@ describe("CardStore", () => {
elementId,
toCardId: cardId,
toPosition,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements[toPosition].id).toEqual(
Expand All @@ -548,6 +562,7 @@ describe("CardStore", () => {
elementId,
toCardId: cardId,
toPosition,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements[1].id).toEqual(elementId);
Expand All @@ -560,7 +575,11 @@ describe("CardStore", () => {
const numberOfElements = cardStore.cards[cardId].elements.length;
const elementId = elements[0].id;

await cardStore.deleteElementSuccess({ cardId: "unkown", elementId });
await cardStore.deleteElementSuccess({
cardId: "unkown",
elementId,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements.length).toEqual(numberOfElements);
});
Expand All @@ -569,7 +588,11 @@ describe("CardStore", () => {
const numberOfElements = cardStore.cards[cardId].elements.length;
const elementId = elements[0].id;

await cardStore.deleteElementSuccess({ cardId, elementId });
await cardStore.deleteElementSuccess({
cardId,
elementId,
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements.length).toEqual(
numberOfElements - 1
Expand Down Expand Up @@ -617,6 +640,7 @@ describe("CardStore", () => {
type: ContentElementType.RichText,
content: richTextElementContentFactory.build(),
},
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements).toEqual(oldElements);
Expand All @@ -634,6 +658,7 @@ describe("CardStore", () => {
type: elementToUpdate.type,
content: newContent,
},
isOwnAction: true,
});

expect(cardStore.cards[cardId].elements[0].content).toEqual(newContent);
Expand Down

0 comments on commit ff6e00c

Please sign in to comment.