Skip to content
Snippets Groups Projects
Commit c18d8e00 authored by kbeyro's avatar kbeyro
Browse files

add test

parent 7b41c6c9
No related branches found
No related tags found
2 merge requests!184Develop,!155domain base add
......@@ -93,7 +93,7 @@
<div class="form-group">
<label for="ingresscontrollerconfigoption" class="col-sm-2 control-label">{{ 'CLUSTERS.CONTROLLER_CONFIG_OPTION' | translate }}</label>
<div class="col-sm-10">
<div class="col-sm-10" *ngIf="controllerConfigOption">
<select class="form-control" id="ingresscontrollerconfigoption" name="ingresscontrollerconfigoption"
[(ngModel)]="cluster.ingress.controllerConfigOption" [disabled]="" required>
<option *ngFor="let configOption of getKeys(controllerConfigOption)" [value]="controllerConfigOption.get(configOption)">{{configOption}}</option>
......@@ -187,7 +187,7 @@
<div class="panel-body">
<div class="form-group">
<label for="deploymentnamespaceconfigoption" class="col-sm-2 control-label">{{ 'CLUSTERS.NAMESPACE_CONFIG_OPTION' | translate }}</label>
<div class="col-sm-10">
<div class="col-sm-10" *ngIf="controllerConfigOption">
<select class="form-control" id="deploymentnamespaceconfigoption" name="deploymentnamespaceconfigoption"
[(ngModel)]="cluster.deployment.namespaceConfigOption" [disabled]="" required>
<option *ngFor="let configOption of getKeys(namespaceConfigOption)" [value]="namespaceConfigOption.get(configOption)">{{configOption}}</option>
......
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ClusterManagerDetailsComponent } from './managerdetails.component';
import { ClusterManagerService } from '../../../../service/cluster-manager.service';
import { ActivatedRoute, Router } from '@angular/router';
import { CommonModule, DatePipe } from '@angular/common';
import { of } from 'rxjs';
import { ClusterManager } from '../../../../model/cluster-manager';
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { IngressCertificateConfigOption, IngressControllerConfigOption, IngressResourceConfigOption, NamespaceConfigOption } from '../../../../model/cluster';
describe('ClusterManagerDetailsComponent', () => {
let component: ClusterManagerDetailsComponent;
let fixture: ComponentFixture<ClusterManagerDetailsComponent>;
let clusterService: jasmine.SpyObj<ClusterManagerService>;
let mockRouter: jasmine.SpyObj<Router>;
let mockActivatedRoute: any;
const mockCluster: ClusterManager = {
id: 1,
name: 'Test Cluster',
description: 'Test Description',
externalNetworks: [],
creationDate: new Date('2025-01-01'),
modificationDate: new Date('2025-02-01'),
codename: 'test-cluster',
pathConfigFile: '/path/to/config.yaml',
clusterConfigFile: 'Config',
ingress: {
id: 1,
controllerConfigOption: IngressControllerConfigOption.USE_EXISTING,
controllerChartName: 'nginx-ingress',
controllerChartArchive: 'nginx-ingress-1.0.0.tgz',
resourceConfigOption: IngressResourceConfigOption.DEPLOY_FROM_CHART,
externalServiceDomain: 'example.com',
tlsSupported: true,
supportedIngressClass: 'nginx',
certificateConfigOption: IngressCertificateConfigOption.USE_LETSENCRYPT,
issuerOrWildcardName: 'letsencrypt',
ingressPerDomain: false,
publicIngressClass: 'nginx-public',
publicServiceDomain: 'public.example.com'
},
deployment: {
id: 1,
smtpServerHostname: 'smtp.example.com',
smtpServerPort: '587',
smtpServerUsername: 'user@example.com',
smtpServerPassword: 'password',
defaultNamespace: 'default',
defaultStorageClass: 'standard',
namespaceConfigOption: NamespaceConfigOption.USE_DEFAULT_NAMESPACE,
forceDedicatedWorkers: false
}
};
beforeEach(waitForAsync(() => {
const clusterServiceSpy = jasmine.createSpyObj('ClusterManagerService', ['getClusterDetails', 'sendCluster', 'updateCluster']);
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
mockActivatedRoute = {
params: of({ id: 1 })
};
TestBed.configureTestingModule({
declarations: [ClusterManagerDetailsComponent],
imports: [FormsModule,
CommonModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateFakeLoader
}
}),
],
providers: [
{ provide: ClusterManagerService, useValue: clusterServiceSpy },
{ provide: Router, useValue: routerSpy },
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
DatePipe
],
schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
clusterService = TestBed.inject(ClusterManagerService) as jasmine.SpyObj<ClusterManagerService>;
mockRouter = TestBed.inject(Router) as jasmine.SpyObj<Router>;
}));
beforeEach(() => {
fixture = TestBed.createComponent(ClusterManagerDetailsComponent);
component = fixture.componentInstance;
component.controllerConfigOption = new Map<string, IngressControllerConfigOption>();
component.resourceConfigOption = new Map<string, IngressResourceConfigOption>();
component.namespaceConfigOption = new Map<string, NamespaceConfigOption>();
component.certificateConfigOption = new Map<string, IngressCertificateConfigOption>();
clusterService.getClusterDetails.and.returnValue(of(mockCluster));
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should initialize and fetch cluster details', () => {
expect(clusterService.getClusterDetails).toHaveBeenCalledWith(1);
expect(component.cluster).toEqual(mockCluster);
});
it('should add a new network', () => {
component.cluster = { ...mockCluster, externalNetworks: [] };
component.addNetwork();
expect(component.cluster.externalNetworks.length).toBe(1);
});
it('should remove a network by id', () => {
component.cluster = {
...mockCluster,
externalNetworks: [{
id: 1,
assigned: false,
assignedSince: '',
assignedTo: '',
externalIp: '',
externalNetwork: '',
externalNetworkMaskLength: 0
}, {
id: 2,
assigned: false,
assignedSince: '',
assignedTo: '',
externalIp: '',
externalNetwork: '',
externalNetworkMaskLength: 0
}]
};
component.removeNetwork(1);
expect(component.cluster.externalNetworks.length).toBe(1);
expect(component.cluster.externalNetworks[0].id).toBe(2);
});
it('should format date correctly', () => {
const date = new Date('2025-01-01T12:00:00');
const formattedDate = component.formatDate(date);
expect(formattedDate).toBe('01-01-2025 12:00');
});
it('should submit updated cluster', () => {
const updatedCluster = { ...mockCluster, name: 'Updated Cluster' };
clusterService.updateCluster.and.returnValue(of(updatedCluster));
component.cluster = mockCluster;
component.submit();
expect(clusterService.updateCluster).toHaveBeenCalledWith(mockCluster);
expect(component.cluster).toEqual(updatedCluster);
});
it('should send cluster with file', () => {
const mockFile = new File(['test content'], 'test.yaml', { type: 'application/x-yaml' });
const mockEvent = { files: [mockFile] };
const mockResponse: ClusterManager = {
id: 1,
name: 'Test Cluster',
description: 'Test Description',
externalNetworks: [],
creationDate: new Date('2025-01-01'),
modificationDate: new Date('2025-02-01'),
codename: 'test-cluster',
pathConfigFile: '/path/to/config.yaml',
clusterConfigFile: 'Config',
ingress: null,
deployment: null
};
clusterService.sendCluster.and.returnValue(of(mockResponse));
component.sendCluster(mockEvent);
expect(clusterService.sendCluster).toHaveBeenCalledWith(mockFile, jasmine.any(ClusterManager));
});
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment