Add test that PolicyControlComponent is created.
Cleaned away non functional sorting in PolicyTypeDataSource and made it
injectable.
Changed so PolicyTypeDataSource is injected in PolicyControlComponent
instead of created with new.
Change-Id: I8f6c80c37b9491b3508e34accecb669905376b38
Issue-ID: NONRTRIC-383
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
# OSx cruft
**/.DS_Store
+.history
# documentation
.tox
[
- {
- "name": "1",
- "schema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 1 policy type\",\"additionalProperties\":false,\"title\":\"1\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}"
- }
+ {
+ "name": "2",
+ "schema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 2 policy type\",\"additionalProperties\":false,\"title\":\"2\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}"
+ },
+ {
+ "name": "1",
+ "schema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"description\":\"Type 1 policy type\",\"additionalProperties\":false,\"title\":\"1\",\"type\":\"object\",\"properties\":{\"qosObjectives\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"priorityLevel\":{\"type\":\"number\"}},\"required\":[\"priorityLevel\"]},\"scope\":{\"additionalProperties\":false,\"type\":\"object\",\"properties\":{\"qosId\":{\"type\":\"string\"},\"ueId\":{\"type\":\"string\"}},\"required\":[\"ueId\",\"qosId\"]}},\"required\":[\"scope\",\"qosObjectives\"]}"
+ }
]
\ No newline at end of file
* ========================LICENSE_END===================================
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
+import { MatDialog } from '@angular/material/dialog';
+import { MatIconModule, MatSort, MatTableModule } from '@angular/material';
+import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
+import { of } from 'rxjs';
+import { NotificationService } from '../services/ui/notification.service';
import { PolicyControlComponent } from './policy-control.component';
-import { MatIconModule, MatTableModule } from '@angular/material';
-import { PolicyType } from '../interfaces/policy.types';
+import { PolicyTypeDataSource } from './policy-type.datasource';
+import { UiService } from '../services/ui/ui.service';
describe('PolicyControlComponent', () => {
let component: PolicyControlComponent;
let fixture: ComponentFixture<PolicyControlComponent>;
beforeEach(async(() => {
+ const policyTypeDataSourceSpy = jasmine.createSpyObj('PolicyTypeDataSource', [ 'connect', 'loadTable', 'disconnect' ]);
+ const policyType = {
+ name: "type1",
+ schema: "{}",
+ schemaObject: "{}"
+ }
+ policyTypeDataSourceSpy.connect.and.returnValue(of([ policyType]));
+ policyTypeDataSourceSpy.disconnect();
+
+ let matDialogStub: Partial<MatDialog>;
+ let notificationServiceStub: Partial<NotificationService>;
+
TestBed.configureTestingModule({
- imports: [ MatIconModule,MatTableModule ],
- declarations: [ PolicyControlComponent ]
+ imports: [
+ MatIconModule,
+ MatTableModule,
+ BrowserAnimationsModule
+ ],
+ schemas: [
+ CUSTOM_ELEMENTS_SCHEMA
+ ],
+ declarations: [
+ PolicyControlComponent
+ ],
+ providers: [
+ { provide: PolicyTypeDataSource, useValue: policyTypeDataSourceSpy },
+ { provide: MatDialog, useValue: matDialogStub },
+ { provide: NotificationService, useValue: notificationServiceStub },
+ UiService
+ ]
})
.compileComponents();
}));
fixture.detectChanges();
});
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
});
*/
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
-import { MatSort } from '@angular/material/sort';
import { animate, state, style, transition, trigger } from '@angular/animations';
-import { PolicyService } from '../services/policy/policy.service';
import { PolicyType } from '../interfaces/policy.types';
import { PolicyTypeDataSource } from './policy-type.datasource';
import { getPolicyDialogProperties } from './policy-instance-dialog.component';
})
export class PolicyControlComponent implements OnInit {
-
- policyTypesDataSource: PolicyTypeDataSource;
- @ViewChild(MatSort, { static: true }) sort: MatSort;
-
policyTypeInfo = new Map<string, PolicyTypeInfo>();
darkMode: boolean;
constructor(
- private policySvc: PolicyService,
+ private policyTypesDataSource: PolicyTypeDataSource,
private dialog: MatDialog,
private notificationService: NotificationService,
private ui: UiService) { }
ngOnInit() {
- this.policyTypesDataSource = new PolicyTypeDataSource(this.policySvc, this.sort, this.notificationService);
this.policyTypesDataSource.loadTable();
this.ui.darkModeState.subscribe((isDark) => {
this.darkMode = isDark;
import { CollectionViewer, DataSource } from '@angular/cdk/collections';
import { HttpErrorResponse } from '@angular/common/http';
-import { MatSort } from '@angular/material';
-import { Observable } from 'rxjs/Observable';
+import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
-import { merge } from 'rxjs';
import { of } from 'rxjs/observable/of';
import { catchError, finalize, map } from 'rxjs/operators';
+import { Observable } from 'rxjs/Observable';
+
import { PolicyType } from '../interfaces/policy.types';
import { PolicyService } from '../services/policy/policy.service';
import { NotificationService } from '../services/ui/notification.service';
+@Injectable({
+ providedIn: 'root'
+})
+
export class PolicyTypeDataSource extends DataSource<PolicyType> {
private policyTypeSubject = new BehaviorSubject<PolicyType[]>([]);
public rowCount = 1; // hide footer during intial load
constructor(private policySvc: PolicyService,
- private sort: MatSort,
private notificationService: NotificationService) {
super();
}
}
connect(collectionViewer: CollectionViewer): Observable<PolicyType[]> {
- const dataMutations = [
- this.policyTypeSubject.asObservable(),
- this.sort.sortChange
- ];
- return merge(...dataMutations).pipe(map(() => {
- return this.getSortedData([...this.policyTypeSubject.getValue()]);
- }));
+ return of(this.policyTypeSubject.getValue());
}
disconnect(collectionViewer: CollectionViewer): void {
this.policyTypeSubject.complete();
this.loadingSubject.complete();
}
-
- private getSortedData(data: PolicyType[]) {
- if (!this.sort.active || this.sort.direction === '') {
- return data;
- }
-
- return data.sort((a, b) => {
- const isAsc = this.sort.direction === 'asc';
- switch (this.sort.active) {
- case 'name': return compare(a.name, b.name, isAsc);
- default: return 0;
- }
- });
- }
-}
-
-function compare(a: any, b: any, isAsc: boolean) {
- return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}