"""Tests for the SetupWizardDialog.""" import pytest from pathlib import Path from unittest.mock import patch, MagicMock from development_hub.settings import Settings class TestSetupWizardStructure: """Test SetupWizardDialog structure without Qt app.""" @pytest.fixture def isolated_settings(self, tmp_path, monkeypatch): """Create isolated settings for testing.""" Settings._instance = None monkeypatch.setattr(Settings, "_settings_file", tmp_path / "settings.json") monkeypatch.setattr(Settings, "_session_file", tmp_path / "session.json") settings = Settings() yield settings Settings._instance = None def test_wizard_import_succeeds(self): """SetupWizardDialog can be imported.""" from development_hub.dialogs import SetupWizardDialog assert SetupWizardDialog is not None def test_wizard_has_expected_methods(self): """SetupWizardDialog has expected methods.""" from development_hub.dialogs import SetupWizardDialog # Check for key methods assert hasattr(SetupWizardDialog, "_create_welcome_page") assert hasattr(SetupWizardDialog, "_create_simple_mode_page") assert hasattr(SetupWizardDialog, "_create_docs_mode_page") assert hasattr(SetupWizardDialog, "_create_import_page") assert hasattr(SetupWizardDialog, "_finish_simple_mode") assert hasattr(SetupWizardDialog, "_finish_docs_mode") assert hasattr(SetupWizardDialog, "_finish_import") class TestWizardSettingsIntegration: """Test wizard settings integration logic.""" @pytest.fixture def isolated_settings(self, tmp_path, monkeypatch): """Create isolated settings for testing.""" Settings._instance = None monkeypatch.setattr(Settings, "_settings_file", tmp_path / "settings.json") monkeypatch.setattr(Settings, "_session_file", tmp_path / "session.json") settings = Settings() yield settings Settings._instance = None def test_simple_mode_sets_standalone_docs(self, isolated_settings, tmp_path): """Simple mode configuration sets standalone docs mode.""" settings = isolated_settings # Simulate what _finish_simple_mode does projects_path = tmp_path / "Projects" projects_path.mkdir() settings.default_project_path = projects_path settings.project_search_paths = [str(projects_path)] settings.docs_mode = "standalone" settings.set("setup_completed", True) assert settings.docs_mode == "standalone" assert settings.get("setup_completed") == True def test_docs_mode_sets_project_docs(self, isolated_settings, tmp_path): """Documentation mode configuration sets project-docs mode.""" settings = isolated_settings # Simulate what _finish_docs_mode does projects_path = tmp_path / "PycharmProjects" projects_path.mkdir() docusaurus_path = projects_path / "project-docs" docusaurus_path.mkdir() settings.default_project_path = projects_path settings.project_search_paths = [str(projects_path)] settings.docs_mode = "project-docs" settings.docusaurus_path = docusaurus_path settings.auto_start_docs_server = True settings.git_host_type = "gitea" settings.git_host_url = "https://gitea.example.com" settings.git_host_owner = "testuser" settings.set("setup_completed", True) assert settings.docs_mode == "project-docs" assert settings.docusaurus_path == docusaurus_path assert settings.auto_start_docs_server == True assert settings.is_git_configured == True assert settings.get("setup_completed") == True def test_import_workspace_integration(self, isolated_settings, tmp_path): """Import workspace correctly sets all values.""" import yaml settings = isolated_settings # Create a workspace file workspace = { "name": "Test Workspace", "version": 1, "paths": { "projects_root": str(tmp_path / "projects") }, "documentation": { "mode": "project-docs", "docusaurus_path": str(tmp_path / "docs"), "auto_start_server": False }, "git_hosting": { "type": "github", "url": "https://github.com", "owner": "myorg" } } workspace_path = tmp_path / "test-workspace.yaml" with open(workspace_path, "w") as f: yaml.dump(workspace, f) # Import (simulates _finish_import) results = settings.import_workspace(workspace_path) assert settings.project_search_paths == [str(tmp_path / "projects")] assert settings.docs_mode == "project-docs" assert settings.docusaurus_path == tmp_path / "docs" assert settings.auto_start_docs_server == False assert settings.git_host_type == "github" assert settings.git_host_owner == "myorg" assert settings.get("setup_completed") == True class TestWizardModeSelection: """Test wizard mode selection logic.""" def test_mode_values(self): """Test expected mode values.""" modes = ["simple", "docs", "import"] # These are the modes used in the wizard for mode in modes: assert isinstance(mode, str) def test_docs_mode_settings_values(self): """Test valid docs_mode setting values.""" valid_modes = ["auto", "standalone", "project-docs"] for mode in valid_modes: assert isinstance(mode, str) class TestWizardGitTypeHandling: """Test git type handling in wizard.""" @pytest.fixture def isolated_settings(self, tmp_path, monkeypatch): """Create isolated settings.""" Settings._instance = None monkeypatch.setattr(Settings, "_settings_file", tmp_path / "settings.json") monkeypatch.setattr(Settings, "_session_file", tmp_path / "session.json") settings = Settings() yield settings Settings._instance = None def test_github_configuration(self, isolated_settings): """GitHub configuration sets correct values.""" settings = isolated_settings settings.git_host_type = "github" settings.git_host_url = "https://github.com" settings.git_host_owner = "testuser" assert settings.is_git_configured == True assert settings.git_host_type == "github" def test_gitlab_configuration(self, isolated_settings): """GitLab configuration sets correct values.""" settings = isolated_settings settings.git_host_type = "gitlab" settings.git_host_url = "https://gitlab.com" settings.git_host_owner = "testuser" assert settings.is_git_configured == True assert settings.git_host_type == "gitlab" def test_gitea_configuration(self, isolated_settings): """Gitea configuration sets correct values.""" settings = isolated_settings settings.git_host_type = "gitea" settings.git_host_url = "https://gitea.example.com" settings.git_host_owner = "testuser" assert settings.is_git_configured == True assert settings.git_host_type == "gitea" def test_optional_git_in_simple_mode(self, isolated_settings, tmp_path): """Git is optional in simple mode.""" settings = isolated_settings # Simple mode without git settings.docs_mode = "standalone" settings.project_search_paths = [str(tmp_path)] settings.set("setup_completed", True) # Git not configured is OK assert settings.is_git_configured == False assert settings.get("setup_completed") == True if __name__ == "__main__": pytest.main([__file__, "-v"])