|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +"""Unit- und Contract-Tests für UI-, UX-, Accessibility- und Sprach-Qualität in CodeBox.""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +from PySide6.QtWidgets import QApplication |
| 7 | + |
| 8 | +from ui.main_window import MainWindow |
| 9 | +from ui.settings_dialog import SettingsDialog |
| 10 | +from ui.shortcuts_dialog import ShortcutsDialog, SHORTCUTS_DATA |
| 11 | +from ui.plugins_dialog import PluginsDialog |
| 12 | +from ui.problems_panel import ProblemsPanel |
| 13 | +from core.tabs import TabWidget |
| 14 | +from core.output import OutputPanel |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture(scope="module") |
| 18 | +def qapp(): |
| 19 | + app = QApplication.instance() |
| 20 | + if app is None: |
| 21 | + app = QApplication([]) |
| 22 | + yield app |
| 23 | + |
| 24 | + |
| 25 | +def test_main_window_toolbar_ux_and_a11y(qapp): |
| 26 | + """Prüft Tooltips, StatusTips und Barrierefreiheit der Haupt-Toolbar.""" |
| 27 | + window = MainWindow() |
| 28 | + try: |
| 29 | + # Toolbar Aktionen |
| 30 | + assert window.action_new.text() == "Neu" |
| 31 | + assert window.action_new.toolTip() == "Neue Datei erstellen (Ctrl+N)" |
| 32 | + assert window.action_new.statusTip() == "Erstellt eine neue leere Datei" |
| 33 | + assert len(window.action_new.whatsThis()) > 5 |
| 34 | + |
| 35 | + assert window.action_open.text() == "Öffnen" |
| 36 | + assert window.action_open.toolTip() == "Datei öffnen (Ctrl+O)" |
| 37 | + assert window.action_open.statusTip() == "Öffnet eine bestehende Datei von der Festplatte" |
| 38 | + assert len(window.action_open.whatsThis()) > 5 |
| 39 | + |
| 40 | + assert window.action_save.text() == "Speichern" |
| 41 | + assert window.action_save.toolTip() == "Aktuelle Datei speichern (Ctrl+S)" |
| 42 | + assert window.action_save.statusTip() == "Speichert die aktive Datei auf die Festplatte" |
| 43 | + assert len(window.action_save.whatsThis()) > 5 |
| 44 | + |
| 45 | + assert window.action_run.text() == "Ausführen" |
| 46 | + assert window.action_run.toolTip() == "Aktuelle Datei ausführen (F5)" |
| 47 | + assert window.action_run.statusTip() == "Führt das aktuelle Skript oder Programm aus" |
| 48 | + assert len(window.action_run.whatsThis()) > 5 |
| 49 | + |
| 50 | + # Sprach-Combo |
| 51 | + assert "Syntax-Highlighting" in window.lang_combo.toolTip() |
| 52 | + assert window.lang_combo.accessibleName() == "Programmiersprache" |
| 53 | + assert len(window.lang_combo.accessibleDescription()) > 10 |
| 54 | + |
| 55 | + # Statusbar |
| 56 | + assert window.pos_label.accessibleName() == "Cursorposition" |
| 57 | + assert "Cursor-Position" in window.pos_label.toolTip() |
| 58 | + assert window.lang_label.accessibleName() == "Aktive Sprache" |
| 59 | + assert window.enc_label.accessibleName() == "Dateikodierung" |
| 60 | + assert window.enc_label.text() == "UTF-8" |
| 61 | + |
| 62 | + # Bottom Tabs |
| 63 | + assert window.bottom_tabs.accessibleName() == "Unteres Bedienpanel" |
| 64 | + assert window.bottom_tabs.tabToolTip(0) == "Programmausgabe und Fehlermeldungen anzeigen" |
| 65 | + assert window.bottom_tabs.tabToolTip(1) == "Integriertes Befehlszeilenterminal" |
| 66 | + assert window.bottom_tabs.tabToolTip(2) == "LSP- und Linter-Diagnosen und Fehlermeldungen" |
| 67 | + finally: |
| 68 | + window.close() |
| 69 | + |
| 70 | + |
| 71 | +def test_tab_widget_ux_tooltips_and_a11y(qapp, tmp_path): |
| 72 | + """Prüft Tab-Tooltips mit echtem Pfad und Accessible-Attribute.""" |
| 73 | + tabs = TabWidget() |
| 74 | + assert tabs.accessibleName() == "Editor-Tabs" |
| 75 | + assert "Reiterleiste" in tabs.accessibleDescription() |
| 76 | + |
| 77 | + # Leerer neuer Tab |
| 78 | + tab1 = tabs.new_tab() |
| 79 | + assert tabs.tabToolTip(0) == "Neues Dokument (ungespeichert)" |
| 80 | + |
| 81 | + # Datei-Tab mit Pfad |
| 82 | + test_file = tmp_path / "main.py" |
| 83 | + test_file.write_text("print('hello')", encoding="utf-8") |
| 84 | + tabs.open_file(test_file) |
| 85 | + assert tabs.tabToolTip(1) == str(test_file) |
| 86 | + |
| 87 | + # Nach Speichern aktualisiert |
| 88 | + tab1.file_path = tmp_path / "neu.py" |
| 89 | + tab1.save() |
| 90 | + tabs._update_tab_title(tab1) |
| 91 | + assert tabs.tabToolTip(0) == str(tab1.file_path) |
| 92 | + |
| 93 | + |
| 94 | +def test_settings_dialog_ux_and_a11y(qapp): |
| 95 | + """Prüft Tooltips und AccessibleNames aller Steuerelemente im Einstellungsdialog.""" |
| 96 | + dialog = SettingsDialog() |
| 97 | + assert dialog.font_combo.accessibleName() == "Schriftart" |
| 98 | + assert len(dialog.font_combo.toolTip()) > 5 |
| 99 | + assert dialog.font_size_spin.accessibleName() == "Schriftgröße" |
| 100 | + assert len(dialog.font_size_spin.toolTip()) > 5 |
| 101 | + assert dialog.tab_size_spin.accessibleName() == "Tab-Breite" |
| 102 | + assert len(dialog.tab_size_spin.toolTip()) > 5 |
| 103 | + assert dialog.theme_combo.accessibleName() == "Farbschema" |
| 104 | + assert len(dialog.theme_combo.toolTip()) > 5 |
| 105 | + assert dialog.auto_save_cb.accessibleName() == "Dateien beim Ausführen automatisch speichern" |
| 106 | + assert len(dialog.auto_save_cb.toolTip()) > 5 |
| 107 | + assert dialog.minimap_cb.accessibleName() == "Minimap anzeigen" |
| 108 | + assert len(dialog.minimap_cb.toolTip()) > 5 |
| 109 | + |
| 110 | + |
| 111 | +def test_shortcuts_dialog_ux_and_a11y(qapp): |
| 112 | + """Prüft Suchfilter, Tabelle und Accessible-Attribute im ShortcutsDialog.""" |
| 113 | + dialog = ShortcutsDialog() |
| 114 | + assert dialog.search_input.accessibleName() == "Tastenkürzel filtern" |
| 115 | + assert len(dialog.search_input.toolTip()) > 5 |
| 116 | + assert dialog.table.accessibleName() == "Tastenkürzel-Tabelle" |
| 117 | + assert dialog.btn_close.accessibleName() == "Tastenkürzel-Übersicht schließen" |
| 118 | + |
| 119 | + # Filterung testen |
| 120 | + assert dialog.table.rowCount() == len(SHORTCUTS_DATA) |
| 121 | + dialog.filter_table("Ctrl+S") |
| 122 | + visible_rows = [r for r in range(dialog.table.rowCount()) if not dialog.table.isRowHidden(r)] |
| 123 | + assert len(visible_rows) >= 1 |
| 124 | + |
| 125 | + dialog.filter_table("") |
| 126 | + visible_rows_all = [r for r in range(dialog.table.rowCount()) if not dialog.table.isRowHidden(r)] |
| 127 | + assert len(visible_rows_all) == len(SHORTCUTS_DATA) |
| 128 | + |
| 129 | + |
| 130 | +def test_plugins_dialog_ux_and_a11y(qapp): |
| 131 | + """Prüft Tabelle, Detailsfeld, Buttons und Accessible-Attribute im PluginsDialog.""" |
| 132 | + dialog = PluginsDialog() |
| 133 | + assert dialog.table.accessibleName() == "Installierte Sprach-Plugins und Provider" |
| 134 | + assert dialog.details_text.accessibleName() == "Plugin-Details" |
| 135 | + assert dialog.btn_open_folder.accessibleName() == "Plugin-Ordner öffnen" |
| 136 | + assert dialog.btn_create.accessibleName() == "Neues JSON-Plugin erstellen" |
| 137 | + assert dialog.btn_reload.accessibleName() == "Plugins neu laden" |
| 138 | + assert dialog.btn_close.accessibleName() == "Plugin-Dialog schließen" |
| 139 | + |
| 140 | + |
| 141 | +def test_problems_and_output_panel_a11y(qapp): |
| 142 | + """Prüft Accessible-Attribute von ProblemsPanel und OutputPanel.""" |
| 143 | + problems = ProblemsPanel() |
| 144 | + assert problems.tree.accessibleName() == "Problems-Panel" |
| 145 | + |
| 146 | + output = OutputPanel() |
| 147 | + assert output.status_label.accessibleName() == "Ausführungsstatus" |
| 148 | + assert output.run_btn.accessibleName() == "Aktuelle Datei ausführen" |
| 149 | + assert output.stop_btn.accessibleName() == "Ausführung stoppen" |
| 150 | + assert output.clear_btn.accessibleName() == "Ausgabe leeren" |
| 151 | + assert output.output.accessibleName() == "Programmausgabe" |
0 commit comments