Skip to content

Commit

Permalink
Fix hit wrong many times bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Nov 5, 2023
1 parent 6b3a813 commit f6735b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/store/review-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,43 @@ describe("card form store", () => {
expect(reviewStore.currentCard).toBeFalsy();
expect(reviewStore.nextCard).toBeFalsy();
});

it('hit wrong many times', () => {
const reviewStore = new ReviewStore();
reviewStore.startDeckReview(deckCardsMock);
expect(reviewStore.isFinished).toBeFalsy();

reviewStore.open()
reviewStore.changeState(CardState.Forget);

reviewStore.open()
reviewStore.changeState(CardState.Forget);

reviewStore.open()
reviewStore.changeState(CardState.Forget);

reviewStore.open()
reviewStore.changeState(CardState.Forget);

reviewStore.open()
reviewStore.changeState(CardState.Forget);

reviewStore.open()
reviewStore.changeState(CardState.Forget);

expect(reviewStore.result.forgotIds).toHaveLength(3)
expect(reviewStore.result.rememberIds).toHaveLength(0)

reviewStore.open()
reviewStore.changeState(CardState.Remember);

reviewStore.open()
reviewStore.changeState(CardState.Remember);

reviewStore.open()
reviewStore.changeState(CardState.Remember);

expect(reviewStore.result.forgotIds).toHaveLength(3)
expect(reviewStore.result.rememberIds).toHaveLength(0)
})
});
4 changes: 3 additions & 1 deletion src/store/review-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class ReviewStore {
assert(currentCardIdx !== -1);
this.cardsToReview.splice(currentCardIdx, 1);
if (currentCard.state === CardState.Forget) {
this.result.forgotIds.push(currentCard.id);
if (!this.result.forgotIds.includes(currentCard.id)) {
this.result.forgotIds.push(currentCard.id);
}
currentCard.close();
this.cardsToReview.push(currentCard);
}
Expand Down

0 comments on commit f6735b2

Please sign in to comment.