@@ -41,19 +41,55 @@ def test_config_default_values(self):
4141
4242 def test_is_note_index_page (self ):
4343 """Test is_note_index_page method."""
44- # Create a mock file
45- mock_file = Mock ()
46- # src_uri is relative to docs_dir, so 'index.md' not 'docs/index.md'
47- mock_file .src_uri = "index.md"
48-
49- # Test with default notes_root
50- result = self .plugin .is_note_index_page (mock_file )
51- self .assertTrue (result )
52-
53- # Test with non-index file
54- mock_file .src_uri = "some-other-page.md"
55- result = self .plugin .is_note_index_page (mock_file )
56- self .assertFalse (result )
44+ import tempfile
45+ import os
46+
47+ # Create a temporary directory structure
48+ with tempfile .TemporaryDirectory () as temp_dir :
49+ # Create notes_root directory
50+ notes_root = os .path .join (temp_dir , "docs" )
51+ os .makedirs (notes_root , exist_ok = True )
52+
53+ # Create index.md in notes_root
54+ index_file = os .path .join (notes_root , "index.md" )
55+ with open (index_file , "w" ) as f :
56+ f .write ("# Index" )
57+
58+ # Create a non-index file
59+ other_file = os .path .join (notes_root , "some-other-page.md" )
60+ with open (other_file , "w" ) as f :
61+ f .write ("# Other Page" )
62+
63+ # Create a subdirectory with its own index.md
64+ sub_dir = os .path .join (notes_root , "subdir" )
65+ os .makedirs (sub_dir , exist_ok = True )
66+ sub_index_file = os .path .join (sub_dir , "index.md" )
67+ with open (sub_index_file , "w" ) as f :
68+ f .write ("# Sub Index" )
69+
70+ # Set notes_root in config
71+ self .plugin .config .notes_root = notes_root
72+
73+ # Test 1: index.md directly under notes_root should return True
74+ mock_file = Mock ()
75+ mock_file .src_uri = "index.md"
76+ mock_file .abs_src_path = index_file
77+ result = self .plugin .is_note_index_page (mock_file )
78+ self .assertTrue (result , "index.md directly under notes_root should be True" )
79+
80+ # Test 2: non-index file should return False
81+ mock_file = Mock ()
82+ mock_file .src_uri = "some-other-page.md"
83+ mock_file .abs_src_path = other_file
84+ result = self .plugin .is_note_index_page (mock_file )
85+ self .assertFalse (result , "Non-index file should be False" )
86+
87+ # Test 3: index.md in subdirectory should return False
88+ mock_file = Mock ()
89+ mock_file .src_uri = "subdir/index.md"
90+ mock_file .abs_src_path = sub_index_file
91+ result = self .plugin .is_note_index_page (mock_file )
92+ self .assertFalse (result , "index.md in subdirectory should be False" )
5793
5894 def test_on_files (self ):
5995 """Test on_files event handler."""
0 commit comments