Files
AccountForger-neuerUpload/utils/modal_test.py
Claude Project Manager 04585e95b6 Initial commit
2025-08-01 23:50:28 +02:00

195 Zeilen
7.2 KiB
Python

"""
Modal System Test - Test-Funktionen für das Modal-System
"""
import logging
import time
from typing import Optional
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget
from PyQt5.QtCore import QTimer
from utils.modal_manager import ModalManager
from views.widgets.progress_modal import ProgressModal
from views.widgets.account_creation_modal import AccountCreationModal
from views.widgets.login_process_modal import LoginProcessModal
logger = logging.getLogger("modal_test")
class ModalTestWindow(QMainWindow):
"""Test-Fenster für Modal-System Tests"""
def __init__(self):
super().__init__()
self.setWindowTitle("AccountForger Modal System Test")
self.setGeometry(100, 100, 600, 400)
# Modal Manager
self.modal_manager = ModalManager(parent_window=self)
# Test UI
self.setup_ui()
def setup_ui(self):
"""Erstellt Test-UI"""
central_widget = QWidget()
self.setCentralWidget(central_widget)
layout = QVBoxLayout(central_widget)
# Test Buttons
btn_account_creation = QPushButton("Test Account Creation Modal")
btn_account_creation.clicked.connect(self.test_account_creation_modal)
layout.addWidget(btn_account_creation)
btn_login_process = QPushButton("Test Login Process Modal")
btn_login_process.clicked.connect(self.test_login_process_modal)
layout.addWidget(btn_login_process)
btn_generic_modal = QPushButton("Test Generic Progress Modal")
btn_generic_modal.clicked.connect(self.test_generic_modal)
layout.addWidget(btn_generic_modal)
btn_error_modal = QPushButton("Test Error Modal")
btn_error_modal.clicked.connect(self.test_error_modal)
layout.addWidget(btn_error_modal)
btn_modal_manager = QPushButton("Test Modal Manager")
btn_modal_manager.clicked.connect(self.test_modal_manager)
layout.addWidget(btn_modal_manager)
def test_account_creation_modal(self):
"""Testet Account Creation Modal"""
logger.info("Testing Account Creation Modal")
modal = AccountCreationModal(parent=self, platform="Instagram")
# Steps setzen
steps = [
"Browser wird vorbereitet",
"Formular wird ausgefüllt",
"Account wird erstellt",
"E-Mail wird verifiziert"
]
modal.set_steps(steps)
# Modal anzeigen
modal.show_platform_specific_process()
# Simuliere Steps
QTimer.singleShot(1000, lambda: modal.start_step("Browser wird vorbereitet"))
QTimer.singleShot(2000, lambda: modal.complete_step("Browser wird vorbereitet", "Formular wird ausgefüllt"))
QTimer.singleShot(3000, lambda: modal.start_step("Formular wird ausgefüllt"))
QTimer.singleShot(4000, lambda: modal.complete_step("Formular wird ausgefüllt", "Account wird erstellt"))
QTimer.singleShot(5000, lambda: modal.start_step("Account wird erstellt"))
QTimer.singleShot(6000, lambda: modal.complete_step("Account wird erstellt", "E-Mail wird verifiziert"))
QTimer.singleShot(7000, lambda: modal.start_step("E-Mail wird verifiziert"))
QTimer.singleShot(8000, lambda: modal.show_success({"username": "test_user", "platform": "Instagram"}))
def test_login_process_modal(self):
"""Testet Login Process Modal"""
logger.info("Testing Login Process Modal")
modal = LoginProcessModal(parent=self, platform="TikTok")
# Session Login testen
modal.show_session_login("test_account", "TikTok")
# Simuliere Login-Prozess
QTimer.singleShot(1000, lambda: modal.update_login_progress("browser_init", "Browser wird gestartet"))
QTimer.singleShot(2000, lambda: modal.update_login_progress("session_restore", "Session wird wiederhergestellt"))
QTimer.singleShot(3000, lambda: modal.update_login_progress("verification", "Login wird geprüft"))
QTimer.singleShot(4000, lambda: modal.show_session_restored())
def test_generic_modal(self):
"""Testet Generic Progress Modal"""
logger.info("Testing Generic Progress Modal")
modal = ProgressModal(parent=self, modal_type="verification")
modal.show_process()
# Simuliere Updates
QTimer.singleShot(1000, lambda: modal.update_status("Verbindung wird hergestellt...", "Server wird kontaktiert"))
QTimer.singleShot(2000, lambda: modal.update_status("Daten werden verarbeitet...", "Bitte warten"))
QTimer.singleShot(3000, lambda: modal.update_status("✅ Vorgang abgeschlossen!", "Erfolgreich"))
QTimer.singleShot(4000, lambda: modal.hide_process())
def test_error_modal(self):
"""Testet Error Modal"""
logger.info("Testing Error Modal")
modal = ProgressModal(parent=self, modal_type="generic")
modal.show_process()
# Nach kurzer Zeit Fehler anzeigen
QTimer.singleShot(1500, lambda: modal.show_error("Netzwerkfehler aufgetreten", auto_close_seconds=3))
def test_modal_manager(self):
"""Testet Modal Manager"""
logger.info("Testing Modal Manager")
# Zeige Account Creation Modal über Manager
self.modal_manager.show_modal(
'account_creation',
title="🔄 Test Account wird erstellt",
status="Modal Manager Test läuft...",
detail="Über ModalManager aufgerufen"
)
# Simuliere Updates über Manager
QTimer.singleShot(1000, lambda: self.modal_manager.update_modal_status(
'account_creation',
"Browser wird initialisiert...",
"Schritt 1 von 3"
))
QTimer.singleShot(2000, lambda: self.modal_manager.update_modal_status(
'account_creation',
"Formular wird ausgefüllt...",
"Schritt 2 von 3"
))
QTimer.singleShot(3000, lambda: self.modal_manager.update_modal_status(
'account_creation',
"Account wird finalisiert...",
"Schritt 3 von 3"
))
QTimer.singleShot(4000, lambda: self.modal_manager.update_modal_status(
'account_creation',
"✅ Account erfolgreich erstellt!",
"Test abgeschlossen"
))
QTimer.singleShot(5000, lambda: self.modal_manager.hide_modal('account_creation'))
def run_modal_test():
"""Führt den Modal-Test aus"""
import sys
# QApplication erstellen falls nicht vorhanden
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
# Test-Fenster erstellen
test_window = ModalTestWindow()
test_window.show()
# App ausführen
if hasattr(app, 'exec'):
return app.exec()
else:
return app.exec_()
if __name__ == "__main__":
# Logging konfigurieren
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
# Test ausführen
run_modal_test()