Created
July 14, 2017 19:15
-
-
Save mattraykowski/36c846a0d634723f2568508d9ea8c37c to your computer and use it in GitHub Desktop.
Editing Card Amounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('#handleCardAddition', () => { | |
let cards; | |
let editingDecklistCards; | |
const handleCardAddition = value => { | |
const cardToAdd = cards.allCards.find(c => c.name === value); | |
// Check to see if the card exists, if it does then add it. | |
if (editingDecklistCards.hasOwnProperty(cardToAdd.cardId)) { | |
cardToAdd.amount = 2; | |
editingDecklistCards[cardToAdd.cardId].amount = 2; | |
} else { | |
cardToAdd.amount = 1; | |
editingDecklistCards[cardToAdd.cardId] = cardId; | |
} | |
}; | |
beforeEach(() => { | |
cards = { | |
allCards: [ | |
{ cardId: 'card1', name: 'test card 1', amount: 1 }, | |
{ cardId: 'card2', name: 'test card 2', amount: 1 }, | |
{ cardId: 'card3', name: 'test card 3', amount: 0 }, | |
], | |
}; | |
editingDecklistCards = { | |
card1: { cardId: 'card1', name: 'test card 1', amount: 1 }, | |
card2: { cardId: 'card2', name: 'test card 2', amount: 2 }, | |
}; | |
}); | |
test('adding an existing card increments amounts to 2', () => { | |
handleCardAddition('test card 1'); | |
expect(cards.allCards[0]).toHaveProperty('amount', 2); | |
expect(editingDecklistCards.card1.amount).toBe(2); | |
}); | |
test('adding an existing card does not increment other cards', () => { | |
handleCardAddition('test card 1'); | |
expect(cards.allCards[1]).toHaveProperty('amount', 0); | |
expect(cards.allCards[2]).toHaveProperty('amount', 0); | |
expect(editingDecklistCards.card2.amount).toBe(0); | |
expect(editingDecklistCards.card3).toBeUndefined(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment