summaryrefslogtreecommitdiff
path: root/tests/test_settings_dialog_structure.py
blob: 3c16238a6dcdabe8a9a7309699c12a365a4ab6b4 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""Tests for the settings dialog category structure and organization."""

from PySide6 import QtCore, QtWidgets

from tidal_dl_ng.ui.dialog_settings import Ui_DialogSettings


class TestSettingsDialogStructure:
    """Test the structural integrity of the settings dialog."""

    def test_dialog_has_proper_layout_hierarchy(self, qapp):
        """Test that the dialog has the correct layout hierarchy."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        # Check main layout
        main_layout = dialog.layout()
        assert main_layout is not None
        assert isinstance(main_layout, QtWidgets.QVBoxLayout)

    def test_categories_and_pages_match(self, qapp):
        """Test that the number of pages matches the expected categories."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        # We expect 5 categories/pages
        expected_categories = ["Flags", "Quality", "Numbers", "Paths & Formats", "Delimiters"]
        assert ui.sw_categories.count() == len(expected_categories)

    def test_all_pages_have_layouts(self, qapp):
        """Test that all pages in the stacked widget have proper layouts."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        for i in range(ui.sw_categories.count()):
            page = ui.sw_categories.widget(i)
            assert page is not None
            assert page.layout() is not None
            assert isinstance(page.layout(), QtWidgets.QVBoxLayout)

    def test_all_pages_have_group_boxes(self, qapp):
        """Test that all pages contain at least one group box."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        for i in range(ui.sw_categories.count()):
            page = ui.sw_categories.widget(i)
            group_boxes = page.findChildren(QtWidgets.QGroupBox)
            assert len(group_boxes) > 0, f"Page {i} should have at least one group box"


class TestSettingsFlagsPage:
    """Test the Flags page specifically."""

    def test_flags_page_is_first(self, qapp):
        """Test that the Flags page is at index 0."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.page_flags is not None
        assert ui.sw_categories.widget(0) == ui.page_flags

    def test_flags_page_has_correct_number_of_checkboxes(self, qapp):
        """Test that the Flags page has the expected number of checkboxes."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        # Count checkboxes in the flags page
        checkboxes = ui.page_flags.findChildren(QtWidgets.QCheckBox)
        assert len(checkboxes) == 14, "Flags page should have 14 checkboxes"

    def test_all_flags_checkboxes_accessible_via_ui(self, qapp):
        """Test that all flag checkboxes are accessible through the ui object."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        checkbox_names = [
            "cb_video_download",
            "cb_video_convert_mp4",
            "cb_lyrics_embed",
            "cb_lyrics_file",
            "cb_download_delay",
            "cb_extract_flac",
            "cb_metadata_cover_embed",
            "cb_cover_album_file",
            "cb_skip_existing",
            "cb_symlink_to_track",
            "cb_playlist_create",
            "cb_mark_explicit",
            "cb_use_primary_album_artist",
            "cb_download_dolby_atmos",
        ]

        for name in checkbox_names:
            checkbox = getattr(ui, name, None)
            assert checkbox is not None, f"Checkbox {name} not found"
            assert isinstance(checkbox, QtWidgets.QCheckBox)


class TestSettingsQualityPage:
    """Test the Quality page specifically."""

    def test_quality_page_is_second(self, qapp):
        """Test that the Quality page is at index 1."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.page_quality is not None
        assert ui.sw_categories.widget(1) == ui.page_quality

    def test_quality_page_has_combo_boxes(self, qapp):
        """Test that the Quality page has combo boxes."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        combos = ui.page_quality.findChildren(QtWidgets.QComboBox)
        assert len(combos) == 3, "Quality page should have 3 combo boxes"

    def test_quality_combo_boxes_have_labels(self, qapp):
        """Test that each combo box has associated labels."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        combo_label_pairs = [
            ("c_quality_audio", "l_quality_audio", "l_icon_quality_audio"),
            ("c_quality_video", "l_quality_video", "l_icon_quality_video"),
            ("c_metadata_cover_dimension", "l_metadata_cover_dimension", "l_icon_metadata_cover_dimension"),
        ]

        for combo_name, label_name, icon_label_name in combo_label_pairs:
            combo = getattr(ui, combo_name, None)
            label = getattr(ui, label_name, None)
            icon_label = getattr(ui, icon_label_name, None)

            assert combo is not None, f"ComboBox {combo_name} not found"
            assert label is not None, f"Label {label_name} not found"
            assert icon_label is not None, f"Icon label {icon_label_name} not found"


class TestSettingsNumbersPage:
    """Test the Numbers page specifically."""

    def test_numbers_page_is_third(self, qapp):
        """Test that the Numbers page is at index 2."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.page_numbers is not None
        assert ui.sw_categories.widget(2) == ui.page_numbers

    def test_numbers_page_has_spin_boxes(self, qapp):
        """Test that the Numbers page has spin boxes."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        spinboxes = ui.page_numbers.findChildren(QtWidgets.QSpinBox)
        assert len(spinboxes) == 2, "Numbers page should have 2 spin boxes"

    def test_spin_boxes_have_valid_ranges(self, qapp):
        """Test that spin boxes have appropriate min/max values."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        # Test album track num padding
        assert ui.sb_album_track_num_pad_min.maximum() == 4
        assert ui.sb_album_track_num_pad_min.minimum() >= 0

        # Test concurrent downloads
        assert ui.sb_downloads_concurrent_max.minimum() == 1
        assert ui.sb_downloads_concurrent_max.maximum() == 5


class TestSettingsPathsPage:
    """Test the Paths & Formats page specifically."""

    def test_paths_page_is_fourth(self, qapp):
        """Test that the Paths page is at index 3."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.page_paths is not None
        assert ui.sw_categories.widget(3) == ui.page_paths

    def test_paths_page_has_line_edits(self, qapp):
        """Test that the Paths page has line edits."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        line_edits = ui.page_paths.findChildren(QtWidgets.QLineEdit)
        assert len(line_edits) == 7, "Paths page should have 7 line edits"

    def test_paths_page_has_browse_buttons(self, qapp):
        """Test that the Paths page has browse buttons."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        buttons = ui.page_paths.findChildren(QtWidgets.QPushButton)
        # Should have at least 2 browse buttons (... buttons)
        assert len(buttons) >= 2, "Paths page should have at least 2 browse buttons"

    def test_path_line_edits_accessible(self, qapp):
        """Test that all path-related line edits are accessible."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        line_edit_names = [
            "le_download_base_path",
            "le_format_track",
            "le_format_video",
            "le_format_album",
            "le_format_playlist",
            "le_format_mix",
            "le_path_binary_ffmpeg",
        ]

        for name in line_edit_names:
            line_edit = getattr(ui, name, None)
            assert line_edit is not None, f"LineEdit {name} not found"
            assert isinstance(line_edit, QtWidgets.QLineEdit)


class TestSettingsDialogButtons:
    """Test the dialog button box."""

    def test_dialog_has_button_box(self, qapp):
        """Test that the dialog has a button box."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.bb_dialog is not None
        assert isinstance(ui.bb_dialog, QtWidgets.QDialogButtonBox)

    def test_button_box_has_ok_and_cancel(self, qapp):
        """Test that the button box has OK and Cancel buttons."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        buttons = ui.bb_dialog.standardButtons()
        assert QtWidgets.QDialogButtonBox.StandardButton.Ok in buttons
        assert QtWidgets.QDialogButtonBox.StandardButton.Cancel in buttons

    def test_button_box_orientation(self, qapp):
        """Test that the button box has horizontal orientation."""
        dialog = QtWidgets.QDialog()
        ui = Ui_DialogSettings()
        ui.setupUi(dialog)

        assert ui.bb_dialog.orientation() == QtCore.Qt.Orientation.Horizontal