MIL-008: Choose level
Review record RC-041 (Go, autonomous mode, not independent). Task: MIL-008#1 Task: MIL-008#2 Task: MIL-008#3 Task: MIL-008#4 Task: MIL-008#5 Task: MIL-008#6 Task: MIL-008#7 Task: MIL-008#8
This commit is contained in:
@@ -11,6 +11,7 @@ from flash_card.domain.entities.deck import Deck
|
||||
from flash_card.domain.entities.vocabulary import Vocabulary
|
||||
from flash_card.domain.errors.vocabulary_errors import VocabularyNotFoundError
|
||||
from flash_card.domain.value_objects.language_pair import LanguagePair
|
||||
from flash_card.domain.value_objects.level import Level
|
||||
|
||||
|
||||
class _FakeRepository:
|
||||
@@ -52,7 +53,7 @@ def test_open_study_session_builds_session_over_all_cards() -> None:
|
||||
repository = _FakeRepository(Vocabulary(LanguagePair("ms", "da"), cards))
|
||||
|
||||
session = open_study_session(
|
||||
repository, _RecordingProgress(), _SilentSpeech(), _first
|
||||
repository, _RecordingProgress(), _SilentSpeech(), _first, Level(None)
|
||||
)
|
||||
|
||||
assert session.remaining == 2
|
||||
@@ -62,7 +63,11 @@ def test_open_study_session_builds_session_over_all_cards() -> None:
|
||||
def test_open_study_session_propagates_repository_error() -> None:
|
||||
with pytest.raises(VocabularyNotFoundError):
|
||||
open_study_session(
|
||||
_MissingRepository(), _RecordingProgress(), _SilentSpeech(), _first
|
||||
_MissingRepository(),
|
||||
_RecordingProgress(),
|
||||
_SilentSpeech(),
|
||||
_first,
|
||||
Level(None),
|
||||
)
|
||||
|
||||
|
||||
@@ -72,21 +77,83 @@ def test_open_study_session_prefers_saved_progress() -> None:
|
||||
progress = _RecordingProgress(Deck(pair, [Card("kau", "du")]))
|
||||
|
||||
session = open_study_session(
|
||||
_FakeRepository(vocabulary), progress, _SilentSpeech(), _first
|
||||
_FakeRepository(vocabulary), progress, _SilentSpeech(), _first, Level(None)
|
||||
)
|
||||
|
||||
assert session.remaining == 1
|
||||
assert session.next_card() == CardDto("kau", "du", "ms", "da")
|
||||
|
||||
|
||||
def test_open_study_session_skips_vocabulary_when_progress_exists() -> None:
|
||||
progress = _RecordingProgress(Deck(LanguagePair("ms", "da"), []))
|
||||
PAIR = LanguagePair("ms", "da")
|
||||
THREE = (Card("aku", "mig"), Card("kau", "du"), Card("ini", "denne"))
|
||||
|
||||
|
||||
def _last(cards: Sequence[Card]) -> Card:
|
||||
return cards[-1]
|
||||
|
||||
|
||||
def test_open_study_session_propagates_error_when_list_is_missing() -> None:
|
||||
progress = _RecordingProgress(Deck(PAIR, []))
|
||||
|
||||
with pytest.raises(VocabularyNotFoundError):
|
||||
open_study_session(
|
||||
_MissingRepository(), progress, _SilentSpeech(), _first, Level(None)
|
||||
)
|
||||
|
||||
|
||||
def test_open_study_session_limits_draws_to_first_cards_of_level() -> None:
|
||||
session = open_study_session(
|
||||
_MissingRepository(), progress, _SilentSpeech(), _first
|
||||
_FakeRepository(Vocabulary(PAIR, THREE)),
|
||||
_RecordingProgress(),
|
||||
_SilentSpeech(),
|
||||
_last,
|
||||
Level(2),
|
||||
)
|
||||
|
||||
assert session.remaining == 0
|
||||
assert session.remaining == 3
|
||||
assert session.remaining_in_level == 2
|
||||
assert session.next_card() == CardDto("kau", "du", "ms", "da")
|
||||
|
||||
|
||||
def test_open_study_session_uses_vocabulary_order_with_saved_progress() -> None:
|
||||
progress = _RecordingProgress(Deck(PAIR, [THREE[2], THREE[1]]))
|
||||
session = open_study_session(
|
||||
_FakeRepository(Vocabulary(PAIR, THREE)),
|
||||
progress,
|
||||
_SilentSpeech(),
|
||||
_first,
|
||||
Level(2),
|
||||
)
|
||||
|
||||
assert session.remaining == 2
|
||||
assert session.remaining_in_level == 1
|
||||
assert session.next_card() == CardDto("kau", "du", "ms", "da")
|
||||
|
||||
|
||||
def test_open_study_session_is_finished_when_level_has_nothing_left() -> None:
|
||||
progress = _RecordingProgress(Deck(PAIR, [THREE[1]]))
|
||||
session = open_study_session(
|
||||
_FakeRepository(Vocabulary(PAIR, THREE)),
|
||||
progress,
|
||||
_SilentSpeech(),
|
||||
_first,
|
||||
Level(1),
|
||||
)
|
||||
|
||||
assert session.next_card() is None
|
||||
assert session.remaining == 1
|
||||
|
||||
|
||||
def test_open_study_session_uses_all_cards_when_level_exceeds_list() -> None:
|
||||
session = open_study_session(
|
||||
_FakeRepository(Vocabulary(PAIR, THREE)),
|
||||
_RecordingProgress(),
|
||||
_SilentSpeech(),
|
||||
_first,
|
||||
Level(1000),
|
||||
)
|
||||
|
||||
assert session.remaining_in_level == 3
|
||||
|
||||
|
||||
def test_open_study_session_never_saves_on_start() -> None:
|
||||
@@ -94,7 +161,7 @@ def test_open_study_session_never_saves_on_start() -> None:
|
||||
progress = _RecordingProgress()
|
||||
|
||||
session = open_study_session(
|
||||
_FakeRepository(vocabulary), progress, _SilentSpeech(), _first
|
||||
_FakeRepository(vocabulary), progress, _SilentSpeech(), _first, Level(None)
|
||||
)
|
||||
session.next_card()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user