|
4 | 4 | import moment from 'moment';
|
5 | 5 | import { Status } from '../src/Status';
|
6 | 6 | import { Task } from '../src/Task';
|
7 |
| -import { getSettings, updateSettings } from '../src/Settings'; |
| 7 | +import { getSettings, toggleFeature, updateSettings } from '../src/Settings'; |
| 8 | +import { Feature } from '../src/Feature'; |
8 | 9 |
|
9 | 10 | jest.mock('obsidian');
|
10 | 11 | window.moment = moment;
|
@@ -192,40 +193,36 @@ describe('parsing tags', () => {
|
192 | 193 | {
|
193 | 194 | markdownTask:
|
194 | 195 | '- [x] #someglobaltasktag this is a done task #tagone π 2021-09-12 β
2021-06-20',
|
195 |
| - expectedDescription: |
196 |
| - '#someglobaltasktag this is a done task #tagone', |
| 196 | + expectedDescription: 'this is a done task #tagone', |
197 | 197 | extractedTags: ['#tagone'],
|
198 | 198 | globalFilter: '#someglobaltasktag',
|
199 | 199 | },
|
200 | 200 | {
|
201 | 201 | markdownTask:
|
202 | 202 | '- [x] #someglobaltasktag this is a done task #tagone #tagtwo π 2021-09-12 β
2021-06-20',
|
203 |
| - expectedDescription: |
204 |
| - '#someglobaltasktag this is a done task #tagone #tagtwo', |
| 203 | + expectedDescription: 'this is a done task #tagone #tagtwo', |
205 | 204 | extractedTags: ['#tagone', '#tagtwo'],
|
206 | 205 | globalFilter: '#someglobaltasktag',
|
207 | 206 | },
|
208 | 207 | {
|
209 | 208 | markdownTask:
|
210 | 209 | '- [ ] #someglobaltasktag this is a normal task #tagone π 2021-09-12 β
2021-06-20',
|
211 |
| - expectedDescription: |
212 |
| - '#someglobaltasktag this is a normal task #tagone', |
| 210 | + expectedDescription: 'this is a normal task #tagone', |
213 | 211 | extractedTags: ['#tagone'],
|
214 | 212 | globalFilter: '#someglobaltasktag',
|
215 | 213 | },
|
216 | 214 | {
|
217 | 215 | markdownTask:
|
218 | 216 | '- [ ] #someglobaltasktag this is a normal task #tagone #tagtwo π 2021-09-12 β
2021-06-20',
|
219 |
| - expectedDescription: |
220 |
| - '#someglobaltasktag this is a normal task #tagone #tagtwo', |
| 217 | + expectedDescription: 'this is a normal task #tagone #tagtwo', |
221 | 218 | extractedTags: ['#tagone', '#tagtwo'],
|
222 | 219 | globalFilter: '#someglobaltasktag',
|
223 | 220 | },
|
224 | 221 | {
|
225 | 222 | markdownTask:
|
226 | 223 | '- [ ] #someglobaltasktag this is a normal task #tagone #tag/with/depth #tagtwo π 2021-09-12 β
2021-06-20',
|
227 | 224 | expectedDescription:
|
228 |
| - '#someglobaltasktag this is a normal task #tagone #tag/with/depth #tagtwo', |
| 225 | + 'this is a normal task #tagone #tag/with/depth #tagtwo', |
229 | 226 | extractedTags: ['#tagone', '#tag/with/depth', '#tagtwo'],
|
230 | 227 | globalFilter: '#someglobaltasktag',
|
231 | 228 | },
|
@@ -275,6 +272,13 @@ describe('parsing tags', () => {
|
275 | 272 | );
|
276 | 273 | });
|
277 | 274 |
|
| 275 | +type GlobalFilterParsingExpectations = { |
| 276 | + location: string; |
| 277 | + scenario: string; |
| 278 | + initialTask: string; |
| 279 | + expectedTask: string; |
| 280 | +}; |
| 281 | + |
278 | 282 | describe('to string', () => {
|
279 | 283 | it('retains the block link', () => {
|
280 | 284 | // Arrange
|
@@ -311,6 +315,77 @@ describe('to string', () => {
|
311 | 315 | // Assert
|
312 | 316 | expect(task.toFileLineString()).toStrictEqual(line);
|
313 | 317 | });
|
| 318 | + |
| 319 | + test.each<GlobalFilterParsingExpectations>([ |
| 320 | + { |
| 321 | + location: 'append', |
| 322 | + scenario: 'at front', |
| 323 | + initialTask: |
| 324 | + '- [x] #globalfilter this is a done task #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 325 | + expectedTask: |
| 326 | + '- [x] this is a done task #tagone #journal/daily #globalfilter π
2021-09-12 β
2021-06-20', |
| 327 | + }, |
| 328 | + { |
| 329 | + location: 'append', |
| 330 | + scenario: 'at end', |
| 331 | + initialTask: |
| 332 | + '- [x] this is a done task #tagone #journal/daily #globalfilter π
2021-09-12 β
2021-06-20', |
| 333 | + expectedTask: |
| 334 | + '- [x] this is a done task #tagone #journal/daily #globalfilter π
2021-09-12 β
2021-06-20', |
| 335 | + }, |
| 336 | + { |
| 337 | + location: 'append', |
| 338 | + scenario: 'in middle', |
| 339 | + initialTask: |
| 340 | + '- [x] this is a done task #globalfilter #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 341 | + expectedTask: |
| 342 | + '- [x] this is a done task #tagone #journal/daily #globalfilter π
2021-09-12 β
2021-06-20', |
| 343 | + }, |
| 344 | + { |
| 345 | + location: 'prepend', |
| 346 | + scenario: 'at front', |
| 347 | + initialTask: |
| 348 | + '- [x] #globalfilter this is a done task #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 349 | + expectedTask: |
| 350 | + '- [x] #globalfilter this is a done task #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 351 | + }, |
| 352 | + { |
| 353 | + location: 'prepend', |
| 354 | + scenario: 'at end', |
| 355 | + initialTask: |
| 356 | + '- [x] this is a done task #tagone #journal/daily #globalfilter π
2021-09-12 β
2021-06-20', |
| 357 | + expectedTask: |
| 358 | + '- [x] #globalfilter this is a done task #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 359 | + }, |
| 360 | + { |
| 361 | + location: 'prepend', |
| 362 | + scenario: 'in middle', |
| 363 | + initialTask: |
| 364 | + '- [x] this is a done task #globalfilter #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 365 | + expectedTask: |
| 366 | + '- [x] #globalfilter this is a done task #tagone #journal/daily π
2021-09-12 β
2021-06-20', |
| 367 | + }, |
| 368 | + ])( |
| 369 | + 'should $location global filter when $scenario', |
| 370 | + ({ location, initialTask, expectedTask }) => { |
| 371 | + // Arrange |
| 372 | + const originalSettings = getSettings(); |
| 373 | + updateSettings({ globalFilter: '#globalfilter' }); |
| 374 | + if (location === 'append') { |
| 375 | + toggleFeature(Feature.APPEND_GLOBAL_FILTER.internalName, true); |
| 376 | + } |
| 377 | + // Act |
| 378 | + const task = constructTaskFromLine(initialTask); |
| 379 | + |
| 380 | + // Assert |
| 381 | + expect(task).not.toBeNull(); |
| 382 | + expect(task?.toFileLineString()).toStrictEqual(expectedTask); |
| 383 | + |
| 384 | + // Cleanup |
| 385 | + updateSettings(originalSettings); |
| 386 | + toggleFeature(Feature.APPEND_GLOBAL_FILTER.internalName, false); |
| 387 | + }, |
| 388 | + ); |
314 | 389 | });
|
315 | 390 |
|
316 | 391 | describe('toggle done', () => {
|
|
0 commit comments