Skip to content

Commit

Permalink
fix: update dashboard unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Jun 3, 2024
1 parent d517507 commit 8ee9221
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 344 deletions.
17 changes: 15 additions & 2 deletions projects/aas-lib/src/test/auth/auth.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { CommonModule } from '@angular/common';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgbActiveModal, NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { NotifyService } from '../../lib/notify/notify.service';
import { AuthService } from '../../lib/auth/auth.service';

import { AuthComponent } from '../../lib/auth/auth.component';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';

describe('AuthComponent', () => {
let component: AuthComponent;
Expand All @@ -35,7 +36,19 @@ describe('AuthComponent', () => {
useValue: jasmine.createSpyObj<NotifyService>(['error', 'info']),
},
],
imports: [HttpClientTestingModule, CommonModule, FormsModule, ReactiveFormsModule, NgbModule],
imports: [
HttpClientTestingModule,
CommonModule,
FormsModule,
ReactiveFormsModule,
NgbModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateFakeLoader,
},
}),
],
});

fixture = TestBed.createComponent(AuthComponent);
Expand Down
26 changes: 13 additions & 13 deletions projects/aas-portal/src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'chart.js/auto';
import { WebSocketSubject } from 'rxjs/webSocket';
import { Observable, Subscription, map } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { AsyncPipe, NgClass } from '@angular/common';
import { FormsModule } from '@angular/forms';
import {
AfterViewInit,
AfterViewChecked,
Expand All @@ -26,7 +28,7 @@ import {
import isNumber from 'lodash-es/isNumber';
import { Chart, ChartConfiguration, ChartDataset, ChartType } from 'chart.js';
import { aas, convertToString, LiveNode, LiveRequest, parseNumber, WebSocketData } from 'common';
import * as lib from 'aas-lib';
import { ClipboardService, LogType, NotifyService, WebSocketFactoryService, WindowService } from 'aas-lib';

import { SelectionMode } from '../types/selection-mode';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -55,8 +57,6 @@ import {
DashboardRow,
DashboardService,
} from './dashboard.service';
import { AsyncPipe, NgClass } from '@angular/common';
import { FormsModule } from '@angular/forms';

interface UpdateTuple {
item: DashboardChart;
Expand Down Expand Up @@ -94,21 +94,21 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit, Aft
private readonly api: DashboardApiService,
private readonly activeRoute: ActivatedRoute,
private readonly translate: TranslateService,
private readonly webServiceFactory: lib.WebSocketFactoryService,
private readonly webServiceFactory: WebSocketFactoryService,
private readonly dashboard: DashboardService,
private readonly notify: lib.NotifyService,
private readonly notify: NotifyService,
private readonly toolbar: ToolbarService,
private readonly commandHandler: CommandHandlerService,
private readonly window: lib.WindowService,
private readonly clipboard: lib.ClipboardService,
private readonly window: WindowService,
private readonly clipboard: ClipboardService,
) {
this.rows = this.dashboard.activePage.pipe(
map(page =>
this.dashboard.getGrid(page).map(row => ({
columns: row.map(item => ({
id: item.id,
item: item,
itemType: item.type,
this.dashboard.getGrid(page).map(rows => ({
columns: rows.map(row => ({
id: row.id,
item: row,
itemType: row.type,
})),
})),
),
Expand Down Expand Up @@ -375,7 +375,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit, Aft
}
}
} catch (error) {
this.notify.log(lib.LogType.Error, error);
this.notify.log(LogType.Error, error);
}

return color ?? '#ffffff';
Expand Down
10 changes: 8 additions & 2 deletions projects/aas-portal/src/app/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Injectable } from '@angular/core';
import { v4 as uuid } from 'uuid';
import cloneDeep from 'lodash-es/cloneDeep';
import { BehaviorSubject, EMPTY, first, map, mergeMap, Observable, of, takeWhile } from 'rxjs';
import { BehaviorSubject, catchError, EMPTY, first, map, mergeMap, Observable, of } from 'rxjs';
import { encodeBase64Url, AuthService } from 'aas-lib';
import { aas, AASDocument, ApplicationError, getIdShortPath, getUnit, LiveNode, LiveRequest } from 'common';

Expand Down Expand Up @@ -107,7 +107,9 @@ export class DashboardService {
this.auth.getCookie('.DashboardPage').pipe(
map(value =>
this.auth.getCookie('.DashboardPages').pipe(
mergeMap(data => (data ? of(JSON.parse(data) as DashboardPage[]) : EMPTY)),
mergeMap(data => {
return data ? of(JSON.parse(data) as DashboardPage[]) : EMPTY;
}),
map(pages => {
this._pages = pages;
this.index$.next(
Expand All @@ -121,6 +123,10 @@ export class DashboardService {
),
),
),
catchError(error => {
console.error(error);
return EMPTY;
}),
)
.subscribe();
}
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export interface LinkDescriptor {
RouterOutlet,
RouterLink,
AsyncPipe,
NotifyComponent,
LocalizeComponent,
AuthComponent,
NgbNavModule,
NgTemplateOutlet,
TranslateModule,
NotifyComponent,
LocalizeComponent,
AuthComponent,
],
})
export class MainComponent implements OnInit, OnDestroy {
Expand Down

This file was deleted.

Loading

0 comments on commit 8ee9221

Please sign in to comment.