Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<number, string> = {
[FilterStringOperator.FILTER_STRING_OPERATOR_EQUAL]: 'equal',
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
});
5 changes: 5 additions & 0 deletions src/app/components/graph/graph.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,9 @@ describe('GraphComponent', () => {
expect(spy).toHaveBeenCalled();
});
});

it('should unsubscribe on destroy', () => {
component.ngOnDestroy();
expect(component['subscription'].closed).toBeTruthy();
});
});
4 changes: 1 addition & 3 deletions src/app/components/graph/graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ export class GraphComponent<N extends ArmoniKGraphNode, L extends GraphLink<N>>

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)));
}
}

Expand Down
18 changes: 15 additions & 3 deletions src/app/components/inspection-header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
Expand Down Expand Up @@ -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', () => {
Expand Down
13 changes: 11 additions & 2 deletions src/app/components/inspection/inspection-object.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('InspectionObjectComponent', () => {
output: {
error: 'error message',
success: false,
}
},
retryOfIds: {},
} as TaskRaw;

const fields: Field<TaskRaw>[] = [
Expand All @@ -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<TaskStatus, string> = {
Expand Down Expand Up @@ -79,14 +84,18 @@ 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' }]);
});
});

it('should get an object', () => {
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);
});
Expand Down
91 changes: 91 additions & 0 deletions src/app/components/status-chip.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});
2 changes: 1 addition & 1 deletion src/app/components/status-chip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '-';
Expand Down
18 changes: 17 additions & 1 deletion src/app/components/table/table-cell.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('TableCellComponent', () => {
]
];

const byteArray = 'Mock-byte-array';

const queryParamsMap = new Map<SessionRawColumnKey, { [key: string]: string }>();
queryParamsMap.set('sessionId', { sessionId: 'session-id' });

Expand All @@ -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',
Expand Down Expand Up @@ -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 = {
Expand Down
66 changes: 7 additions & 59 deletions src/app/services/default-config-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
Expand Down
Loading