@@ -145,3 +145,161 @@ def test_list_all_flag(runner):
145145 result = runner .invoke (cli , ["list" , "--all" ])
146146 assert "Test task" in result .output
147147 assert "completed" in result .output .lower ()
148+
149+
150+ def test_import_md_basic (runner , tmp_path ):
151+ """Test import-md command with basic markdown file."""
152+ md_file = tmp_path / "tasks.md"
153+ md_file .write_text ("""
154+ # Tasks
155+
156+ - [ ] Task 1
157+ - [x] Task 2
158+ - [ ] Task 3
159+ """ )
160+
161+ with runner .isolated_filesystem ():
162+ runner .invoke (cli , ["init" ])
163+ result = runner .invoke (cli , ["import-md" , str (md_file )])
164+ assert result .exit_code == 0
165+ assert "Imported 3 task(s)" in result .output
166+ assert "Task 1" in result .output
167+ assert "Task 2" in result .output
168+ assert "Task 3" in result .output
169+
170+
171+ def test_import_md_without_init (runner , tmp_path ):
172+ """Test import-md command without initialization."""
173+ md_file = tmp_path / "tasks.md"
174+ md_file .write_text ("- [ ] Task 1" )
175+
176+ with runner .isolated_filesystem ():
177+ result = runner .invoke (cli , ["import-md" , str (md_file )])
178+ assert result .exit_code != 0
179+ assert "not initialized" in result .output .lower ()
180+
181+
182+ def test_import_md_file_not_found (runner ):
183+ """Test import-md command with non-existent file."""
184+ with runner .isolated_filesystem ():
185+ runner .invoke (cli , ["init" ])
186+ result = runner .invoke (cli , ["import-md" , "/non/existent/file.md" ])
187+ assert result .exit_code != 0
188+
189+
190+ def test_import_md_no_checkboxes (runner , tmp_path ):
191+ """Test import-md command with file without checkboxes."""
192+ md_file = tmp_path / "no_tasks.md"
193+ md_file .write_text ("""
194+ # Just some text
195+
196+ No checkbox items here.
197+ """ )
198+
199+ with runner .isolated_filesystem ():
200+ runner .invoke (cli , ["init" ])
201+ result = runner .invoke (cli , ["import-md" , str (md_file )])
202+ assert result .exit_code == 0
203+ assert "No checkbox items found" in result .output
204+
205+
206+ def test_import_md_skip_duplicates (runner , tmp_path ):
207+ """Test import-md command with --skip-duplicates flag."""
208+ md_file = tmp_path / "tasks.md"
209+ md_file .write_text ("""
210+ - [ ] Duplicate task
211+ - [ ] Unique task
212+ """ )
213+
214+ with runner .isolated_filesystem ():
215+ runner .invoke (cli , ["init" ])
216+ # Add a task manually first
217+ runner .invoke (cli , ["add" , "Duplicate task" ])
218+
219+ # Import with skip-duplicates
220+ result = runner .invoke (cli , ["import-md" , str (md_file ), "--skip-duplicates" ])
221+ assert result .exit_code == 0
222+ assert "Imported 1 task(s)" in result .output
223+ assert "Skipped 1 duplicate(s)" in result .output
224+
225+
226+ def test_import_md_dry_run (runner , tmp_path ):
227+ """Test import-md command with --dry-run flag."""
228+ md_file = tmp_path / "tasks.md"
229+ md_file .write_text ("""
230+ - [ ] Task 1
231+ - [ ] Task 2
232+ """ )
233+
234+ with runner .isolated_filesystem ():
235+ runner .invoke (cli , ["init" ])
236+ result = runner .invoke (cli , ["import-md" , str (md_file ), "--dry-run" ])
237+ assert result .exit_code == 0
238+ assert "Task 1" in result .output
239+ assert "Task 2" in result .output
240+ assert "Dry run - no tasks were imported" in result .output
241+
242+ # Verify tasks were not actually imported
243+ list_result = runner .invoke (cli , ["list" ])
244+ assert "No tasks found" in list_result .output
245+
246+
247+ def test_import_md_complex_file (runner , tmp_path ):
248+ """Test import-md with complex markdown file."""
249+ md_file = tmp_path / "complex.md"
250+ md_file .write_text ("""
251+ # Project Tasks
252+
253+ ## Phase 1
254+ - [x] Setup project
255+ - [ ] Write docs
256+
257+ ## Phase 2
258+ - [ ] Implement feature A
259+ - [ ] Sub-task 1
260+ - [ ] Sub-task 2
261+ - [ ] Implement feature B
262+
263+ Some random text here.
264+
265+ ## Phase 3
266+ - [ ] Deploy to production
267+ """ )
268+
269+ with runner .isolated_filesystem ():
270+ runner .invoke (cli , ["init" ])
271+ result = runner .invoke (cli , ["import-md" , str (md_file )])
272+ assert result .exit_code == 0
273+ assert "Imported 7 task(s)" in result .output
274+
275+ # Verify tasks are in storage
276+ list_result = runner .invoke (cli , ["list" , "--all" ])
277+ assert "Setup project" in list_result .output
278+ assert "Write docs" in list_result .output
279+ assert "Deploy to production" in list_result .output
280+
281+
282+ def test_import_md_preserves_status (runner , tmp_path ):
283+ """Test that import-md preserves task status (completed vs pending)."""
284+ md_file = tmp_path / "tasks.md"
285+ md_file .write_text ("""
286+ - [ ] Pending task
287+ - [x] Completed task
288+ - [X] Another completed task
289+ """ )
290+
291+ with runner .isolated_filesystem ():
292+ runner .invoke (cli , ["init" ])
293+ runner .invoke (cli , ["import-md" , str (md_file )])
294+
295+ # Check that completed tasks show up in --all but not in default list
296+ default_list = runner .invoke (cli , ["list" ])
297+ all_list = runner .invoke (cli , ["list" , "--all" ])
298+
299+ assert "Pending task" in default_list .output
300+ assert "Completed task" not in default_list .output
301+ assert "Another completed task" not in default_list .output
302+
303+ assert "Pending task" in all_list .output
304+ assert "Completed task" in all_list .output
305+ assert "Another completed task" in all_list .output
0 commit comments