expect(component.textFilter).toBeNull()
}))
+ it('should ingest text filter content with relative dates that are not in quick list', fakeAsync(() => {
+ expect(component.dateAddedRelativeDate).toBeNull()
+ component.filterRules = [
+ {
+ rule_type: FILTER_FULLTEXT_QUERY,
+ value: 'added:[-2 week to now]',
+ },
+ ]
+ expect(component.dateAddedRelativeDate).toBeNull()
+ expect(component.textFilter).toEqual('added:[-2 week to now]')
+
+ expect(component.dateCreatedRelativeDate).toBeNull()
+ component.filterRules = [
+ {
+ rule_type: FILTER_FULLTEXT_QUERY,
+ value: 'created:[-2 week to now]',
+ },
+ ]
+ expect(component.dateCreatedRelativeDate).toBeNull()
+ expect(component.textFilter).toEqual('created:[-2 week to now]')
+ }))
+
it('should ingest text filter rules for more like', fakeAsync(() => {
const moreLikeSpy = jest.spyOn(documentService, 'get')
moreLikeSpy.mockReturnValue(of({ id: 1, title: 'Foo Bar' }))
])
}))
+ it('should leave relative dates not in quick list intact', fakeAsync(() => {
+ component.textFilterInput.nativeElement.value = 'created:[-2 week to now]'
+ component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
+ const textFieldTargetDropdown = fixture.debugElement.queryAll(
+ By.directive(NgbDropdownItem)
+ )[4]
+ textFieldTargetDropdown.triggerEventHandler('click')
+ fixture.detectChanges()
+ tick(400)
+ expect(component.filterRules).toEqual([
+ {
+ rule_type: FILTER_FULLTEXT_QUERY,
+ value: 'created:[-2 week to now]',
+ },
+ ])
+
+ component.textFilterInput.nativeElement.value = 'added:[-2 month to now]'
+ component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
+ fixture.detectChanges()
+ tick(400)
+ expect(component.filterRules).toEqual([
+ {
+ rule_type: FILTER_FULLTEXT_QUERY,
+ value: 'added:[-2 month to now]',
+ },
+ ])
+ }))
+
it('should convert user input to correct filter rules on date added after', fakeAsync(() => {
const dateAddedDropdown = fixture.debugElement.queryAll(
By.directive(DateDropdownComponent)
this.dateCreatedRelativeDate =
RELATIVE_DATE_QUERYSTRINGS.find(
(qS) => qS.dateQuery == match[1]
- )?.relativeDate
+ )?.relativeDate ?? null
}
}
)
+ if (this.dateCreatedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list
} else if (arg.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)) {
;[...arg.matchAll(RELATIVE_DATE_QUERY_REGEXP_ADDED)].forEach(
(match) => {
this.dateAddedRelativeDate =
RELATIVE_DATE_QUERYSTRINGS.find(
(qS) => qS.dateQuery == match[1]
- )?.relativeDate
+ )?.relativeDate ?? null
}
}
)
+ if (this.dateAddedRelativeDate === null) textQueryArgs.push(arg) // relative query not in the quick list
} else {
textQueryArgs.push(arg)
}
})
}
}
- if (
- this.dateCreatedRelativeDate == null &&
- this.dateAddedRelativeDate == null
- ) {
- const existingRule = filterRules.find(
- (fr) => fr.rule_type == FILTER_FULLTEXT_QUERY
- )
- if (
- existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_CREATED) ||
- existingRule?.value.match(RELATIVE_DATE_QUERY_REGEXP_ADDED)
- ) {
- // remove any existing date query
- existingRule.value = existingRule.value
- .replace(RELATIVE_DATE_QUERY_REGEXP_CREATED, '')
- .replace(RELATIVE_DATE_QUERY_REGEXP_ADDED, '')
- if (existingRule.value.replace(',', '').trim() === '') {
- // if its empty now, remove it entirely
- filterRules.splice(filterRules.indexOf(existingRule), 1)
- }
- }
- }
if (this.permissionsSelectionModel.ownerFilter == OwnerFilterType.SELF) {
filterRules.push({
rule_type: FILTER_OWNER,