@@ -55,7 +55,7 @@ describe('searchString', () => {
55
55
] )
56
56
} )
57
57
58
- test ( 'multiple getText() segments ' , ( ) => {
58
+ test ( 'multiple texts ' , ( ) => {
59
59
const input = 'to:me foobar zoobar'
60
60
const parsed = parseAdvancedSearchQuery ( input )
61
61
@@ -104,7 +104,7 @@ describe('searchString', () => {
104
104
] )
105
105
} )
106
106
107
- test ( 'isNegated getText() ' , ( ) => {
107
+ test ( 'negated texts ' , ( ) => {
108
108
const input = 'hello -big -fat is:condition world'
109
109
const parsed = parseAdvancedSearchQuery ( input )
110
110
@@ -122,13 +122,13 @@ describe('searchString', () => {
122
122
123
123
test ( 'complex use case' , ( ) => {
124
124
const input =
125
- 'op1:value op1:value2 op2:"multi, \'word\', value" sometext -op3:value more text'
125
+ 'op1:value op1:value2 op2:"multi, \'word\', value" sometext -op3:value more - text'
126
126
const parsed = parseAdvancedSearchQuery ( input )
127
127
128
128
expect ( parsed . getTexts ( ) ) . toEqual ( [
129
129
{ value : 'sometext' , isNegated : false } ,
130
130
{ value : 'more' , isNegated : false } ,
131
- { value : 'text' , isNegated : false } ,
131
+ { value : 'text' , isNegated : true } ,
132
132
] )
133
133
expect ( getNumberOfKeywords ( parsed ) ) . toEqual ( 3 )
134
134
expect ( parsed . getKeyword ( 'op1' ) ) . toEqual ( [
@@ -162,24 +162,34 @@ describe('searchString', () => {
162
162
op3 : [ { value : 'value' , isNegated : true } ] ,
163
163
} )
164
164
expect ( parsed . toString ( ) ) . toEqual (
165
- 'op1:value,value2 op2:"multi, \'word\', value" -op3:value sometext more text'
165
+ 'op1:value,value2 op2:"multi, \'word\', value" -op3:value sometext more - text'
166
166
)
167
167
parsed . removeKeyword ( 'op1' )
168
168
expect ( parsed . toString ( ) ) . toEqual (
169
- 'op2:"multi, \'word\', value" -op3:value sometext more text'
169
+ 'op2:"multi, \'word\', value" -op3:value sometext more - text'
170
170
)
171
171
// Check once more to see if cached copy returns correctly.
172
172
expect ( parsed . toString ( ) ) . toEqual (
173
- 'op2:"multi, \'word\', value" -op3:value sometext more text'
173
+ 'op2:"multi, \'word\', value" -op3:value sometext more - text'
174
174
)
175
175
parsed . removeKeyword ( 'op3' , undefined , false )
176
176
expect ( parsed . toString ( ) ) . toEqual (
177
- 'op2:"multi, \'word\', value" -op3:value sometext more text'
177
+ 'op2:"multi, \'word\', value" -op3:value sometext more - text'
178
178
)
179
179
parsed . removeKeyword ( 'op3' , 'value' )
180
180
expect ( parsed . toString ( ) ) . toEqual (
181
- 'op2:"multi, \'word\', value" sometext more text'
181
+ 'op2:"multi, \'word\', value" sometext more - text'
182
182
)
183
+ parsed . removeText ( 'sometext' )
184
+ expect ( parsed . toString ( ) ) . toEqual ( 'op2:"multi, \'word\', value" more -text' )
185
+ parsed . removeText ( 'text' , false )
186
+ expect ( parsed . toString ( ) ) . toEqual ( 'op2:"multi, \'word\', value" more -text' )
187
+ parsed . removeText ( 'text' , true )
188
+ expect ( parsed . toString ( ) ) . toEqual ( 'op2:"multi, \'word\', value" more' )
189
+ parsed . removeTexts ( )
190
+ expect ( parsed . toString ( ) ) . toEqual ( 'op2:"multi, \'word\', value"' )
191
+ parsed . removeKeywords ( )
192
+ expect ( parsed . toString ( ) ) . toEqual ( '' )
183
193
} )
184
194
185
195
test ( 'several quoted strings' , ( ) => {
@@ -358,7 +368,7 @@ describe('searchString', () => {
358
368
expect ( parsed . toObject ( ) . keywords . foo . include ) . toEqual ( [ 'bar' ] )
359
369
} )
360
370
361
- test ( 'removeKeyword should remove only one case ' , ( ) => {
371
+ test ( 'removeKeyword should remove all occurences ' , ( ) => {
362
372
const input = '-foo:bar,baz,bar,bar,bar'
363
373
const parsed = parseAdvancedSearchQuery ( input )
364
374
@@ -388,4 +398,45 @@ describe('searchString', () => {
388
398
expect ( parsed . toObject ( ) . keywords . foo . include ) . toEqual ( [ 'bar' ] )
389
399
expect ( parsed . isDirty ) . toEqual ( false )
390
400
} )
401
+
402
+ test ( 'removeText simple case' , ( ) => {
403
+ const input = 'bar baz'
404
+ const parsed = parseAdvancedSearchQuery ( input )
405
+
406
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [ 'bar' , 'baz' ] )
407
+ parsed . removeText ( 'baz' )
408
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [ 'bar' ] )
409
+ } )
410
+
411
+ test ( 'removeText should remove all occurences' , ( ) => {
412
+ const input = 'bar baz bar bar bar'
413
+ const parsed = parseAdvancedSearchQuery ( input )
414
+
415
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [
416
+ 'bar' ,
417
+ 'baz' ,
418
+ 'bar' ,
419
+ 'bar' ,
420
+ 'bar' ,
421
+ ] )
422
+
423
+ parsed . removeText ( 'bar' )
424
+
425
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [ 'baz' ] )
426
+ } )
427
+
428
+ test ( 'removeText should be noop if entry is not found' , ( ) => {
429
+ const input = 'test -notest'
430
+ const parsed = parseAdvancedSearchQuery ( input )
431
+
432
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [ 'test' ] )
433
+ expect ( parsed . toObject ( ) . text . exclude ) . toEqual ( [ 'notest' ] )
434
+ expect ( parsed . toString ( ) ) . toEqual ( 'test -notest' )
435
+ expect ( parsed . isDirty ) . toEqual ( false )
436
+
437
+ parsed . removeText ( 'test' , true )
438
+
439
+ expect ( parsed . toObject ( ) . text . include ) . toEqual ( [ 'test' ] )
440
+ expect ( parsed . isDirty ) . toEqual ( false )
441
+ } )
391
442
} )
0 commit comments