blob: 87affe153ae1ecfcc9fb927ebe5d62f59c069f44 [file] [log] [blame]
Sean Condon0d064ec2019-02-04 21:53:53 +00001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
17
18import { MapSelectorComponent } from './mapselector.component';
19import {FormsModule, ReactiveFormsModule} from '@angular/forms';
20import {ActivatedRoute, Params} from '@angular/router';
21import {of} from 'rxjs';
Sean Condon3dd062f2020-04-14 09:25:00 +010022import {FnService, LogService} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condon0d064ec2019-02-04 21:53:53 +000023
24class MockActivatedRoute extends ActivatedRoute {
25 constructor(params: Params) {
26 super();
27 this.queryParams = of(params);
28 }
29}
30
31describe('MapSelectorComponent', () => {
32 let fs: FnService;
33 let ar: MockActivatedRoute;
34 let windowMock: Window;
35 let logServiceSpy: jasmine.SpyObj<LogService>;
36 let component: MapSelectorComponent;
37 let fixture: ComponentFixture<MapSelectorComponent>;
38
39 beforeEach(async(() => {
40 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
41 ar = new MockActivatedRoute({ 'debug': 'txrx' });
42
43 windowMock = <any>{
44 location: <any>{
45 hostname: 'foo',
46 host: 'foo',
47 port: '80',
48 protocol: 'http',
49 search: { debug: 'true' },
50 href: 'ws://foo:123/onos/ui/websock/path',
51 absUrl: 'ws://foo:123/onos/ui/websock/path'
52 }
53 };
54 fs = new FnService(ar, logSpy, windowMock);
55
56 TestBed.configureTestingModule({
57 imports: [
58 FormsModule,
59 ReactiveFormsModule
60 ],
61 declarations: [ MapSelectorComponent ],
62 providers: [
63 { provide: FnService, useValue: fs },
64 { provide: LogService, useValue: logSpy },
65 { provide: 'Window', useValue: windowMock },
66 ]
67 })
68 .compileComponents();
69 logServiceSpy = TestBed.get(LogService);
70 }));
71
72 beforeEach(() => {
73 fixture = TestBed.createComponent(MapSelectorComponent);
74 component = fixture.componentInstance;
75 fixture.detectChanges();
76 });
77
78 it('should create', () => {
79 expect(component).toBeTruthy();
80 });
81});
82
83// Expecting WebSocket request and response similar to:
84//
85// {"event":"mapSelectorRequest","payload":{}}
86//
87// {
88// "event": "mapSelectorResponse",
89// "payload": {
90// "order": ["australia", "americas", "n_america", "s_america", "usa", "bayareaGEO",
91// "europe", "italy", "uk", "japan", "s_korea", "taiwan", "africa", "oceania", "asia"],
92// "maps": {
93// "australia": {
94// "id": "australia",
95// "description": "Australia",
96// "filePath": "*australia",
97// "scale": 1.0
98// },