Skip to content

Commit

Permalink
Merge branch 'main' into chore/improve-tests-for-applications-compone…
Browse files Browse the repository at this point in the history
…nts-and-services
  • Loading branch information
ngruelaneo authored Apr 29, 2024
2 parents 9547891 + ebc7fe1 commit 6908a9a
Show file tree
Hide file tree
Showing 30 changed files with 2,687 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/app/components/count-tasks-by-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { ViewTasksByStatusComponent } from '@components/view-tasks-by-status.com
selector: 'app-count-tasks-by-status',
template: `
<app-view-tasks-by-status
[defaultQueryParams]="queryParams"
[statuses]="statuses"
[loading]="loading"
[statusesCounts]="statusesCounts"
[defaultQueryParams]="queryParams"
>
</app-view-tasks-by-status>
`,
Expand Down
7 changes: 1 addition & 6 deletions src/app/components/icon-picker-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatMenuModule } from '@angular/material/menu';
import { MatTooltipModule } from '@angular/material/tooltip';
import { Page } from '@app/types/pages';
import { IconsService } from '@services/icons.service';

@Component({
Expand Down Expand Up @@ -53,11 +52,7 @@ export class IconPickerDialogComponent implements OnInit {
}

getIcon(icon: string): string {
try {
return this.iconsService.getIcon(icon);
} catch (error) {
return this.iconsService.getPageIcon(icon as Page);
}
return this.iconsService.getIcon(icon);
}

selectIcon(icon: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('EditExternalServiceDialogComponent', () => {
const externalService = {
name: 'service',
url: 'url',
icon: 'main'
icon: 'heart'
};
const mockMatDialogData = {
externalService: externalService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('', () => {
component.externalService = {
name: 'service',
url: 'url',
icon: 'main'
icon: 'heart'
};
fixture.detectChanges();
});
Expand Down
126 changes: 93 additions & 33 deletions src/app/results/components/table.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Clipboard } from '@angular/cdk/clipboard';
import { TestBed } from '@angular/core/testing';
import { BehaviorSubject, Subject, of } from 'rxjs';
import { BehaviorSubject, Subject, of, throwError } from 'rxjs';
import { TableColumn } from '@app/types/column.type';
import { FiltersService } from '@services/filters.service';
import { NotificationService } from '@services/notification.service';
Expand All @@ -9,45 +10,63 @@ import { ResultsIndexService } from '../services/results-index.service';
import { ResultsStatusesService } from '../services/results-statuses.service';
import { ResultRawColumnKey, ResultRawFilters } from '../types';

describe('ApplicationTableComponent', () => {
describe('TasksTableComponent', () => {
let component: ResultsTableComponent;

const displayedColumns: TableColumn<ResultRawColumnKey>[] = [
{
name: 'Completed at',
key: 'completedAt',
type: 'date',
sortable: true
name: 'Result ID',
key: 'resultId',
type: 'link',
sortable: true,
link: '/tasks',
},
{
name: 'Name',
key: 'name',
sortable: true
name: 'Status',
key: 'status',
type: 'status',
sortable: true,
},
{
name: 'Created at',
key: 'createdAt',
type: 'date',
sortable: true,
},
{
name: 'Actions',
key: 'actions',
type: 'actions',
sortable: false
sortable: false,
}
];

const mockResultsIndexService = {
columnToLabel: jest.fn(),
isSessionIdColumn: jest.fn(),
isDateColumn: jest.fn(),
isActionsColumn: jest.fn(),
isTaskIdColumn: jest.fn(),
isStatusColumn: jest.fn(),
isDateColumn: jest.fn(),
isDurationColumn: jest.fn(),
isObjectColumn: jest.fn(),
isSelectColumn: jest.fn(),
isSimpleColumn: jest.fn(),
saveColumns: jest.fn(),
isResultIdColumn: jest.fn()
isNotSortableColumn: jest.fn(),
columnToLabel: jest.fn(),
saveColumns: jest.fn()
};

const mockResultsGrpcService = {
list$: jest.fn(() => of({results: [{resultId: '1'}, {resultId: '2'}]}))
const mockNotificationService = {
success: jest.fn(),
error: jest.fn(),
};

const mockNotificationService = {
error: jest.fn()
const mockClipBoard = {
copy: jest.fn()
};

const mockResultsGrpcService = {
list$: jest.fn(() => of({ results: [{ resultId: 'result1' }, { resultId: 'result2' }, { resultId: 'result3' }], total: 3 })),
cancel$: jest.fn(() => of({})),
};

beforeEach(() => {
Expand All @@ -56,58 +75,99 @@ describe('ApplicationTableComponent', () => {
ResultsTableComponent,
{ provide: ResultsIndexService, useValue: mockResultsIndexService },
{ provide: ResultsGrpcService, useValue: mockResultsGrpcService },
{ provide: NotificationService, useValue: mockNotificationService },
ResultsStatusesService,
FiltersService,
ResultsStatusesService
{ provide: NotificationService, useValue: mockNotificationService },
{ provide: Clipboard, useValue: mockClipBoard },
]
}).inject(ResultsTableComponent);
component.refresh$ = new Subject();
component.loading$ = new Subject();

component.displayedColumns = displayedColumns;
component.filters$ = new BehaviorSubject<ResultRawFilters>([]);
component.options = {
pageIndex: 0,
pageSize: 10,
sort: {
active: 'name',
active: 'resultId',
direction: 'desc'
}
};
component.refresh$ = new Subject();
component.loading$ = new Subject();
component.ngAfterViewInit();
});

it('should run', () => {
expect(component).toBeTruthy();
});

it('should update data on next', () => {
it('should update data on refresh', () => {
component.refresh$.next();
expect(component.data).toEqual([
{
raw: {
resultId: '1'
resultId: 'result1'
},
value$: expect.any(Subject)
},
{
raw: {
resultId: 'result2'
},
value$: expect.any(Subject)
},
{
raw: {
resultId: '2'
resultId: 'result3'
},
value$: expect.any(Subject)
}
]);
});

it('should change column order', () => {
const newColumns: ResultRawColumnKey[] = ['actions', 'name', 'completedAt'];
it('should return columns keys', () => {
expect(component.columnKeys).toEqual(displayedColumns.map(column => column.key));
});

describe('on list error', () => {
beforeEach(() => {
mockResultsGrpcService.list$.mockReturnValueOnce(throwError(() => new Error()));
});

it('should log error', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => { });
component.refresh$.next();
expect(spy).toHaveBeenCalled();
});

it('should send a notification', () => {
component.refresh$.next();
expect(mockNotificationService.error).toHaveBeenCalled();
});

it('should send empty data', () => {
component.refresh$.next();
expect(component.data).toEqual([]);
});
});

it('should refresh data on options changes', () => {
const spy = jest.spyOn(component.refresh$, 'next');
component.onOptionsChange();
expect(spy).toHaveBeenCalled();
});

test('onDrop should call ResultsIndexService', () => {
const newColumns: ResultRawColumnKey[] = ['actions', 'resultId', 'status'];
component.onDrop(newColumns);
expect(mockResultsIndexService.saveColumns).toHaveBeenCalledWith(newColumns);
expect(component.displayedColumns).toEqual(displayedColumns);
});

it('should get the session filter for a result', () => {
expect(component.createSessionIdQueryParams('12345')).toEqual({
'1-root-1-0':'12345'
test('createSessionIdQueryParams should return query params with correct session', () => {
const sessionId = 'session1';
const result = component.createSessionIdQueryParams(sessionId);
expect(result).toEqual({
'1-root-1-0': sessionId
});
});
});
4 changes: 2 additions & 2 deletions src/app/results/components/table.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterStringOperator, ListResultsResponse, ResultRawEnumField } from '@aneoconsultingfr/armonik.api.angular';
import { FilterStringOperator, ListResultsResponse, SessionRawEnumField } from '@aneoconsultingfr/armonik.api.angular';
import { AfterViewInit, Component, inject } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ResultsTableComponent extends AbstractTableComponent<ResultRaw, Res
}

createSessionIdQueryParams(sessionId: string) {
const keySession = this.filtersService.createQueryParamsKey<ResultRawEnumField>(1, 'root', FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL, ResultRawEnumField.RESULT_RAW_ENUM_FIELD_SESSION_ID);
const keySession = this.filtersService.createQueryParamsKey<SessionRawEnumField>(1, 'root', FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL, SessionRawEnumField.SESSION_RAW_ENUM_FIELD_SESSION_ID);

return {
[keySession]: sessionId,
Expand Down
Loading

0 comments on commit 6908a9a

Please sign in to comment.