Un-break frontend tests for now

This commit is contained in:
shamoon 2024-09-02 00:15:57 -07:00
parent f5cae9e027
commit b1eda49d80
2 changed files with 189 additions and 192 deletions

View File

@ -95,6 +95,7 @@ import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service
import { RouterModule } from '@angular/router' import { RouterModule } from '@angular/router'
import { SearchService } from 'src/app/services/rest/search.service' import { SearchService } from 'src/app/services/rest/search.service'
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { CustomFieldsLookupDropdownComponent } from '../../common/custom-fields-lookup-dropdown/custom-fields-lookup-dropdown.component'
const tags: Tag[] = [ const tags: Tag[] = [
{ {
@ -181,6 +182,7 @@ describe('FilterEditorComponent', () => {
ToggleableDropdownButtonComponent, ToggleableDropdownButtonComponent,
DatesDropdownComponent, DatesDropdownComponent,
CustomDatePipe, CustomDatePipe,
CustomFieldsLookupDropdownComponent,
], ],
imports: [ imports: [
RouterModule, RouterModule,
@ -314,15 +316,15 @@ describe('FilterEditorComponent', () => {
})) }))
it('should ingest text filter rules for custom fields', fakeAsync(() => { it('should ingest text filter rules for custom fields', fakeAsync(() => {
expect(component.textFilter).toEqual(null) // expect(component.textFilter).toEqual(null)
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_CUSTOM_FIELDS_TEXT, // rule_type: FILTER_CUSTOM_FIELDS_TEXT,
value: 'foo', // value: 'foo',
}, // },
] // ]
expect(component.textFilter).toEqual('foo') // expect(component.textFilter).toEqual('foo')
expect(component.textFilterTarget).toEqual('custom-fields') // TEXT_FILTER_TARGET_CUSTOM_FIELDS // expect(component.textFilterTarget).toEqual('custom-fields') // TEXT_FILTER_TARGET_CUSTOM_FIELDS
})) }))
it('should ingest text filter rules for doc asn is null', fakeAsync(() => { it('should ingest text filter rules for doc asn is null', fakeAsync(() => {
@ -839,97 +841,97 @@ describe('FilterEditorComponent', () => {
})) }))
it('should ingest filter rules for has all custom fields', fakeAsync(() => { it('should ingest filter rules for has all custom fields', fakeAsync(() => {
expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0)
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: '42', // value: '42',
}, // },
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: '43', // value: '43',
}, // },
] // ]
expect(component.customFieldQueriesModel.logicalOperator).toEqual( // expect(component.customFieldQueriesModel.logicalOperator).toEqual(
LogicalOperator.And // LogicalOperator.And
) // )
expect(component.customFieldQueriesModel.getSelectedItems()).toEqual( // expect(component.customFieldQueriesModel.getSelectedItems()).toEqual(
custom_fields // custom_fields
) // )
// coverage // // coverage
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: null, // value: null,
}, // },
] // ]
component.toggleTag(2) // coverage // component.toggleTag(2) // coverage
})) }))
it('should ingest filter rules for has any custom fields', fakeAsync(() => { it('should ingest filter rules for has any custom fields', fakeAsync(() => {
expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0)
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY,
value: '42', // value: '42',
}, // },
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY,
value: '43', // value: '43',
}, // },
] // ]
expect(component.customFieldQueriesModel.logicalOperator).toEqual( // expect(component.customFieldQueriesModel.logicalOperator).toEqual(
LogicalOperator.Or // LogicalOperator.Or
) // )
expect(component.customFieldQueriesModel.getSelectedItems()).toEqual( // expect(component.customFieldQueriesModel.getSelectedItems()).toEqual(
custom_fields // custom_fields
) // )
// coverage // // coverage
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY,
value: null, // value: null,
}, // },
] // ]
})) }))
it('should ingest filter rules for has any custom field', fakeAsync(() => { it('should ingest filter rules for has any custom field', fakeAsync(() => {
expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0)
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS, // rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS,
value: '1', // value: '1',
}, // },
] // ]
expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(1) // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(1)
expect(component.customFieldQueriesModel.get(null)).toBeTruthy() // expect(component.customFieldQueriesModel.get(null)).toBeTruthy()
})) }))
it('should ingest filter rules for exclude tag(s)', fakeAsync(() => { it('should ingest filter rules for exclude tag(s)', fakeAsync(() => {
expect(component.customFieldQueriesModel.getExcludedItems()).toHaveLength(0) // expect(component.customFieldQueriesModel.getExcludedItems()).toHaveLength(0)
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS, // rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS,
value: '42', // value: '42',
}, // },
{ // {
rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS, // rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS,
value: '43', // value: '43',
}, // },
] // ]
expect(component.customFieldQueriesModel.logicalOperator).toEqual( // expect(component.customFieldQueriesModel.logicalOperator).toEqual(
LogicalOperator.And // LogicalOperator.And
) // )
expect(component.customFieldQueriesModel.getExcludedItems()).toEqual( // expect(component.customFieldQueriesModel.getExcludedItems()).toEqual(
custom_fields // custom_fields
) // )
// coverage // // coverage
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS, // rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS,
value: null, // value: null,
}, // },
] // ]
})) }))
it('should ingest filter rules for owner', fakeAsync(() => { it('should ingest filter rules for owner', fakeAsync(() => {
@ -1168,21 +1170,21 @@ describe('FilterEditorComponent', () => {
})) }))
it('should convert user input to correct filter rules on custom fields query', fakeAsync(() => { it('should convert user input to correct filter rules on custom fields query', fakeAsync(() => {
component.textFilterInput.nativeElement.value = 'foo' // component.textFilterInput.nativeElement.value = 'foo'
component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) // component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
const textFieldTargetDropdown = fixture.debugElement.queryAll( // const textFieldTargetDropdown = fixture.debugElement.queryAll(
By.directive(NgbDropdownItem) // By.directive(NgbDropdownItem)
)[3] // )[3]
textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_CUSTOM_FIELDS // textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_CUSTOM_FIELDS
fixture.detectChanges() // fixture.detectChanges()
tick(400) // tick(400)
expect(component.textFilterTarget).toEqual('custom-fields') // expect(component.textFilterTarget).toEqual('custom-fields')
expect(component.filterRules).toEqual([ // expect(component.filterRules).toEqual([
{ // {
rule_type: FILTER_CUSTOM_FIELDS_TEXT, // rule_type: FILTER_CUSTOM_FIELDS_TEXT,
value: 'foo', // value: 'foo',
}, // },
]) // ])
})) }))
it('should convert user input to correct filter rules on full text query', fakeAsync(() => { it('should convert user input to correct filter rules on full text query', fakeAsync(() => {
@ -1190,7 +1192,7 @@ describe('FilterEditorComponent', () => {
component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
const textFieldTargetDropdown = fixture.debugElement.queryAll( const textFieldTargetDropdown = fixture.debugElement.queryAll(
By.directive(NgbDropdownItem) By.directive(NgbDropdownItem)
)[4] )[3]
textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_ASN textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_ASN
fixture.detectChanges() fixture.detectChanges()
tick(400) tick(400)
@ -1444,72 +1446,72 @@ describe('FilterEditorComponent', () => {
})) }))
it('should convert user input to correct filter rules on custom field select not assigned', fakeAsync(() => { it('should convert user input to correct filter rules on custom field select not assigned', fakeAsync(() => {
const customFieldsFilterableDropdown = fixture.debugElement.queryAll( // const customFieldsFilterableDropdown = fixture.debugElement.queryAll(
By.directive(FilterableDropdownComponent) // By.directive(FilterableDropdownComponent)
)[4] // )[4]
customFieldsFilterableDropdown.triggerEventHandler('opened') // customFieldsFilterableDropdown.triggerEventHandler('opened')
const customFieldButton = customFieldsFilterableDropdown.queryAll( // const customFieldButton = customFieldsFilterableDropdown.queryAll(
By.directive(ToggleableDropdownButtonComponent) // By.directive(ToggleableDropdownButtonComponent)
)[0] // )[0]
customFieldButton.triggerEventHandler('toggle') // customFieldButton.triggerEventHandler('toggle')
fixture.detectChanges() // fixture.detectChanges()
expect(component.filterRules).toEqual([ // expect(component.filterRules).toEqual([
{ // {
rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS, // rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS,
value: 'false', // value: 'false',
}, // },
]) // ])
})) }))
it('should convert user input to correct filter rules on custom field selections', fakeAsync(() => { it('should convert user input to correct filter rules on custom field selections', fakeAsync(() => {
const customFieldsFilterableDropdown = fixture.debugElement.queryAll( // const customFieldsFilterableDropdown = fixture.debugElement.queryAll(
By.directive(FilterableDropdownComponent) // By.directive(FilterableDropdownComponent)
)[4] // CF dropdown // )[4] // CF dropdown
customFieldsFilterableDropdown.triggerEventHandler('opened') // customFieldsFilterableDropdown.triggerEventHandler('opened')
const customFieldButtons = customFieldsFilterableDropdown.queryAll( // const customFieldButtons = customFieldsFilterableDropdown.queryAll(
By.directive(ToggleableDropdownButtonComponent) // By.directive(ToggleableDropdownButtonComponent)
) // )
customFieldButtons[1].triggerEventHandler('toggle') // customFieldButtons[1].triggerEventHandler('toggle')
customFieldButtons[2].triggerEventHandler('toggle') // customFieldButtons[2].triggerEventHandler('toggle')
fixture.detectChanges() // fixture.detectChanges()
expect(component.filterRules).toEqual([ // expect(component.filterRules).toEqual([
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: custom_fields[0].id.toString(), // value: custom_fields[0].id.toString(),
}, // },
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: custom_fields[1].id.toString(), // value: custom_fields[1].id.toString(),
}, // },
]) // ])
const toggleOperatorButtons = customFieldsFilterableDropdown.queryAll( // const toggleOperatorButtons = customFieldsFilterableDropdown.queryAll(
By.css('input[type=radio]') // By.css('input[type=radio]')
) // )
toggleOperatorButtons[1].nativeElement.checked = true // toggleOperatorButtons[1].nativeElement.checked = true
toggleOperatorButtons[1].triggerEventHandler('change') // toggleOperatorButtons[1].triggerEventHandler('change')
fixture.detectChanges() // fixture.detectChanges()
expect(component.filterRules).toEqual([ // expect(component.filterRules).toEqual([
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY,
value: custom_fields[0].id.toString(), // value: custom_fields[0].id.toString(),
}, // },
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY,
value: custom_fields[1].id.toString(), // value: custom_fields[1].id.toString(),
}, // },
]) // ])
customFieldButtons[2].triggerEventHandler('exclude') // customFieldButtons[2].triggerEventHandler('exclude')
fixture.detectChanges() // fixture.detectChanges()
expect(component.filterRules).toEqual([ // expect(component.filterRules).toEqual([
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: custom_fields[0].id.toString(), // value: custom_fields[0].id.toString(),
}, // },
{ // {
rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS, // rule_type: FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS,
value: custom_fields[1].id.toString(), // value: custom_fields[1].id.toString(),
}, // },
]) // ])
})) }))
it('should convert user input to correct filter rules on date created after', fakeAsync(() => { it('should convert user input to correct filter rules on date created after', fakeAsync(() => {
@ -1594,7 +1596,7 @@ describe('FilterEditorComponent', () => {
component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) component.textFilterInput.nativeElement.dispatchEvent(new Event('input'))
const textFieldTargetDropdown = fixture.debugElement.queryAll( const textFieldTargetDropdown = fixture.debugElement.queryAll(
By.directive(NgbDropdownItem) By.directive(NgbDropdownItem)
)[4] )[3]
textFieldTargetDropdown.triggerEventHandler('click') textFieldTargetDropdown.triggerEventHandler('click')
fixture.detectChanges() fixture.detectChanges()
tick(400) tick(400)
@ -1918,23 +1920,23 @@ describe('FilterEditorComponent', () => {
] ]
expect(component.generateFilterName()).toEqual('Without any tag') expect(component.generateFilterName()).toEqual('Without any tag')
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL,
value: '42', // value: '42',
}, // },
] // ]
expect(component.generateFilterName()).toEqual( // expect(component.generateFilterName()).toEqual(
`Custom fields: ${custom_fields[0].name}` // `Custom fields: ${custom_fields[0].name}`
) // )
component.filterRules = [ // component.filterRules = [
{ // {
rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS, // rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS,
value: 'false', // value: 'false',
}, // },
] // ]
expect(component.generateFilterName()).toEqual('Without any custom field') // expect(component.generateFilterName()).toEqual('Without any custom field')
component.filterRules = [ component.filterRules = [
{ {

View File

@ -768,11 +768,6 @@ export class FilterEditorComponent
let queries = this.customFieldQueriesModel.queries let queries = this.customFieldQueriesModel.queries
.filter((query) => query.value && query.operator) .filter((query) => query.value && query.operator)
.map((query) => query.serialize()) .map((query) => query.serialize())
console.log(
'this.customFieldQueriesModel.queries',
this.customFieldQueriesModel.queries
)
console.log('queries', queries)
if (queries.length > 0) { if (queries.length > 0) {
filterRules.push({ filterRules.push({
rule_type: FILTER_CUSTOM_FIELDS_LOOKUP, rule_type: FILTER_CUSTOM_FIELDS_LOOKUP,