blob: 930533e74b1b2f49accaeac0636614390e1bdceb [file] [log] [blame]
Sean Condon50855cf2018-12-23 15:37:42 +00001/*
2 * Copyright 2018-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 */
Sean Condonf9fc0342020-03-22 12:55:57 +000016import {async, ComponentFixture, TestBed} from '@angular/core/testing';
Sean Condon0c577f62018-11-18 22:40:05 +000017
Sean Condonf9fc0342020-03-22 12:55:57 +000018import {HostNodeSvgComponent} from './hostnodesvg.component';
Sean Condon50855cf2018-12-23 15:37:42 +000019import {ActivatedRoute, Params} from '@angular/router';
20import {of} from 'rxjs';
21import {LogService} from 'gui2-fw-lib';
Sean Condonf9fc0342020-03-22 12:55:57 +000022import {Host, HostLabelToggle} from '../../models';
Sean Condon50855cf2018-12-23 15:37:42 +000023import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
24import {ChangeDetectorRef} from '@angular/core';
25
26class MockActivatedRoute extends ActivatedRoute {
27 constructor(params: Params) {
28 super();
29 this.queryParams = of(params);
30 }
31}
Sean Condon0c577f62018-11-18 22:40:05 +000032
33describe('HostNodeSvgComponent', () => {
Sean Condon50855cf2018-12-23 15:37:42 +000034 let logServiceSpy: jasmine.SpyObj<LogService>;
35 let component: HostNodeSvgComponent;
36 let fixture: ComponentFixture<HostNodeSvgComponent>;
37 let ar: MockActivatedRoute;
38 let testHost: Host;
Sean Condon0c577f62018-11-18 22:40:05 +000039
Sean Condonf9fc0342020-03-22 12:55:57 +000040 const topo2BaseData = require('../../tests/topo2Highlights-base-data.json');
41 const topo2BaseHostsData: Host[] = <Host[]><unknown>(topo2BaseData.payload.hosts[2]);
42
Sean Condon50855cf2018-12-23 15:37:42 +000043 beforeEach(async(() => {
44 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
45 ar = new MockActivatedRoute({ 'debug': 'txrx' });
46 testHost = new Host('host:1');
47 testHost.ips = ['10.205.86.123', '192.168.56.10'];
Sean Condon0c577f62018-11-18 22:40:05 +000048
Sean Condon50855cf2018-12-23 15:37:42 +000049 TestBed.configureTestingModule({
50 imports: [ BrowserAnimationsModule ],
51 declarations: [ HostNodeSvgComponent ],
52 providers: [
53 { provide: LogService, useValue: logSpy },
54 { provide: ActivatedRoute, useValue: ar },
55 { provide: ChangeDetectorRef, useClass: ChangeDetectorRef }
56 ]
57 })
58 .compileComponents();
59 logServiceSpy = TestBed.get(LogService);
60 }));
Sean Condon0c577f62018-11-18 22:40:05 +000061
Sean Condon50855cf2018-12-23 15:37:42 +000062 beforeEach(() => {
63 fixture = TestBed.createComponent(HostNodeSvgComponent);
64 component = fixture.componentInstance;
65 component.host = testHost;
66 fixture.detectChanges();
67 });
68
69 it('should create', () => {
70 expect(component).toBeTruthy();
71 });
Sean Condonf9fc0342020-03-22 12:55:57 +000072
73 it('should be able to read host data properly', () => {
74 expect(topo2BaseHostsData.length).toBe(5);
75
76 expect(topo2BaseHostsData[0].id).toBe('00:00:00:00:00:30/None');
77
78 component.host = topo2BaseHostsData[0];
79 component.labelToggle = HostLabelToggle.Enum.NONE;
80 expect(component.hostName()).toBe('00:00:00:00:00:30/None');
81
82 component.labelToggle = HostLabelToggle.Enum.NAME;
83 expect(component.hostName()).toBe('h3');
84
85 component.labelToggle = HostLabelToggle.Enum.IP;
86 expect(component.hostName()).toBe('2001:2:3::1');
87
88 component.labelToggle = HostLabelToggle.Enum.MAC;
89 expect(component.hostName()).toBe('00:00:00:00:00:30/None');
90
91 });
Sean Condon0c577f62018-11-18 22:40:05 +000092});