2
2
* @jest -environment jsdom
3
3
*/
4
4
import moment from 'moment' ;
5
- import { Status , Task } from '../src/Task' ;
5
+ import { Priority , Status , Task } from '../src/Task' ;
6
6
import { getSettings , updateSettings } from '../src/config/Settings' ;
7
+ import { fromLine } from './TestHelpers' ;
7
8
8
9
jest . mock ( 'obsidian' ) ;
9
10
window . moment = moment ;
@@ -129,6 +130,30 @@ describe('parsing', () => {
129
130
) . toStrictEqual ( true ) ;
130
131
expect ( task ! . blockLink ) . toEqual ( ' ^my-precious' ) ;
131
132
} ) ;
133
+
134
+ it ( 'supports tag anywhere in the description and separates them correctly from signifier emojis' , ( ) => {
135
+ // Arrange
136
+ const line =
137
+ '- [ ] this is a task due 📅 2021-09-12 #inside_tag ⏫ #some/tags_with_underscore' ;
138
+
139
+ // Act
140
+ const task = fromLine ( {
141
+ line,
142
+ } ) ;
143
+
144
+ // Assert
145
+ expect ( task ) . not . toBeNull ( ) ;
146
+ expect ( task ! . description ) . toEqual (
147
+ 'this is a task due #inside_tag #some/tags_with_underscore' ,
148
+ ) ;
149
+ expect ( task ! . tags ) . toEqual ( [
150
+ '#inside_tag' ,
151
+ '#some/tags_with_underscore' ,
152
+ ] ) ;
153
+ expect ( task ! . dueDate ) . not . toBeNull ( ) ;
154
+ expect ( task ! . dueDate ! . isSame ( moment ( '2021-09-12' , 'YYYY-MM-DD' ) ) ) ;
155
+ expect ( task ! . priority == Priority . High ) ;
156
+ } ) ;
132
157
} ) ;
133
158
134
159
type TagParsingExpectations = {
@@ -153,9 +178,10 @@ describe('parsing tags', () => {
153
178
test . each < TagParsingExpectations > ( [
154
179
{
155
180
markdownTask :
156
- '- [x] this is a done task #tagone 🗓 2021-09-12 ✅ 2021-06-20' ,
157
- expectedDescription : 'this is a done task #tagone' ,
158
- extractedTags : [ '#tagone' ] ,
181
+ '- [x] this is a done task #tagone 🗓 2021-09-12 #another-tag ✅ 2021-06-20 #and_another' ,
182
+ expectedDescription :
183
+ 'this is a done task #tagone #another-tag #and_another' ,
184
+ extractedTags : [ '#tagone' , '#another-tag' , '#and_another' ] ,
159
185
globalFilter : '' ,
160
186
} ,
161
187
{
@@ -214,10 +240,10 @@ describe('parsing tags', () => {
214
240
} ,
215
241
{
216
242
markdownTask :
217
- '- [ ] #someglobaltasktag this is a normal task #tagone #tagtwo 🗓 2021-09-12 ✅ 2021-06-20' ,
243
+ '- [ ] #someglobaltasktag this is a normal task #tagone #tagtwo 🗓 2021-09-12 #tagthree ✅ 2021-06-20 #tagfour ' ,
218
244
expectedDescription :
219
- '#someglobaltasktag this is a normal task #tagone #tagtwo' ,
220
- extractedTags : [ '#tagone' , '#tagtwo' ] ,
245
+ '#someglobaltasktag this is a normal task #tagone #tagtwo #tagthree #tagfour ' ,
246
+ extractedTags : [ '#tagone' , '#tagtwo' , '#tagthree' , '#tagfour' ] ,
221
247
globalFilter : '#someglobaltasktag' ,
222
248
} ,
223
249
{
@@ -230,10 +256,18 @@ describe('parsing tags', () => {
230
256
} ,
231
257
{
232
258
markdownTask :
233
- '- [ ] Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare 🔁 every 4 weeks on Sunday ⏳ 2022-05-15' ,
259
+ '- [ ] Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare 🔁 every 4 weeks on Sunday ⏳ 2022-05-15 #context/more_context ' ,
234
260
expectedDescription :
235
- 'Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare' ,
236
- extractedTags : [ '#context/pc_clare' ] ,
261
+ 'Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare #context/more_context' ,
262
+ extractedTags : [ '#context/pc_clare' , '#context/more_context' ] ,
263
+ globalFilter : '' ,
264
+ } ,
265
+ {
266
+ markdownTask :
267
+ '- [ ] Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare ⏳ 2022-05-15 🔁 every 4 weeks on Sunday #context/more_context' ,
268
+ expectedDescription :
269
+ 'Export [Cloud Feedly feeds](http://cloud.feedly.com/#opml) #context/pc_clare #context/more_context' ,
270
+ extractedTags : [ '#context/pc_clare' , '#context/more_context' ] ,
237
271
globalFilter : '' ,
238
272
} ,
239
273
{
@@ -296,7 +330,7 @@ describe('to string', () => {
296
330
it ( 'retains the tags' , ( ) => {
297
331
// Arrange
298
332
const line =
299
- '- [x] this is a done task #tagone #journal/daily 📅 2021-09-12 ✅ 2021-06-20' ;
333
+ '- [x] this is a done task #tagone 📅 2021-09-12 ✅ 2021-06-20 #journal/daily ' ;
300
334
301
335
// Act
302
336
const task : Task = Task . fromLine ( {
@@ -308,7 +342,9 @@ describe('to string', () => {
308
342
} ) as Task ;
309
343
310
344
// Assert
311
- expect ( task . toFileLineString ( ) ) . toStrictEqual ( line ) ;
345
+ const expectedLine =
346
+ '- [x] this is a done task #tagone #journal/daily 📅 2021-09-12 ✅ 2021-06-20' ;
347
+ expect ( task . toFileLineString ( ) ) . toStrictEqual ( expectedLine ) ;
312
348
} ) ;
313
349
} ) ;
314
350
@@ -603,4 +639,74 @@ describe('toggle done', () => {
603
639
todaySpy . mockClear ( ) ;
604
640
} ,
605
641
) ;
642
+
643
+ it ( 'supports recurrence rule after a due date' , ( ) => {
644
+ // Arrange
645
+ const line = '- [ ] this is a task 🗓 2021-09-12 🔁 every day' ;
646
+ const path = 'this/is a path/to a/file.md' ;
647
+ const sectionStart = 1337 ;
648
+ const sectionIndex = 1209 ;
649
+ const precedingHeader = 'Eloquent Section' ;
650
+
651
+ // Act
652
+ const task = Task . fromLine ( {
653
+ line,
654
+ path,
655
+ sectionStart,
656
+ sectionIndex,
657
+ precedingHeader,
658
+ } ) ;
659
+
660
+ // Assert
661
+ expect ( task ) . not . toBeNull ( ) ;
662
+ expect ( task ! . dueDate ) . not . toBeNull ( ) ;
663
+ expect (
664
+ task ! . dueDate ! . isSame ( moment ( '2021-09-12' , 'YYYY-MM-DD' ) ) ,
665
+ ) . toStrictEqual ( true ) ;
666
+
667
+ const nextTask : Task = task ! . toggle ( ) [ 0 ] ;
668
+ expect ( {
669
+ nextDue : nextTask . dueDate ?. format ( 'YYYY-MM-DD' ) ,
670
+ nextScheduled : nextTask . scheduledDate ?. format ( 'YYYY-MM-DD' ) ,
671
+ nextStart : nextTask . startDate ?. format ( 'YYYY-MM-DD' ) ,
672
+ } ) . toMatchObject ( {
673
+ nextDue : '2021-09-13' ,
674
+ nextScheduled : undefined ,
675
+ nextStart : undefined ,
676
+ } ) ;
677
+ } ) ;
678
+
679
+ it ( 'supports parsing large number of values' , ( ) => {
680
+ // Arrange
681
+ const line =
682
+ '- [ ] Wobble ⏫ #tag1 ✅ 2022-07-02 #tag2 📅 2022-07-02 #tag3 ⏳ 2022-07-02 #tag4 🛫 2022-07-02 #tag5 🔁 every day #tag6 #tag7 #tag8 #tag9 #tag10' ;
683
+
684
+ // Act
685
+ const task = fromLine ( {
686
+ line,
687
+ } ) ;
688
+
689
+ // Assert
690
+ expect ( task ) . not . toBeNull ( ) ;
691
+ expect ( task ! . description ) . toEqual (
692
+ 'Wobble #tag1 #tag2 #tag3 #tag4 #tag5 #tag6 #tag7 #tag8 #tag9 #tag10' ,
693
+ ) ;
694
+ expect ( task ! . dueDate ! . isSame ( moment ( '022-07-02' , 'YYYY-MM-DD' ) ) ) ;
695
+ expect ( task ! . doneDate ! . isSame ( moment ( '022-07-02' , 'YYYY-MM-DD' ) ) ) ;
696
+ expect ( task ! . startDate ! . isSame ( moment ( '022-07-02' , 'YYYY-MM-DD' ) ) ) ;
697
+ expect ( task ! . scheduledDate ! . isSame ( moment ( '022-07-02' , 'YYYY-MM-DD' ) ) ) ;
698
+ expect ( task ! . priority == Priority . High ) ;
699
+ expect ( task ! . tags ) . toStrictEqual ( [
700
+ '#tag1' ,
701
+ '#tag2' ,
702
+ '#tag3' ,
703
+ '#tag4' ,
704
+ '#tag5' ,
705
+ '#tag6' ,
706
+ '#tag7' ,
707
+ '#tag8' ,
708
+ '#tag9' ,
709
+ '#tag10' ,
710
+ ] ) ;
711
+ } ) ;
606
712
} ) ;
0 commit comments