Skip to content

Commit

Permalink
fixed tests; #SNRGY-3008
Browse files Browse the repository at this point in the history
  • Loading branch information
hahahannes committed Dec 11, 2023
1 parent 21219bb commit c16ffe1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DeviceInstancesFilterDialogComponent>;
const deviceInstanceServiceSpy: Spy<DeviceInstancesService> = createSpyFromClass(DeviceInstancesService);
deviceInstanceServiceSpy.listUsedDeviceTypeIds.and.returnValue(of(["id"]))
const matDialogRefSpy: Spy<MatDialogRef<DeviceInstancesFilterDialogComponent>> =
createSpyFromClass<MatDialogRef<DeviceInstancesFilterDialogComponent>>(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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<FilterSelection> {
const editDialogRef = this.dialog.open(DeviceInstancesFilterDialogComponent, {
data: filterSelection
});

return editDialogRef.afterClosed()
}

listUsedDeviceTypeIds(): Observable<string[]> {
return this.http
.post<{ term: string }[]>(environment.permissionSearchUrl + '/v3/query/devices', {
Expand Down

0 comments on commit c16ffe1

Please sign in to comment.