@@ -14,7 +14,7 @@ import {
1414 OnCompletionActionType ,
1515} from "../types/onCompletion" ;
1616import { Task } from "../types/task" ;
17- import { createMockPlugin } from "./mockUtils" ;
17+ import { createMockPlugin , createMockApp } from "./mockUtils" ;
1818import TaskProgressBarPlugin from "../index" ;
1919
2020// Mock vault
@@ -34,22 +34,39 @@ const mockApp = {
3434describe ( "ArchiveActionExecutor - Markdown Tasks" , ( ) => {
3535 let executor : ArchiveActionExecutor ;
3636 let mockContext : OnCompletionExecutionContext ;
37- let mockPlugin : TaskProgressBarPlugin ;
37+ let mockPlugin : any ;
38+ let mockApp : any ;
3839
3940 beforeEach ( ( ) => {
4041 executor = new ArchiveActionExecutor ( ) ;
42+
43+ // Create fresh mock instances for each test
4144 mockPlugin = createMockPlugin ( ) ;
45+ mockApp = createMockApp ( ) ;
4246
4347 // Reset mocks
4448 jest . clearAllMocks ( ) ;
4549
4650 // Reset all vault method mocks to default behavior
47- mockVault . getAbstractFileByPath . mockReset ( ) ;
48- mockVault . getFileByPath . mockReset ( ) ;
49- mockVault . read . mockReset ( ) ;
50- mockVault . modify . mockReset ( ) ;
51- mockVault . create . mockReset ( ) ;
52- mockVault . createFolder . mockReset ( ) ;
51+ mockApp . vault . getAbstractFileByPath . mockReset ( ) ;
52+ mockApp . vault . getFileByPath . mockReset ( ) ;
53+ mockApp . vault . read . mockReset ( ) ;
54+ mockApp . vault . modify . mockReset ( ) ;
55+ mockApp . vault . create . mockReset ( ) ;
56+ mockApp . vault . createFolder . mockReset ( ) ;
57+
58+ // Mock the current date to ensure consistent test results
59+ jest . spyOn ( Date . prototype , "toISOString" ) . mockReturnValue (
60+ "2025-07-07T00:00:00.000Z"
61+ ) ;
62+ jest . spyOn ( Date . prototype , "getFullYear" ) . mockReturnValue ( 2025 ) ;
63+ jest . spyOn ( Date . prototype , "getMonth" ) . mockReturnValue ( 6 ) ; // July (0-indexed)
64+ jest . spyOn ( Date . prototype , "getDate" ) . mockReturnValue ( 7 ) ;
65+ } ) ;
66+
67+ afterEach ( ( ) => {
68+ // Restore date mocks
69+ jest . restoreAllMocks ( ) ;
5370 } ) ;
5471
5572 describe ( "Markdown Task Archiving" , ( ) => {
@@ -82,7 +99,7 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
8299
83100 // Mock source file
84101 const mockSourceFile = { path : "source.md" } ;
85- mockVault . getFileByPath
102+ mockApp . vault . getFileByPath
86103 . mockReturnValueOnce ( mockSourceFile ) // Source file
87104 . mockReturnValueOnce ( { path : "Archive/Completed Tasks.md" } ) ; // Archive file
88105
@@ -91,11 +108,11 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
91108 "# Tasks\n\n- [ ] Other task\n- [x] Task with onCompletion 🏁 archive:done.md\n- [ ] Another task" ;
92109 const archiveContent = "# Archive\n\n## Completed Tasks\n\n" ;
93110
94- mockVault . read
111+ mockApp . vault . read
95112 . mockResolvedValueOnce ( sourceContent ) // Read source
96113 . mockResolvedValueOnce ( archiveContent ) ; // Read archive
97114
98- mockVault . modify . mockResolvedValue ( undefined ) ;
115+ mockApp . vault . modify . mockResolvedValue ( undefined ) ;
99116
100117 const result = await executor . execute ( mockContext , archiveConfig ) ;
101118
@@ -105,17 +122,17 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
105122 ) ;
106123
107124 // Verify source file was updated (task removed)
108- const sourceModifyCall = mockVault . modify . mock . calls [ 0 ] ;
125+ const sourceModifyCall = mockApp . vault . modify . mock . calls [ 0 ] ;
109126 const updatedSourceContent = sourceModifyCall [ 1 ] ;
110127 expect ( updatedSourceContent ) . toBe (
111128 "# Tasks\n\n- [ ] Other task\n- [ ] Another task"
112129 ) ;
113130
114131 // Verify archive file was updated (task added without onCompletion metadata)
115- const archiveModifyCall = mockVault . modify . mock . calls [ 1 ] ;
132+ const archiveModifyCall = mockApp . vault . modify . mock . calls [ 1 ] ;
116133 const updatedArchiveContent = archiveModifyCall [ 1 ] ;
117134 expect ( updatedArchiveContent ) . toContain (
118- "- [x] Task with onCompletion ✅ 2025-07-04 (from source.md)"
135+ "- [x] Task with onCompletion ✅ 2025-07-07 (from source.md)"
119136 ) ;
120137 expect ( updatedArchiveContent ) . not . toContain ( "🏁" ) ;
121138 expect ( updatedArchiveContent ) . not . toContain ( "archive:done.md" ) ;
@@ -150,7 +167,7 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
150167
151168 // Mock source file
152169 const mockSourceFile = { path : "source.md" } ;
153- mockVault . getFileByPath
170+ mockApp . vault . getFileByPath
154171 . mockReturnValueOnce ( mockSourceFile ) // Source file
155172 . mockReturnValueOnce ( { path : "Archive/Completed Tasks.md" } ) ; // Archive file
156173
@@ -159,21 +176,21 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
159176 "# Tasks\n- [ ] Incomplete task to archive 🏁 archive\n- [ ] Other task" ;
160177 const archiveContent = "# Archive\n\n## Completed Tasks\n\n" ;
161178
162- mockVault . read
179+ mockApp . vault . read
163180 . mockResolvedValueOnce ( sourceContent ) // Read source
164181 . mockResolvedValueOnce ( archiveContent ) ; // Read archive
165182
166- mockVault . modify . mockResolvedValue ( undefined ) ;
183+ mockApp . vault . modify . mockResolvedValue ( undefined ) ;
167184
168185 const result = await executor . execute ( mockContext , archiveConfig ) ;
169186
170187 expect ( result . success ) . toBe ( true ) ;
171188
172189 // Verify archive file contains completed task without onCompletion metadata
173- const archiveModifyCall = mockVault . modify . mock . calls [ 1 ] ;
190+ const archiveModifyCall = mockApp . vault . modify . mock . calls [ 1 ] ;
174191 const updatedArchiveContent = archiveModifyCall [ 1 ] ;
175192 expect ( updatedArchiveContent ) . toContain (
176- "- [x] Incomplete task to archive ✅ 2025-07-04 (from source.md)"
193+ "- [x] Incomplete task to archive ✅ 2025-07-07 (from source.md)"
177194 ) ;
178195 expect ( updatedArchiveContent ) . not . toContain ( "- [ ]" ) ; // Should not contain incomplete checkbox
179196 expect ( updatedArchiveContent ) . not . toContain ( "🏁" ) ;
@@ -208,7 +225,7 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
208225
209226 // Mock source file
210227 const mockSourceFile = { path : "source.md" } ;
211- mockVault . getFileByPath
228+ mockApp . vault . getFileByPath
212229 . mockReturnValueOnce ( mockSourceFile ) // Source file
213230 . mockReturnValueOnce ( { path : "Archive/Completed Tasks.md" } ) ; // Archive file
214231
@@ -217,21 +234,21 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
217234 "- [x] Task with dataview onCompletion [onCompletion:: archive:done.md]" ;
218235 const archiveContent = "# Archive\n\n## Completed Tasks\n\n" ;
219236
220- mockVault . read
237+ mockApp . vault . read
221238 . mockResolvedValueOnce ( sourceContent ) // Read source
222239 . mockResolvedValueOnce ( archiveContent ) ; // Read archive
223240
224- mockVault . modify . mockResolvedValue ( undefined ) ;
241+ mockApp . vault . modify . mockResolvedValue ( undefined ) ;
225242
226243 const result = await executor . execute ( mockContext , archiveConfig ) ;
227244
228245 expect ( result . success ) . toBe ( true ) ;
229246
230247 // Verify archive file contains task without dataview onCompletion metadata
231- const archiveModifyCall = mockVault . modify . mock . calls [ 1 ] ;
248+ const archiveModifyCall = mockApp . vault . modify . mock . calls [ 1 ] ;
232249 const updatedArchiveContent = archiveModifyCall [ 1 ] ;
233250 expect ( updatedArchiveContent ) . toContain (
234- "- [x] Task with dataview onCompletion ✅ 2025-07-04 (from source.md)"
251+ "- [x] Task with dataview onCompletion ✅ 2025-07-07 (from source.md)"
235252 ) ;
236253 expect ( updatedArchiveContent ) . not . toContain ( "[onCompletion::" ) ;
237254 expect ( updatedArchiveContent ) . not . toContain ( "archive:done.md" ) ;
@@ -267,7 +284,7 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
267284
268285 // Mock source file
269286 const mockSourceFile = { path : "source.md" } ;
270- mockVault . getFileByPath
287+ mockApp . vault . getFileByPath
271288 . mockReturnValueOnce ( mockSourceFile ) // Source file
272289 . mockReturnValueOnce ( { path : "Archive/Completed Tasks.md" } ) ; // Archive file
273290
@@ -276,21 +293,21 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
276293 '- [x] Task with JSON onCompletion 🏁 {"type": "archive", "archiveFile": "custom.md"}' ;
277294 const archiveContent = "# Archive\n\n## Completed Tasks\n\n" ;
278295
279- mockVault . read
296+ mockApp . vault . read
280297 . mockResolvedValueOnce ( sourceContent ) // Read source
281298 . mockResolvedValueOnce ( archiveContent ) ; // Read archive
282299
283- mockVault . modify . mockResolvedValue ( undefined ) ;
300+ mockApp . vault . modify . mockResolvedValue ( undefined ) ;
284301
285302 const result = await executor . execute ( mockContext , archiveConfig ) ;
286303
287304 expect ( result . success ) . toBe ( true ) ;
288305
289306 // Verify archive file contains task without JSON onCompletion metadata
290- const archiveModifyCall = mockVault . modify . mock . calls [ 1 ] ;
307+ const archiveModifyCall = mockApp . vault . modify . mock . calls [ 1 ] ;
291308 const updatedArchiveContent = archiveModifyCall [ 1 ] ;
292309 expect ( updatedArchiveContent ) . toContain (
293- "- [x] Task with JSON onCompletion ✅ 2025-07-04 (from source.md)"
310+ "- [x] Task with JSON onCompletion ✅ 2025-07-07 (from source.md)"
294311 ) ;
295312 expect ( updatedArchiveContent ) . not . toContain ( "🏁" ) ;
296313 expect ( updatedArchiveContent ) . not . toContain ( '{"type": "archive"' ) ;
@@ -324,7 +341,7 @@ describe("ArchiveActionExecutor - Markdown Tasks", () => {
324341 } ;
325342
326343 // Mock source file not found
327- mockVault . getFileByPath . mockReturnValue ( null ) ;
344+ mockApp . vault . getFileByPath . mockReturnValue ( null ) ;
328345
329346 const result = await executor . execute ( mockContext , archiveConfig ) ;
330347
0 commit comments