| name | cli-dashboard-testing |
| description | Test and validate the Textual-based CLI dashboard components. Use when building or debugging CLI interface components. Use when this capability is needed. |
| metadata | {"author":"crypticsaiyan"} |
CLI Dashboard Testing Skill
This skill provides comprehensive testing strategies for the Textual-based CLI dashboard.
Testing Strategy
1. Component Testing
Test each Textual component in isolation:
import pytest
from textual.widgets import Static
from cli.components.charts import ChartWidget
@pytest.mark.asyncio
async def test_chart_widget_rendering():
"""Test that chart widget renders correctly."""
widget = ChartWidget()
async with widget.app:
await widget.app._process_messages()
assert widget.is_mounted
assert widget.display
test_data = [1, 2, 3, 4, 5]
widget.update_data(test_data)
assert widget.data == test_data
2. Visual Regression Testing
Take snapshots of the dashboard for visual comparison:
from textual.pilot import Pilot
async def test_dashboard_snapshot(snap_compare):
"""Test dashboard visual appearance."""
from cli.dashboard_textual import AutoFinanceDashboard
app = AutoFinanceDashboard()
async with app.run_test() as pilot:
await pilot.pause()
assert await snap_compare(app)
3. Interaction Testing
Test keyboard shortcuts and user interactions:
async def test_keyboard_shortcuts():
"""Test keyboard shortcuts work correctly."""
from cli.dashboard_textual import AutoFinanceDashboard
app = AutoFinanceDashboard()
async with app.run_test() as pilot:
await pilot.press("ctrl+q")
assert app.is_exiting
await pilot.press("/")
assert app.search_box.has_focus
await pilot.press("tab")
assert app.next_widget_has_focus()
4. Data Fetching Tests
Mock API calls and test data updates:
from unittest.mock import patch, AsyncMock
@pytest.mark.asyncio
async def test_portfolio_data_fetch():
"""Test portfolio data fetching and display."""
from cli.components.portfolio import PortfolioWidget
mock_data = {
'total_value': 100000,
'positions': [
{'symbol': 'AAPL', 'value': 50000},
{'symbol': 'GOOGL', 'value': 50000}
]
}
with patch('cli.data.fetchers.fetch_portfolio_data',
new=AsyncMock(return_value=mock_data)):
widget = PortfolioWidget()
await widget.fetch_data()
assert widget.total_value == 100000
assert len(widget.positions) == 2
5. Performance Testing
Test rendering performance:
import time
async def test_chart_rendering_performance():
"""Test that charts render within acceptable time."""
from cli.components.charts import ChartWidget
widget = ChartWidget()
large_dataset = list(range(10000))
start = time.time()
widget.update_data(large_dataset)
await widget.refresh()
elapsed = time.time() - start
assert elapsed < 0.1
6. Error Handling Tests
Test error states and recovery:
@pytest.mark.asyncio
async def test_api_error_handling():
"""Test dashboard handles API errors gracefully."""
from cli.dashboard_textual import AutoFinanceDashboard
with patch('cli.data.fetchers.fetch_market_data',
side_effect=Exception("API Error")):
app = AutoFinanceDashboard()
async with app.run_test() as pilot:
await pilot.pause()
assert "Error" in app.screen.render()
await pilot.press("ctrl+r")
assert not app.is_frozen
Testing Checklist
Visual Tests
Interaction Tests
Data Tests
Error Tests
Performance Tests
Running Tests
pytest tests/test_cli*.py -v
pytest tests/test_cli*.py --cov=cli --cov-report=html
pytest tests/test_cli*.py --snapshot-update
pytest tests/test_cli*.py -k performance --benchmark
ptw tests/test_cli*.py
Manual Testing Script
Create a manual test script for comprehensive testing:
"""Manual testing script for CLI dashboard."""
import asyncio
from cli.dashboard_textual import AutoFinanceDashboard
async def manual_test():
"""Run manual test scenarios."""
app = AutoFinanceDashboard()
print("Starting manual test...")
print("1. Verify all widgets are visible")
print("2. Test keyboard shortcuts:")
print(" - Ctrl+Q: Quit")
print(" - /: Search")
print(" - Tab: Navigate")
print("3. Check data updates")
print("4. Test error handling (disconnect network)")
await app.run_async()
if __name__ == "__main__":
asyncio.run(manual_test())
Debugging Tips
- Use Textual Devtools:
textual console for live debugging
- Enable Debug Mode: Set
DEBUG=1 environment variable
- Log Rendering: Use
app.log() to debug render issues
- Inspect Widget Tree: Use
app.tree to see widget hierarchy
- Profile Performance: Use
textual --profile to find bottlenecks
Converted and distributed by TomeVault — claim your Tome and manage your conversions.