Skip to content

Commit

Permalink
NAS-131558: Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 committed Dec 12, 2024
1 parent cd2bcd9 commit 3aa9e5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fakeAsync } from '@angular/core/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { MockComponents } from 'ng-mocks';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('WidgetAppComponent', () => {
mockProvider(WidgetResourcesService, {
serverTime$: of(new Date()),
getApp: () => of(app),
getAppStats: () => of(),
getAppStats: () => of({}),
getAppStatusUpdates: () => of(),
}),
mockProvider(RedirectService, {
Expand Down Expand Up @@ -99,13 +100,14 @@ describe('WidgetAppComponent', () => {
});
});

it('checks components', () => {
it('checks components', fakeAsync(() => {
spectator.detectChanges();
expect(spectator.query(AppControlsComponent)).toBeTruthy();
expect(spectator.query(AppCardLogoComponent)).toBeTruthy();
expect(spectator.query(AppCardInfoComponent)).toBeTruthy();
expect(spectator.query(AppCpuInfoComponent)).toBeTruthy();
expect(spectator.query(AppMemoryInfoComponent)).toBeTruthy();
expect(spectator.query(AppNetworkInfoComponent)).toBeTruthy();
expect(spectator.query(AppDiskInfoComponent)).toBeTruthy();
});
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Component, ChangeDetectionStrategy, input,
computed,
effect,
ChangeDetectorRef,
} from '@angular/core';
import { MatCard, MatCardContent } from '@angular/material/card';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -47,14 +48,18 @@ export class WidgetAppComponent implements WidgetComponent<WidgetAppSettings> {
size = input.required<SlotSize>();
settings = input.required<WidgetAppSettings>();

appName = computed(() => this.settings().appName);
app = computed(() => this.resources.getApp(this.appName()));
job = computed(() => this.resources.getAppStatusUpdates(this.appName()));
stats$: Observable<LoadingState<AppStats>>;
protected appName = computed(() => this.settings().appName);
protected app = computed(() => this.resources.getApp(this.appName()));
protected job = computed(() => this.resources.getAppStatusUpdates(this.appName()));
protected stats$: Observable<LoadingState<AppStats>>;

effect = effect(() => {
this.stats$ = this.resources.getAppStats(this.appName());
this.cdr.markForCheck();
});

constructor(private resources: WidgetResourcesService) {}
constructor(
private resources: WidgetResourcesService,
private cdr: ChangeDetectorRef,
) {}
}

0 comments on commit 3aa9e5f

Please sign in to comment.