|
| 1 | +import { CardCollection } from '.'; |
| 2 | + |
| 3 | +describe('CardCollection', () => { |
| 4 | + let cardCollection: CardCollection; |
| 5 | + |
| 6 | + beforeEach(() => { |
| 7 | + cardCollection = new CardCollection(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should add a card to the collection', () => { |
| 11 | + const question = 'What is the capital of France?'; |
| 12 | + const answer = 'Paris'; |
| 13 | + const count = 0; |
| 14 | + const submitDate = new Date(); |
| 15 | + |
| 16 | + cardCollection.addCard(question, answer, count, submitDate); |
| 17 | + |
| 18 | + expect(cardCollection.items.length).toBe(1); |
| 19 | + expect(cardCollection.items[0].question).toBe(question); |
| 20 | + expect(cardCollection.items[0].answer).toBe(answer); |
| 21 | + expect(cardCollection.items[0].stackCount).toBe(count); |
| 22 | + expect(cardCollection.items[0].submitDate).toStrictEqual(submitDate); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should delete a card from the collection', () => { |
| 26 | + const question = 'What is the capital of France?'; |
| 27 | + const answer = 'Paris'; |
| 28 | + const count = 0; |
| 29 | + const submitDate = new Date(); |
| 30 | + const cardId = 'card-123'; |
| 31 | + |
| 32 | + cardCollection.addCard(question, answer, count, submitDate, cardId); |
| 33 | + |
| 34 | + cardCollection.deleteCard(cardId); |
| 35 | + |
| 36 | + expect(cardCollection.items.length).toBe(0); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should edit a card in the collection', () => { |
| 40 | + const question = 'What is the capital of France?'; |
| 41 | + const answer = 'Paris'; |
| 42 | + const count = 0; |
| 43 | + const submitDate = new Date(); |
| 44 | + const newQuestion = 'What is the capital of Germany?'; |
| 45 | + const newAnswer = 'Berlin'; |
| 46 | + const cardId = 'card-123'; |
| 47 | + |
| 48 | + cardCollection.addCard(question, answer, count, submitDate, cardId); |
| 49 | + |
| 50 | + cardCollection.editCard(cardId, newQuestion, newAnswer); |
| 51 | + |
| 52 | + expect(cardCollection.items[0].question).toBe(newQuestion); |
| 53 | + expect(cardCollection.items[0].answer).toBe(newAnswer); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should update stackCount when checking answer', () => { |
| 57 | + const question = 'What is the capital of France?'; |
| 58 | + const answer = 'Paris'; |
| 59 | + const count = 0; |
| 60 | + const submitDate = new Date(); |
| 61 | + const cardId = 'card-123'; |
| 62 | + |
| 63 | + cardCollection.addCard(question, answer, count, submitDate, cardId); |
| 64 | + |
| 65 | + // Correct answer |
| 66 | + expect(cardCollection.checkAnswer(cardId, 'paris')).toBe(true); |
| 67 | + expect(cardCollection.items[0].stackCount).toBe(1); |
| 68 | + |
| 69 | + // Incorrect answer |
| 70 | + expect(cardCollection.checkAnswer(cardId, 'berlin')).toBe(false); |
| 71 | + expect(cardCollection.items[0].stackCount).toBe(0); |
| 72 | + }); |
| 73 | +}); |
0 commit comments