Skip to content

Commit

Permalink
chore: tested applications index service (#710)
Browse files Browse the repository at this point in the history
Co-authored-by: yannick-aneo <[email protected]>
  • Loading branch information
fdewas-aneo and yannick-aneo authored Oct 19, 2023
1 parent b604d98 commit f180aed
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions src/app/applications/services/applications-index.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { TestBed } from '@angular/core/testing';
import { DefaultConfigService } from '@services/default-config.service';
import { TableService } from '@services/table.service';
import { ApplicationsIndexService } from './applications-index.service';
import { ApplicationRawColumnKey, ApplicationRawListOptions } from '../types';


describe('TasksIndexService', () => {
let service: ApplicationsIndexService;

const expectedColumnLabels: Record<ApplicationRawColumnKey, string> = {
name: $localize`Name`,
namespace: $localize`Namespace`,
service: $localize`Service`,
version: $localize`Version`,
count: $localize`Tasks by Status`,
actions: $localize`Actions`,
};

const expectDefaultOptions :ApplicationRawListOptions = {
pageIndex: 0,
pageSize: 10,
sort: {
active: 'name',
direction: 'asc'
},
};
const expectedDefaultColumns = new DefaultConfigService().defaultApplications.columns;

const expectedDefaultIntervalValue = new DefaultConfigService().defaultApplications.interval;
const mockTableService = {
saveIntervalValue: jest.fn(),
restoreIntervalValue: jest.fn(),
saveOptions: jest.fn(),
restoreOptions: jest.fn(),
saveColumns: jest.fn(),
restoreColumns: jest.fn(),
resetColumns: jest.fn(),
saveViewInLogs: jest.fn(),
restoreViewInLogs: jest.fn()
};


beforeEach(() => {
service = TestBed.configureTestingModule({
providers: [
ApplicationsIndexService,
DefaultConfigService,
{provide: TableService, useValue: mockTableService}
]
}).inject(ApplicationsIndexService);
});

test('Create ApplicationsIndexService', ()=> {
expect(service).toBeTruthy();
});


describe('Columns', ()=> {
test('the service should label the right column among available columns labels',() => {
for(const [key] of Object.entries(expectedColumnLabels)) {
expect(service.columnToLabel(key as ApplicationRawColumnKey)).toEqual(service.columnsLabels[`${key}` as ApplicationRawColumnKey]);
}
});
});

describe('Table', () => {
it('should return true if the column is actions', () =>{
expect(service.isActionsColumn('actions')).toEqual(true);
});
it('should return false if the column is not actions', () =>{
expect(service.isActionsColumn('name')).toEqual(false);
});

it('should return true if the column is id', () =>{
expect(service.isCountColumn('count')).toEqual(true);
});
it('should return false if the column is not id', () =>{
expect(service.isCountColumn('name')).toEqual(false);
});

it('should return true if the column is a simple column', () =>{
expect(service.isSimpleColumn('name')).toEqual(true);
});
it('should return false if the column is not a simple column', () =>{
expect(service.isSimpleColumn('actions')).toEqual(false);
});

it('should return true if the column is not sortable', () =>{
expect(service.isNotSortableColumn('count')).toEqual(true);
});
it('should return false if the column is sortable', () =>{
expect(service.isNotSortableColumn('name')).toEqual(false);
});
});

describe('Interval', ()=>{
it('should call saveIntervalValue from TableService', ()=>{
service.saveIntervalValue(9);
expect(mockTableService.saveIntervalValue).toBeCalledWith('applications-interval', 9);
});

it('should call restoreIntervalValue from TableService', ()=>{
service.restoreIntervalValue();
expect(mockTableService.restoreIntervalValue).toHaveBeenCalledWith('applications-interval');
});

it('should return defaultIntervalValue when restoreIntervalValue from TableService returns null', () => {
mockTableService.restoreIntervalValue.mockImplementationOnce(() => null);
expect(service.restoreIntervalValue()).toEqual(expectedDefaultIntervalValue);
});

});

describe('Options', ()=>{
it('should call saveOptions from TableService', ()=>{
service.saveOptions(expectDefaultOptions);
expect(mockTableService.saveOptions).toBeCalledWith('applications-options',expectDefaultOptions);
});

it('should call restoreOptions from TableService', ()=>{
service.restoreOptions();
expect(mockTableService.restoreOptions).toBeCalledWith('applications-options',expectDefaultOptions);
});
});

describe('Columns', ()=>{
it('should call saveColumns from TableService', ()=>{
service.saveColumns(['namespace', 'actions', 'version']);
expect(mockTableService.saveColumns).toBeCalledWith('applications-columns', ['namespace', 'actions', 'version']);
});

it('should call restoreColumns from TableService', ()=>{
service.restoreColumns();
expect(mockTableService.restoreColumns).toBeCalledWith('applications-columns');
});

it('should return defaultColums when restoreColumns from TableService returns null', ()=>{
mockTableService.restoreColumns.mockImplementationOnce(() => null);
expect(service.restoreColumns()).toEqual(expectedDefaultColumns);
});

it('should call resetColumns from TableService', ()=>{
service.resetColumns();
expect(mockTableService.resetColumns).toBeCalledWith('applications-columns');
expect(service.resetColumns()).toEqual(expectedDefaultColumns);
});
});
});

1 comment on commit f180aed

@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: 89%
88.98% (1470/1652) 79.6% (285/358) 80.26% (358/446)

JUnit

Tests Skipped Failures Errors Time
503 0 💤 0 ❌ 0 🔥 1m 11s ⏱️
Files coverage (89%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files88.9879.680.2689.14 
applications/services97.180.9591.6696.96 
   applications-filters.service.ts100100100100 
   applications-grpc.service.ts10066.6610010068–69
   applications-index.service.ts93.18086.6692.8571–75
components92.0394.1181.4493.6 
   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.ts26.660033.3365–123
   count-tasks-by-status.component.ts1005010010048
   page-header.component.ts8010008039
   page-section-header.component.ts8010008031
   page-section.component.ts100100100100 
   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 
dashboard100100100100 
   index.component.ts100100100100 
dashboard/components68.138.8845.6768.24 
   add-line-dialog.component.ts55.55100055.5527–38
   add-statuses-group-dialog.component.ts45.45100045.4529–45
   edit-name-line-dialog.component.ts5010005031–46
   edit-status-group-dialog.component.ts41.66100041.6630–47
   form-name-line.component.ts47.360047.3657–88
   form-statuses-group.component.ts22.50022.582–159
   line.component.ts100100100100 
   manage-groups-dialog.component.ts100100100100 
   reorganize-lines-dialog.component.ts32.430034.28104–160
   split-lines-dialog.component.ts42.850042.8538–61
   statuses-group-card.component.ts100100100100 
dashboard/services52.533.3326.6652.77 
   dashboard-index.service.ts240022.7210–49
   dashboard-storage.service.ts100100100100 
services98.3695.4195.6998.24 
   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/services77.455083.7876.53 
   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.