diff --git a/src/app/components/filters/dialog/filters-dialog-operator.component.spec.ts b/src/app/components/filters/dialog/filters-dialog-operator.component.spec.ts index 962eb340a..cde048a38 100644 --- a/src/app/components/filters/dialog/filters-dialog-operator.component.spec.ts +++ b/src/app/components/filters/dialog/filters-dialog-operator.component.spec.ts @@ -1,8 +1,9 @@ import { FilterStringOperator } from '@aneoconsultingfr/armonik.api.angular'; +import { TestBed } from '@angular/core/testing'; import { FiltersDialogOperatorComponent } from './filters-dialog-operator.component'; describe('FiltersDialogOperatorComponent', () => { - const component = new FiltersDialogOperatorComponent(); + let component: FiltersDialogOperatorComponent; const operators: Record = { [FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL]: 'equal', @@ -13,6 +14,11 @@ describe('FiltersDialogOperatorComponent', () => { const registeredOnTouche = jest.fn((val: number | null) => val); beforeEach(() => { + component = TestBed.configureTestingModule({ + providers: [ + FiltersDialogOperatorComponent + ], + }).inject(FiltersDialogOperatorComponent); component.operators = operators; component.registerOnChange(registeredOnChange); component.registerOnTouched(registeredOnTouche); @@ -77,4 +83,11 @@ describe('FiltersDialogOperatorComponent', () => { }); }); }); + + it('should directly write value if there is only one operator available', () => { + component.operators = { + [FilterStringOperator.FILTER_STRING_OPERATOR_CONTAINS]: 'Contains', + }; + expect(registeredOnChange).toHaveBeenCalledWith(FilterStringOperator.FILTER_STRING_OPERATOR_CONTAINS); + }); }); \ No newline at end of file diff --git a/src/app/components/graph/graph.component.spec.ts b/src/app/components/graph/graph.component.spec.ts index 31db87869..801de679d 100644 --- a/src/app/components/graph/graph.component.spec.ts +++ b/src/app/components/graph/graph.component.spec.ts @@ -403,4 +403,9 @@ describe('GraphComponent', () => { expect(spy).toHaveBeenCalled(); }); }); + + it('should unsubscribe on destroy', () => { + component.ngOnDestroy(); + expect(component['subscription'].closed).toBeTruthy(); + }); }); \ No newline at end of file diff --git a/src/app/components/graph/graph.component.ts b/src/app/components/graph/graph.component.ts index d65dfbddf..2c4ff7599 100644 --- a/src/app/components/graph/graph.component.ts +++ b/src/app/components/graph/graph.component.ts @@ -118,9 +118,7 @@ export class GraphComponent> this.subscription.add(this.grpcObservable.subscribe((result) => this.subscribeToData(result))); - this.subscription.add(this.redrawGraph$ - .pipe(switchMap(() => this.grpcObservable)) - .subscribe((result) => this.subscribeToData(result))); + this.subscription.add(this.redrawGraph$.pipe(switchMap(() => this.grpcObservable)).subscribe((result) => this.subscribeToData(result))); } } diff --git a/src/app/components/inspection-header.component.spec.ts b/src/app/components/inspection-header.component.spec.ts index 040ab2282..9ee683de4 100644 --- a/src/app/components/inspection-header.component.spec.ts +++ b/src/app/components/inspection-header.component.spec.ts @@ -17,11 +17,15 @@ describe('InspectionHeaderComponent', () => { copy: jest.fn() }; + const mockIconsService = { + getIcon: jest.fn() + }; + beforeEach(() => { component = TestBed.configureTestingModule({ providers: [ InspectionHeaderComponent, - IconsService, + { provide: IconsService, useValue: mockIconsService }, { provide: NotificationService, useValue: mockNotificationService }, { provide: Clipboard, useValue: mockClipboard } ] @@ -60,8 +64,16 @@ describe('InspectionHeaderComponent', () => { expect(component.sharableURL).toEqual(url); }); - it('should get icons', () => { - expect(component.getIcon('share')).toBeDefined(); + describe('getIcon', () => { + it('should get icons', () => { + const icon = 'share'; + component.getIcon(icon); + expect(mockIconsService.getIcon).toHaveBeenCalledWith(icon); + }); + + it('should return an empty string when undefined is provided', () => { + expect(component.getIcon(undefined)).toEqual(''); + }); }); describe('onCopyId', () => { diff --git a/src/app/components/inspection/inspection-object.component.spec.ts b/src/app/components/inspection/inspection-object.component.spec.ts index 786143c61..21721267d 100644 --- a/src/app/components/inspection/inspection-object.component.spec.ts +++ b/src/app/components/inspection/inspection-object.component.spec.ts @@ -20,7 +20,8 @@ describe('InspectionObjectComponent', () => { output: { error: 'error message', success: false, - } + }, + retryOfIds: {}, } as TaskRaw; const fields: Field[] = [ @@ -46,6 +47,10 @@ describe('InspectionObjectComponent', () => { key: 'options', type: 'object' }, + { + key: 'retryOfIds', // Change the type of this property for tests purposes + type: 'byte-array', + }, ]; const statuses: Record = { @@ -79,7 +84,7 @@ describe('InspectionObjectComponent', () => { it('should set data keys as fields if none are provided', () => { component.fields = []; component.data = data; - expect(component.fields).toEqual([{ key: 'id' }, { key: 'options' }, { key: 'output' }, { key: 'statusMessage' }]); + expect(component.fields).toEqual([{ key: 'id' }, { key: 'options' }, { key: 'output' }, { key: 'retryOfIds' }, { key: 'statusMessage' }]); }); }); @@ -87,6 +92,10 @@ describe('InspectionObjectComponent', () => { expect(component.getObject(findField('options', fields)!)).toEqual(data.options); }); + it('should get the byteArray', () => { + expect(component.getByteArray(findField('retryOfIds', fields)!)).toEqual(data.retryOfIds); + }); + it('should get the output error', () => { expect(component.getError(findField('output', fields)!)).toEqual(data.output?.error); }); diff --git a/src/app/components/status-chip.component.spec.ts b/src/app/components/status-chip.component.spec.ts new file mode 100644 index 000000000..d72950979 --- /dev/null +++ b/src/app/components/status-chip.component.spec.ts @@ -0,0 +1,91 @@ +import { TestBed } from '@angular/core/testing'; +import { StatusLabelColor } from '@app/types/status'; +import { IconsService } from '@services/icons.service'; +import { StatusChipComponent } from './status-chip.component'; + +describe('StatusChipComponent', () => { + let component: StatusChipComponent; + + const mockIconsService = { + getIcon: jest.fn(icon => icon), + }; + + beforeEach(() => { + component = TestBed.configureTestingModule({ + providers: [ + StatusChipComponent, + { provide: IconsService, useValue: mockIconsService }, + ], + }).inject(StatusChipComponent); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + describe('Initialisation', () => { + it('should have a set label', () => { + expect(component.label).toBeDefined(); + }); + + it('should have a set color', () => { + expect(component.color).toBeDefined(); + }); + + it('should not have a set icon', () => { + expect(component.icon).toBeUndefined(); + }); + }); + + describe('Setting status', () => { + describe('With valid and complete status data', () => { + const newStatusLabelColor: StatusLabelColor = { + color: 'yellow', + label: 'Running', + icon: 'heart', + }; + + beforeEach(() => { + component.status = newStatusLabelColor; + }); + + it('should set the label properly', () => { + expect(component.label).toBe(newStatusLabelColor.label); + }); + + it('should set the label properly', () => { + expect(component.color).toBe(newStatusLabelColor.color); + }); + + it('should set the icon properly', () => { + expect(component.icon).toBe(newStatusLabelColor.icon); + }); + }); + + describe('With incomplete status data', () => { + beforeEach(() => { + component.status = { + color: undefined as unknown as string, + label: undefined as unknown as string, + icon: '', + }; + }); + + it('should set the label as "Unknown"', () => { + expect(component.label).toEqual('Unknown'); + }); + + it('should set the color as grey (default)', () => { + expect(component.color).toEqual('grey'); + }); + + it('should set the icon as undefined', () => { + expect(component.icon).toBeUndefined(); + }); + }); + }); +}); \ No newline at end of file diff --git a/src/app/components/status-chip.component.ts b/src/app/components/status-chip.component.ts index 14dbdd9e6..178fc6ab9 100644 --- a/src/app/components/status-chip.component.ts +++ b/src/app/components/status-chip.component.ts @@ -22,7 +22,7 @@ export class StatusChipComponent { @Input({ required: false }) set status(entry: StatusLabelColor) { this.label = entry.label ?? 'Unknown'; this.color = entry.color ?? 'grey'; - this.icon = entry.icon !== undefined && entry.icon.length !== 1 ? this.iconsService.getIcon(entry.icon) : undefined; + this.icon = entry.icon !== undefined && entry.icon.length !== 0 ? this.iconsService.getIcon(entry.icon) : undefined; } label: string = '-'; diff --git a/src/app/components/table/table-cell.component.spec.ts b/src/app/components/table/table-cell.component.spec.ts index 51e491c4f..e8671b753 100644 --- a/src/app/components/table/table-cell.component.spec.ts +++ b/src/app/components/table/table-cell.component.spec.ts @@ -39,6 +39,8 @@ describe('TableCellComponent', () => { ] ]; + const byteArray = 'Mock-byte-array'; + const queryParamsMap = new Map(); queryParamsMap.set('sessionId', { sessionId: 'session-id' }); @@ -54,8 +56,9 @@ describe('TableCellComponent', () => { options, clientSubmission: false, workerSubmission: false, + cancelledAt: byteArray, // This property is modified for tests purposes partitionIds: [] - } as SessionRaw, + } as unknown as SessionRaw, resultsQueryParams: { '0-root-1-1': 'session-not-id', '0-root-2-1': 'session', @@ -230,6 +233,19 @@ describe('TableCellComponent', () => { }); }); + describe('byteArray value', () => { + beforeEach(() => { + column.key = 'cancelledAt'; + column.type = 'byte-array'; + component.column = column; + component.element = element; + }); + + it('should set byteArray', () => { + expect(component.byteArray).toEqual(byteArray); + }); + }); + describe('object value', () => { beforeEach(() => { component.column = { diff --git a/src/app/services/default-config-service.spec.ts b/src/app/services/default-config-service.spec.ts index b5864e572..70f896132 100644 --- a/src/app/services/default-config-service.spec.ts +++ b/src/app/services/default-config-service.spec.ts @@ -25,52 +25,12 @@ describe('DefaultConfigService', () => { expect(service).toBeTruthy(); }); - it('should have the right default theme', () => { - expect(service.defaultTheme).toBe('light-blue'); - }); - - it('should have a defined defaultExternalServices configuration', () => { - expect(service.defaultExternalServices).toBeDefined(); - }); - - it('should have a defined defaultTasks configuration', () => { - expect(service.defaultTasks).toBeDefined(); - }); - - it('should have a defined defaultTasksByStatus configuration', () => { - expect(service.defaultTasksByStatus).toBeDefined(); - }); - - it('should have a defined defaultPartititons configuration', () => { - expect(service.defaultPartitions).toBeDefined(); - }); - - it('should have a defined defaultDashboardSplitLines configuration', ()=> { - expect(service.defaultDashboardSplitLines).toBeDefined(); - }); - - it('should have a defined defaultSessions configuration', () => { - expect(service.defaultSessions).toBeDefined(); - }); - - it('should have a defined defaultResults configuration', () => { - expect(service.defaultResults).toBeDefined(); - }); - - it('should have a defined defaultApplications configuration', () => { - expect(service.defaultApplications).toBeDefined(); - }); - - it('should have a defined defaultSidebar configuration', () => { - expect(service.defaultSidebar).toBeDefined(); - }); - - it('should have a defined defaultTasksViewInLogs configuration', () => { - expect(service.defaultTasksViewInLogs).toBeDefined(); - }); - - it('should have a defined exportedDefaultConfig configuration', () => { - expect(service.exportedDefaultConfig).toBeDefined(); + it('Every method should return a defined value', () => { + const keys = Object.getOwnPropertyNames(DefaultConfigService.prototype).filter(key => key !== 'constructor'); + for (const key of keys) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + expect((service as any)[key]).toBeDefined(); + } }); describe('defaultLanguage configuration', () => { @@ -79,19 +39,7 @@ describe('DefaultConfigService', () => { }); }); - it('should have a defined availableLanguages configuration', () => { - expect(service.availableLanguages).toBeDefined(); - }); - - it('should have a defined defaultSideBarOpened', () => { - expect(service.defaultSidebarOpened).toBeDefined(); - }); - - describe(' default dashboard configuration', () => { - it('the dashboard lines configuration should display at least 1 line', () => { - expect(service.defaultDashboardLines).toBeDefined(); - }); - + describe('default dashboard configuration', () => { it('the line by default should contain 3 task statuses', () => { const defaultDashboardLines = service.defaultDashboardLines; const taskStatuses = defaultDashboardLines.map(line => (line as CountLine).taskStatusesGroups);