242 lines
9.0 KiB
Python
242 lines
9.0 KiB
Python
"""
|
|
Test suite for manager JavaScript and CSS generation.
|
|
|
|
This test module validates that all manager classes can successfully generate
|
|
their JavaScript and CSS code without runtime errors.
|
|
"""
|
|
|
|
import unittest
|
|
import sys
|
|
import os
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
class TestManagerGeneration(unittest.TestCase):
|
|
"""Test class for validating manager JavaScript/CSS generation."""
|
|
|
|
def setUp(self):
|
|
"""Set up test fixtures before each test method."""
|
|
self.managers_tested = 0
|
|
self.total_js_chars = 0
|
|
self.total_css_chars = 0
|
|
|
|
def test_keyboard_shortcut_manager(self):
|
|
"""Test KeyboardShortcutManager JavaScript generation."""
|
|
try:
|
|
from keyboard_shortcuts import KeyboardShortcutManager
|
|
manager = KeyboardShortcutManager()
|
|
js = manager.get_shortcuts_js()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.total_js_chars += len(js)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ KeyboardShortcutManager: JS={len(js)} chars (no CSS method)')
|
|
|
|
except Exception as e:
|
|
self.fail(f'KeyboardShortcutManager failed: {e}')
|
|
|
|
def test_drag_drop_manager(self):
|
|
"""Test DragDropManager JavaScript and CSS generation."""
|
|
try:
|
|
from drag_drop import DragDropManager
|
|
manager = DragDropManager()
|
|
|
|
js = manager.get_drag_drop_js()
|
|
css = manager.get_css()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertIsInstance(css, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.assertGreater(len(css), 0)
|
|
|
|
self.total_js_chars += len(js)
|
|
self.total_css_chars += len(css)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ DragDropManager: JS={len(js)} chars, CSS={len(css)} chars')
|
|
|
|
except Exception as e:
|
|
self.fail(f'DragDropManager failed: {e}')
|
|
|
|
def test_accessibility_manager(self):
|
|
"""Test AccessibilityManager JavaScript and CSS generation."""
|
|
try:
|
|
from accessibility_features import AccessibilityManager
|
|
manager = AccessibilityManager()
|
|
|
|
js = manager.get_accessibility_js()
|
|
css = manager.get_css()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertIsInstance(css, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.assertGreater(len(css), 0)
|
|
|
|
self.total_js_chars += len(js)
|
|
self.total_css_chars += len(css)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ AccessibilityManager: JS={len(js)} chars, CSS={len(css)} chars')
|
|
|
|
except Exception as e:
|
|
self.fail(f'AccessibilityManager failed: {e}')
|
|
|
|
def test_user_preferences_manager(self):
|
|
"""Test UserPreferencesManager JavaScript and CSS generation."""
|
|
try:
|
|
from user_preferences import UserPreferencesManager
|
|
manager = UserPreferencesManager()
|
|
|
|
js = manager.get_preferences_js()
|
|
css = manager.get_css()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertIsInstance(css, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.assertGreater(len(css), 0)
|
|
|
|
self.total_js_chars += len(js)
|
|
self.total_css_chars += len(css)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ UserPreferencesManager: JS={len(js)} chars, CSS={len(css)} chars')
|
|
|
|
except Exception as e:
|
|
self.fail(f'UserPreferencesManager failed: {e}')
|
|
|
|
def test_advanced_search_manager(self):
|
|
"""Test AdvancedSearchManager JavaScript and CSS generation."""
|
|
try:
|
|
from advanced_search import AdvancedSearchManager
|
|
manager = AdvancedSearchManager()
|
|
|
|
js = manager.get_search_js()
|
|
css = manager.get_css()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertIsInstance(css, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.assertGreater(len(css), 0)
|
|
|
|
self.total_js_chars += len(js)
|
|
self.total_css_chars += len(css)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ AdvancedSearchManager: JS={len(js)} chars, CSS={len(css)} chars')
|
|
|
|
except Exception as e:
|
|
self.fail(f'AdvancedSearchManager failed: {e}')
|
|
|
|
def test_undo_redo_manager(self):
|
|
"""Test UndoRedoManager JavaScript and CSS generation."""
|
|
try:
|
|
from undo_redo_manager import UndoRedoManager
|
|
manager = UndoRedoManager()
|
|
|
|
js = manager.get_undo_redo_js()
|
|
css = manager.get_css()
|
|
|
|
self.assertIsInstance(js, str)
|
|
self.assertIsInstance(css, str)
|
|
self.assertGreater(len(js), 0)
|
|
self.assertGreater(len(css), 0)
|
|
|
|
self.total_js_chars += len(js)
|
|
self.total_css_chars += len(css)
|
|
self.managers_tested += 1
|
|
|
|
print(f'✓ UndoRedoManager: JS={len(js)} chars, CSS={len(css)} chars')
|
|
|
|
except Exception as e:
|
|
self.fail(f'UndoRedoManager failed: {e}')
|
|
|
|
def test_all_managers_comprehensive(self):
|
|
"""Comprehensive test to ensure all managers work together."""
|
|
expected_managers = 6 # Total number of managers we expect to test
|
|
|
|
# Run all individual tests first
|
|
self.test_keyboard_shortcut_manager()
|
|
self.test_drag_drop_manager()
|
|
self.test_accessibility_manager()
|
|
self.test_user_preferences_manager()
|
|
self.test_advanced_search_manager()
|
|
self.test_undo_redo_manager()
|
|
|
|
# Validate overall results
|
|
self.assertEqual(self.managers_tested, expected_managers)
|
|
self.assertGreater(self.total_js_chars, 0)
|
|
self.assertGreater(self.total_css_chars, 0)
|
|
|
|
print(f'\n=== COMPREHENSIVE TEST SUMMARY ===')
|
|
print(f'Managers tested: {self.managers_tested}/{expected_managers}')
|
|
print(f'Total JavaScript generated: {self.total_js_chars:,} characters')
|
|
print(f'Total CSS generated: {self.total_css_chars:,} characters')
|
|
print('🎉 All manager JavaScript/CSS generation tests passed!')
|
|
|
|
def tearDown(self):
|
|
"""Clean up after each test method."""
|
|
pass
|
|
|
|
|
|
class TestManagerMethods(unittest.TestCase):
|
|
"""Test class for validating specific manager methods."""
|
|
|
|
def test_keyboard_shortcuts_methods(self):
|
|
"""Test that KeyboardShortcutManager has required methods."""
|
|
try:
|
|
from keyboard_shortcuts import KeyboardShortcutManager
|
|
manager = KeyboardShortcutManager()
|
|
|
|
# Test that required methods exist
|
|
self.assertTrue(hasattr(manager, 'get_shortcuts_js'))
|
|
self.assertTrue(hasattr(manager, 'setEnabled'))
|
|
self.assertTrue(hasattr(manager, 'updateShortcuts'))
|
|
|
|
# Test method calls
|
|
self.assertIsNotNone(manager.get_shortcuts_js())
|
|
|
|
print('✓ KeyboardShortcutManager methods validated')
|
|
|
|
except Exception as e:
|
|
self.fail(f'KeyboardShortcutManager method test failed: {e}')
|
|
|
|
def test_screen_reader_methods(self):
|
|
"""Test that ScreenReaderSupportManager has required methods."""
|
|
try:
|
|
from screen_reader_support import ScreenReaderManager
|
|
manager = ScreenReaderManager()
|
|
|
|
# Test that required methods exist
|
|
self.assertTrue(hasattr(manager, 'get_screen_reader_js'))
|
|
self.assertTrue(hasattr(manager, 'enhanceFormElements'))
|
|
self.assertTrue(hasattr(manager, 'generateId'))
|
|
|
|
print('✓ ScreenReaderSupportManager methods validated')
|
|
|
|
except Exception as e:
|
|
self.fail(f'ScreenReaderSupportManager method test failed: {e}')
|
|
|
|
def test_user_preferences_initialization(self):
|
|
"""Test that UserPreferencesManager initializes correctly."""
|
|
try:
|
|
from user_preferences import UserPreferencesManager
|
|
|
|
# Test initialization without Flask app
|
|
manager = UserPreferencesManager()
|
|
self.assertTrue(hasattr(manager, 'preferences'))
|
|
self.assertIsInstance(manager.preferences, dict)
|
|
self.assertGreater(len(manager.preferences), 0)
|
|
|
|
print('✓ UserPreferencesManager initialization validated')
|
|
|
|
except Exception as e:
|
|
self.fail(f'UserPreferencesManager initialization test failed: {e}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# Configure test runner
|
|
unittest.main(verbosity=2, buffer=True) |