diff --git a/src/app/modules/devices/device-instances/device-instances.component.ts b/src/app/modules/devices/device-instances/device-instances.component.ts index 398ea73c..c8274af1 100644 --- a/src/app/modules/devices/device-instances/device-instances.component.ts +++ b/src/app/modules/devices/device-instances/device-instances.component.ts @@ -36,6 +36,8 @@ import { SelectionModel } from '@angular/cdk/collections'; import { MatPaginator } from '@angular/material/paginator'; import { forkJoin, Observable, map, Subscription, of } from 'rxjs'; import { SearchbarService } from 'src/app/core/components/searchbar/shared/searchbar.service'; +import { DeviceInstancesFilterDialogComponent } from './dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component'; +import { MatDialog } from '@angular/material/dialog'; export interface DeviceInstancesRouterState { type: DeviceInstancesRouterStateTypesEnum | undefined | null; @@ -72,10 +74,9 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit { private snackBar: MatSnackBar, private permissionsDialogService: PermissionsDialogService, private dialogsService: DialogsService, - private locationsService: LocationsService, - private networksService: NetworksService, private deviceTypesService: DeviceTypeService, - private searchbarService: SearchbarService + private searchbarService: SearchbarService, + private dialog: MatDialog ) { this.getRouterParams(); } @@ -181,7 +182,10 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit { location: this.routerLocation } - this.deviceInstancesService.openFilterDialog(filterSelection).subscribe({ + const editDialogRef = this.dialog.open(DeviceInstancesFilterDialogComponent, { + data: filterSelection + }); + editDialogRef.afterClosed().subscribe({ next: (filterSelection: FilterSelection) => { if(filterSelection != null) { this.routerConnectionState = filterSelection.connectionState diff --git a/src/app/modules/devices/device-instances/dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component.spec.ts b/src/app/modules/devices/device-instances/dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component.spec.ts index b356362e..1a77ba9a 100644 --- a/src/app/modules/devices/device-instances/dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component.spec.ts +++ b/src/app/modules/devices/device-instances/dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component.spec.ts @@ -1,14 +1,34 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; +import { createSpyFromClass, Spy } from 'jasmine-auto-spies'; +import { of } from 'rxjs'; +import { DeviceInstancesService } from '../../shared/device-instances.service'; import { DeviceInstancesFilterDialogComponent } from './device-instances-filter-dialog.component'; describe('DeviceInstancesFilterDialogComponent', () => { let component: DeviceInstancesFilterDialogComponent; let fixture: ComponentFixture; + const deviceInstanceServiceSpy: Spy = createSpyFromClass(DeviceInstancesService); + deviceInstanceServiceSpy.listUsedDeviceTypeIds.and.returnValue(of(["id"])) + const matDialogRefSpy: Spy> = + createSpyFromClass>(MatDialogRef); beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ DeviceInstancesFilterDialogComponent ] + declarations: [ DeviceInstancesFilterDialogComponent ], + imports: [HttpClientTestingModule, MatSnackBarModule, MatDialogModule], + providers: [ + { provide: DeviceInstancesService, useValue: deviceInstanceServiceSpy }, + { provide: MatDialogRef, useValue: matDialogRefSpy }, + { + provide: MAT_DIALOG_DATA, + useValue: { + }, + }, + ] }) .compileComponents(); diff --git a/src/app/modules/devices/device-instances/shared/device-instances.service.ts b/src/app/modules/devices/device-instances/shared/device-instances.service.ts index 65b5c2e4..f5fcb4b9 100644 --- a/src/app/modules/devices/device-instances/shared/device-instances.service.ts +++ b/src/app/modules/devices/device-instances/shared/device-instances.service.ts @@ -38,8 +38,6 @@ import { DeviceTypePermSearchModel } from 'src/app/modules/metadata/device-types import { PermissionQueryRequest, Selection } from 'src/app/core/model/permissions/permissions'; import { LocationsService } from '../../locations/shared/locations.service'; import { NetworksService } from '../../networks/shared/networks.service'; -import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; -import { DeviceInstancesFilterDialogComponent } from '../dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component'; @Injectable({ providedIn: 'root', @@ -57,19 +55,10 @@ export class DeviceInstancesService { private utilService: UtilService, private locationService: LocationsService, private networkService: NetworksService, - private dialog: MatDialog ) { this.authorizations = this.ladonService.getUserAuthorizationsForURI(environment.deviceManagerUrl) } - openFilterDialog(filterSelection: FilterSelection | undefined): Observable { - const editDialogRef = this.dialog.open(DeviceInstancesFilterDialogComponent, { - data: filterSelection - }); - - return editDialogRef.afterClosed() - } - listUsedDeviceTypeIds(): Observable { return this.http .post<{ term: string }[]>(environment.permissionSearchUrl + '/v3/query/devices', {