"""Tests for DashboardDataStore.""" import pytest from pathlib import Path from unittest.mock import MagicMock, patch from development_hub.views.dashboard.data_store import DashboardDataStore from development_hub.project_discovery import Project class TestFileWatching: """Tests for file watching functionality.""" def test_watches_all_parent_directories(self, qtbot, tmp_path): """File watcher should watch all unique parent directories.""" # Create directory structure like global dashboard docs_dir = tmp_path / "docs" goals_dir = docs_dir / "goals" goals_dir.mkdir(parents=True) # Create test files todos_file = docs_dir / "todos.md" ideas_file = docs_dir / "ideas-and-exploration.md" goals_file = goals_dir / "goals.md" milestones_file = goals_dir / "milestones.md" todos_file.write_text("# TODOs\n") ideas_file.write_text("# Ideas\n") goals_file.write_text("# Goals\n") milestones_file.write_text("# Milestones\n") # Create data store with mocked paths project = MagicMock(spec=Project) project.key = "test-project" store = DashboardDataStore(project) # Manually set paths to our test files store._todos_path = todos_file store._goals_path = goals_file store._milestones_path = milestones_file store._ideas_path = ideas_file # Set up file watching store._setup_file_watching() # Check that both directories are being watched watched_dirs = store._file_watcher.directories() assert str(docs_dir) in watched_dirs assert str(goals_dir) in watched_dirs def test_watches_files_that_exist(self, qtbot, tmp_path): """File watcher should watch existing files.""" docs_dir = tmp_path / "docs" docs_dir.mkdir() todos_file = docs_dir / "todos.md" todos_file.write_text("# TODOs\n") project = MagicMock(spec=Project) project.key = "test-project" store = DashboardDataStore(project) store._todos_path = todos_file store._goals_path = docs_dir / "goals.md" # Doesn't exist store._milestones_path = None store._ideas_path = None store._setup_file_watching() watched_files = store._file_watcher.files() assert str(todos_file) in watched_files # Non-existent file should not be watched assert str(docs_dir / "goals.md") not in watched_files def test_ensure_file_watched_adds_missing(self, qtbot, tmp_path): """_ensure_file_watched adds files that aren't being watched.""" docs_dir = tmp_path / "docs" docs_dir.mkdir() todos_file = docs_dir / "todos.md" todos_file.write_text("# TODOs\n") project = MagicMock(spec=Project) project.key = "test-project" store = DashboardDataStore(project) store._todos_path = todos_file store._goals_path = None store._milestones_path = None store._ideas_path = None # Initially no watches assert str(todos_file) not in store._file_watcher.files() # Ensure should add it store._ensure_file_watched() assert str(todos_file) in store._file_watcher.files() assert str(docs_dir) in store._file_watcher.directories() class TestDateHandling: """Tests for dynamic date in save_ideas.""" def test_save_ideas_uses_current_date(self, qtbot, tmp_path): """save_ideas should use today's date, not a hardcoded one.""" from datetime import date docs_dir = tmp_path / "docs" docs_dir.mkdir() ideas_file = docs_dir / "ideas-and-exploration.md" project = MagicMock(spec=Project) project.key = "test-project" store = DashboardDataStore(project) store._ideas_path = ideas_file store._ideas_list = [] store.save_ideas() content = ideas_file.read_text() today = date.today().isoformat() assert f"updated: {today}" in content # Should NOT have the old hardcoded date assert "updated: 2026-01-08" not in content if __name__ == "__main__": pytest.main([__file__, "-v"])