Skip to content

Commit

Permalink
chore: tests for applications-filters service (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdewas-aneo authored Oct 13, 2023
1 parent 8d7f48c commit a40aaab
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/app/applications/services/applications-filters.service.spec.ts
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');
});
});

1 comment on commit a40aaab

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 94%
94.74% (1099/1160) 85.17% (247/290) 91.2% (280/307)

JUnit

Tests Skipped Failures Errors Time
418 0 💤 0 ❌ 0 🔥 1m 18s ⏱️
Files coverage (94%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files94.7485.1791.294.85 
applications/services100100100100 
   applications-filters.service.ts100100100100 
components92.8594.1184.6193.95 
   actions-toolbar-group.component.ts100100100100 
   actions-toolbar.component.ts100100100100 
   auto-refresh-button.component.ts100100100100 
   auto-refresh-dialog.component.ts100100100100 
   columns-button.component.ts100100100100 
   columns-modify-dialog.component.ts28.570033.3365–123
   count-tasks-by-status.component.ts1005010010048
   refresh-button.component.ts100100100100 
   share-url.component.ts92.851007592.337
   show-card-content.component.ts100100100100 
   spinner.component.ts100100100100 
   table-actions-toolbar.component.ts100100100100 
   view-tasks-by-status-dialog.component.ts100100100100 
   view-tasks-by-status.component.ts100100100100 
components/filters9578.9495.7494.89 
   filters-chips.component.ts100100100100 
   filters-dialog-and.component.ts100100100100 
   filters-dialog-filter-field.component.ts86.275.7592.385.9699–100, 132, 174, 198–202
   filters-dialog-input.component.ts92.8563.6387.592.5973–74
   filters-dialog-or.component.ts100100100100 
   filters-dialog.component.ts100100100100 
   filters-toolbar.component.ts100100100100 
components/navigation99.4410097.3699.42 
   add-external-service-dialog.component.ts100100100100 
   edit-external-service-dialog.component.ts100100100100 
   form-external-service.component.ts100100100100 
   manage-external-services-dialog.component.ts100100100100 
   navigation.component.ts98.1410088.8898.11215
   theme-selector.component.ts100100100100 
services98.3695.4195.698.23 
   auto-refresh.service.ts100100100100 
   date-handler.service.ts100100100100 
   default-config.service.ts100100100100 
   environment.service.ts80100507519
   filters.service.ts100100100100 
   icons.service.ts100100100100 
   navigation.service.ts10080100100109
   notification.service.ts100100100100 
   query-params.service.ts100100100100 
   share-url.service.ts100100100100 
   storage.service.ts98.0310010097.9595
   table-storage.service.ts500042.8511–31
   table-url.service.ts100100100100 
   table.service.ts100100100100 
   tasks-by-status.service.ts100100100100 
   user-grpc.service.ts100100100100 
   user.service.ts100100100100 
   utils.service.ts100100100100 
   versions-grpc.service.ts100100100100 
   versions.service.ts1007010010014, 25, 32
tasks/services76.7647.7282.8575.78 
   tasks-filters.service.ts100100100100 
   tasks-grpc.service.ts23.330020.6813–151
   tasks-index.service.ts100100100100 
   tasks-statuses.service.ts100100100100 
tokens100100100100 
   filters.token.ts100100100100 

Please sign in to comment.