From 081f9a9846fc8ece6706c1e29c6d05399d7e4784 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Thu, 20 Mar 2025 09:43:33 +0100 Subject: [PATCH 1/2] Enhance unit tests for ConvertImageToVirtualComponent with improved mock services and dependencies --- ...convert-image-to-virtual.component.spec.ts | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/ogWebconsole/src/app/components/repositories/convert-image-to-virtual/convert-image-to-virtual.component.spec.ts b/ogWebconsole/src/app/components/repositories/convert-image-to-virtual/convert-image-to-virtual.component.spec.ts index be42a50..6f25a05 100644 --- a/ogWebconsole/src/app/components/repositories/convert-image-to-virtual/convert-image-to-virtual.component.spec.ts +++ b/ogWebconsole/src/app/components/repositories/convert-image-to-virtual/convert-image-to-virtual.component.spec.ts @@ -1,16 +1,45 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ConvertImageToVirtualComponent } from './convert-image-to-virtual.component'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { ToastrModule } from 'ngx-toastr'; +import { ConfigService } from '@services/config.service'; describe('ConvertImageToVirtualComponent', () => { let component: ConvertImageToVirtualComponent; let fixture: ComponentFixture; beforeEach(async () => { + const mockConfigService = { + apiUrl: 'http://mock-api-url' + }; await TestBed.configureTestingModule({ - declarations: [ConvertImageToVirtualComponent] + declarations: [ConvertImageToVirtualComponent], + imports: [ + MatDialogModule, + ToastrModule.forRoot() + ], + providers: [ + provideHttpClient(), + provideHttpClientTesting(), + { + provide: MatDialogRef, + useValue: {} + }, + { + provide: MAT_DIALOG_DATA, + useValue: {} + }, + { + provide: ConfigService, + useValue: mockConfigService + } + ], + schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); fixture = TestBed.createComponent(ConvertImageToVirtualComponent); component = fixture.componentInstance; @@ -20,4 +49,4 @@ describe('ConvertImageToVirtualComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); -}); +}); \ No newline at end of file From 3d62161aaabde3e43be015ed928f817368e105b8 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Thu, 20 Mar 2025 11:07:38 +0100 Subject: [PATCH 2/2] refs #1725 Add support for DHCP and subnets in Global Status component --- .../global-status.component.html | 8 ++++-- .../global-status/global-status.component.ts | 24 ++++++++++++---- .../status-tab/status-tab.component.html | 28 ++++++++++++------- .../status-tab/status-tab.component.ts | 3 +- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/ogWebconsole/src/app/components/global-status/global-status.component.html b/ogWebconsole/src/app/components/global-status/global-status.component.html index 886dfe7..dce42df 100644 --- a/ogWebconsole/src/app/components/global-status/global-status.component.html +++ b/ogWebconsole/src/app/components/global-status/global-status.component.html @@ -13,7 +13,8 @@ [view]="view" [colorScheme]="colorScheme" [isDoughnut]="isDoughnut" - [showLabels]="showLabels"> + [showLabels]="showLabels" + [isDhcp]="isDhcp"> @@ -22,12 +23,13 @@ [loading]="loading" [diskUsage]="dhcpDiskUsage" [servicesStatus]="dhcpServicesStatus" - [installedOgLives]="installedOgLives" + [subnets]="subnets" [diskUsageChartData]="dhcpDiskUsageChartData" [view]="view" [colorScheme]="colorScheme" [isDoughnut]="isDoughnut" - [showLabels]="showLabels"> + [showLabels]="showLabels" + [isDhcp]="isDhcp"> diff --git a/ogWebconsole/src/app/components/global-status/global-status.component.ts b/ogWebconsole/src/app/components/global-status/global-status.component.ts index bc0812f..6272b4b 100644 --- a/ogWebconsole/src/app/components/global-status/global-status.component.ts +++ b/ogWebconsole/src/app/components/global-status/global-status.component.ts @@ -13,6 +13,7 @@ export class GlobalStatusComponent implements OnInit { baseUrl: string; loading: boolean = false; installedOgLives: any[] = []; + subnets: any[] = []; showLabels: boolean = true; isDoughnut: boolean = true; colorScheme: any = { @@ -29,6 +30,7 @@ export class GlobalStatusComponent implements OnInit { dhcpDiskUsage: any = {}; dhcpServicesStatus: any = {}; dhcpDiskUsageChartData: any[] = []; + isDhcp: boolean = false; constructor( private configService: ConfigService, @@ -44,7 +46,7 @@ export class GlobalStatusComponent implements OnInit { this.loadOgBootStatus(); } - loadStatus(apiUrl: string, diskUsage: any, servicesStatus: any, diskUsageChartData: any[], installedOgLives: any[]): void { + loadStatus(apiUrl: string, diskUsage: any, servicesStatus: any, diskUsageChartData: any[], installedOgLives: any[], isDhcp: boolean): void { this.loading = true; const timeoutId = setTimeout(() => { this.loading = false; @@ -58,9 +60,17 @@ export class GlobalStatusComponent implements OnInit { diskUsage.percentage = data.message.disk_usage.percentage; Object.assign(servicesStatus, data.message.services_status); - installedOgLives.length = 0; - if (data.message.installed_oglives) { - installedOgLives.push(...data.message.installed_oglives); + + if (isDhcp) { + this.subnets.length = 0; + if (data.message.subnets) { + this.subnets.push(...data.message.subnets); + } + } else { + installedOgLives.length = 0; + if (data.message.installed_oglives) { + installedOgLives.push(...data.message.installed_oglives); + } } diskUsageChartData.length = 0; @@ -82,11 +92,13 @@ export class GlobalStatusComponent implements OnInit { } loadOgBootStatus(): void { - this.loadStatus(this.ogBootApiUrl, this.ogBootDiskUsage, this.ogBootServicesStatus, this.ogBootDiskUsageChartData, this.installedOgLives); + this.isDhcp = false; + this.loadStatus(this.ogBootApiUrl, this.ogBootDiskUsage, this.ogBootServicesStatus, this.ogBootDiskUsageChartData, this.installedOgLives, this.isDhcp); } loadDhcpStatus(): void { - this.loadStatus(this.dhcpApiUrl, this.dhcpDiskUsage, this.dhcpServicesStatus, this.dhcpDiskUsageChartData, this.installedOgLives); + this.isDhcp = true; + this.loadStatus(this.dhcpApiUrl, this.dhcpDiskUsage, this.dhcpServicesStatus, this.dhcpDiskUsageChartData, this.installedOgLives, this.isDhcp); } onTabChange(event: MatTabChangeEvent): void { diff --git a/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.html b/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.html index c94d266..0893c75 100644 --- a/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.html +++ b/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.html @@ -31,24 +31,32 @@ - +
-

{{ 'installedOglivesTitle' | translate }}

+

{{ isDhcp ? ('subnets' | translate) : ('InstalledOglivesTitle' | translate)}}

- - - + + + + + + + - - - - - + + + + + + + + +
{{ 'idLabel' | translate }}{{ 'kernelLabel' | translate }}{{ 'architectureLabel' | translate }}{{ 'revisionLabel' | translate }}{{ 'kernelLabel' | translate }}{{ 'architectureLabel' | translate }}{{ 'revisionLabel' | translate }}{{ 'bootFileNameLabel' | translate }}{{ 'nextServerLabel' | translate }}{{ 'ipLabel' | translate }}{{ 'clientsLabel' | translate }}
{{ oglive.id }}{{ oglive.kernel }}{{ oglive.architecture }}{{ oglive.revision }}
{{ item.id }}{{ item.kernel }}{{ item.architecture }}{{ item.revision }}{{ item['boot-file-name'] }}{{ item['next-server'] }}{{ item.subnet }}{{ item.reservations.length }}
diff --git a/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.ts b/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.ts index 00efd4d..e92d6ab 100644 --- a/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.ts +++ b/ogWebconsole/src/app/components/global-status/status-tab/status-tab.component.ts @@ -10,6 +10,7 @@ export class StatusTabComponent { @Input() diskUsage: any = {}; @Input() servicesStatus: any = {}; @Input() installedOgLives: any[] = []; + @Input() subnets: any[] = []; @Input() diskUsageChartData: any[] = []; @Input() showLabels: boolean = true; @Input() isDoughnut: boolean = true; @@ -17,6 +18,7 @@ export class StatusTabComponent { domain: ['#df200d', '#26a700'] }; @Input() view: [number, number] = [400, 220]; + @Input() isDhcp: boolean = false; getServices(): { name: string, status: string }[] { if (!this.servicesStatus) { @@ -26,7 +28,6 @@ export class StatusTabComponent { name: key, status: this.servicesStatus[key] })) - console.log(services) return services; }