-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: tests for applications-filters service (#716)
- Loading branch information
1 parent
8d7f48c
commit a40aaab
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
src/app/applications/services/applications-filters.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { ApplicationRawEnumField } from '@aneoconsultingfr/armonik.api.angular'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { FilterFor } from '@app/types/filter-definition'; | ||
import { DefaultConfigService } from '@services/default-config.service'; | ||
import { TableService } from '@services/table.service'; | ||
import { ApplicationsFiltersService } from './applications-filters.service'; | ||
import { ApplicationRawFilter, ApplicationsFiltersDefinition } from '../types'; | ||
|
||
describe('ApplicationsFiltersService', () => { | ||
let service: ApplicationsFiltersService; | ||
const mockTableService = { | ||
saveFilters: jest.fn(), | ||
restoreFilters: jest.fn(), | ||
resetFilters: jest.fn() | ||
}; | ||
|
||
const defaultFilterDefinition: ApplicationsFiltersDefinition[] = [ | ||
{ | ||
for: 'root', | ||
field: ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_NAME, | ||
type: 'string', | ||
}, | ||
{ | ||
for: 'root', | ||
field: ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_NAMESPACE, | ||
type: 'string', | ||
}, | ||
{ | ||
for: 'root', | ||
field: ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_SERVICE, | ||
type: 'string', | ||
}, | ||
{ | ||
for: 'root', | ||
field: ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_VERSION, | ||
type: 'string', | ||
} | ||
]; | ||
|
||
const defaultFilters: ApplicationRawFilter = new DefaultConfigService().defaultApplications.filters; | ||
|
||
beforeEach(() => { | ||
service = TestBed.configureTestingModule({ | ||
providers: [ | ||
ApplicationsFiltersService, | ||
DefaultConfigService, | ||
{ provide: TableService, useValue: mockTableService } | ||
] | ||
}).inject(ApplicationsFiltersService); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should save filters', () => { | ||
const filters: ApplicationRawFilter = [[ | ||
{ | ||
field: 0, | ||
for: 'root', | ||
operator: 1, | ||
value: 1 | ||
} | ||
]]; | ||
service.saveFilters(filters); | ||
expect(mockTableService.saveFilters).toHaveBeenCalledWith('applications-filters', filters); | ||
}); | ||
|
||
it('should restore filters', () => { | ||
service.restoreFilters(); | ||
expect(mockTableService.restoreFilters).toHaveBeenCalledWith('applications-filters', defaultFilterDefinition); | ||
}); | ||
|
||
it('should restore default filters if it cannot restore', () => { | ||
mockTableService.restoreFilters.mockImplementationOnce(() => null); | ||
expect(service.restoreFilters()).toEqual(defaultFilters); | ||
}); | ||
|
||
it('should reset filters', () => { | ||
service.resetFilters(); | ||
expect(mockTableService.resetFilters).toHaveBeenCalledWith('applications-filters'); | ||
}); | ||
|
||
it('should return default filters on reset', () => { | ||
expect(service.resetFilters()).toEqual(defaultFilters); | ||
}); | ||
|
||
it('should return filters definitions', () => { | ||
expect(service.retrieveFiltersDefinitions()).toEqual(defaultFilterDefinition); | ||
}); | ||
|
||
it('should retrieve label', () => { | ||
expect(service.retrieveLabel('root', ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_NAME)).toEqual('Name'); | ||
}); | ||
|
||
it('should not retrieve label in case of options property', () => { | ||
expect(() => {service.retrieveLabel('options', ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_NAME);}) | ||
.toThrowError('Impossible case'); | ||
}); | ||
|
||
it('should throw an error in case of an unknown filter for', () => { | ||
expect(() => service.retrieveLabel('unexisting' as FilterFor<ApplicationRawEnumField, null>, ApplicationRawEnumField.APPLICATION_RAW_ENUM_FIELD_NAME)) | ||
.toThrowError('Unknown filter type: unexisting 1'); | ||
}); | ||
}); |
a40aaab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit
Files coverage (94%)