File size: 2,004 Bytes
5e84ffc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d53fa1b
5e84ffc
 
 
 
 
d53fa1b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Tests for the ViewTextManager class."""

from typing import List, Optional

import pytest

from improvisation_lab.presentation.view_text_manager import ViewTextManager
from improvisation_lab.service.base_practice_service import PitchResult


class MockViewTextManager(ViewTextManager):
    """Mock implementation of ViewTextManager for testing."""

    def __init__(self):
        super().__init__()

    def update_phrase_text(self, current_phrase_idx: int, phrases: Optional[List]):
        pass


class TestViewTextManager:

    @pytest.fixture
    def init_module(self):
        self.text_manager = MockViewTextManager()

    @pytest.mark.usefixtures("init_module")
    def test_initialize_text(self):
        self.text_manager.initialize_text()
        assert self.text_manager.phrase_text == "No phrase data"
        assert self.text_manager.result_text == "Ready to start... (waiting for audio)"

    @pytest.mark.usefixtures("init_module")
    def test_terminate_text(self):
        self.text_manager.terminate_text()
        assert self.text_manager.phrase_text == "Session Stopped"
        assert self.text_manager.result_text == "Practice ended"

    @pytest.mark.usefixtures("init_module")
    def test_set_waiting_for_audio(self):
        self.text_manager.set_waiting_for_audio()
        assert self.text_manager.result_text == "Waiting for audio..."

    @pytest.mark.usefixtures("init_module")
    def test_update_pitch_result(self):
        pitch_result = PitchResult(
            target_note="C", current_base_note="A", is_correct=False, remaining_time=2.5
        )
        # Test without auto advance
        self.text_manager.update_pitch_result(pitch_result)
        assert (
            self.text_manager.result_text
            == "Target: C | Your note: A | Remaining: 2.5s"
        )

        # Test with auto advance
        self.text_manager.update_pitch_result(pitch_result, is_auto_advance=True)
        assert self.text_manager.result_text == "Target: C | Your note: A"