blob: ab5fff076d57de9ac31c52608907bda857db393a [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 Condonf9ff66a2020-03-23 08:40:55 +000016import {async, ComponentFixture, TestBed} from '@angular/core/testing';
Sean Condon0c577f62018-11-18 22:40:05 +000017
Sean Condonf9ff66a2020-03-23 08:40:55 +000018import {HostNodeSvgComponent} from './hostnodesvg.component';
Sean Condon50855cf2018-12-23 15:37:42 +000019import {ActivatedRoute, Params} from '@angular/router';
20import {of} from 'rxjs';
Sean Condona3ad7792020-01-04 19:26:34 +000021import {LogService} from 'gui2-fw-lib/public_api';
Sean Condonf9ff66a2020-03-23 08:40:55 +000022import {Host, HostLabelToggle} from '../../models';
Sean Condon50855cf2018-12-23 15:37:42 +000023import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
24import {ChangeDetectorRef} from '@angular/core';
Sean Condon590b34b2019-12-04 18:44:37 +000025import {BadgeSvgComponent} from '../badgesvg/badgesvg.component';
Sean Condon50855cf2018-12-23 15:37:42 +000026
27class MockActivatedRoute extends ActivatedRoute {
28 constructor(params: Params) {
29 super();
30 this.queryParams = of(params);
31 }
32}
Sean Condon0c577f62018-11-18 22:40:05 +000033
34describe('HostNodeSvgComponent', () => {
Sean Condon50855cf2018-12-23 15:37:42 +000035 let logServiceSpy: jasmine.SpyObj<LogService>;
36 let component: HostNodeSvgComponent;
37 let fixture: ComponentFixture<HostNodeSvgComponent>;
38 let ar: MockActivatedRoute;
39 let testHost: Host;
Sean Condon0c577f62018-11-18 22:40:05 +000040
Sean Condon50855cf2018-12-23 15:37:42 +000041 beforeEach(async(() => {
42 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
43 ar = new MockActivatedRoute({ 'debug': 'txrx' });
44 testHost = new Host('host:1');
45 testHost.ips = ['10.205.86.123', '192.168.56.10'];
Sean Condon0c577f62018-11-18 22:40:05 +000046
Sean Condonf9ff66a2020-03-23 08:40:55 +000047 const topo2BaseData = require('../../tests/topo2Highlights-base-data.json');
48 const topo2BaseHostsData: Host[] = <Host[]><unknown>(topo2BaseData.payload.hosts[2]);
49
Sean Condon50855cf2018-12-23 15:37:42 +000050 TestBed.configureTestingModule({
51 imports: [ BrowserAnimationsModule ],
Sean Condon590b34b2019-12-04 18:44:37 +000052 declarations: [ HostNodeSvgComponent, BadgeSvgComponent ],
Sean Condon50855cf2018-12-23 15:37:42 +000053 providers: [
54 { provide: LogService, useValue: logSpy },
55 { provide: ActivatedRoute, useValue: ar },
56 { provide: ChangeDetectorRef, useClass: ChangeDetectorRef }
57 ]
58 })
59 .compileComponents();
60 logServiceSpy = TestBed.get(LogService);
61 }));
Sean Condon0c577f62018-11-18 22:40:05 +000062
Sean Condon50855cf2018-12-23 15:37:42 +000063 beforeEach(() => {
64 fixture = TestBed.createComponent(HostNodeSvgComponent);
65 component = fixture.componentInstance;
66 component.host = testHost;
67 fixture.detectChanges();
68 });
69
70 it('should create', () => {
71 expect(component).toBeTruthy();
72 });
Sean Condonf9ff66a2020-03-23 08:40:55 +000073
74 it('should be able to read host data properly', () => {
75 expect(topo2BaseHostsData.length).toBe(5);
76
77 expect(topo2BaseHostsData[0].id).toBe('00:00:00:00:00:30/None');
78
79 component.host = topo2BaseHostsData[0];
80 component.labelToggle = HostLabelToggle.Enum.NONE;
81 expect(component.hostName()).toBe('00:00:00:00:00:30/None');
82
83 component.labelToggle = HostLabelToggle.Enum.NAME;
84 expect(component.hostName()).toBe('h3');
85
86 component.labelToggle = HostLabelToggle.Enum.IP;
87 expect(component.hostName()).toBe('2001:2:3::1');
88
89 component.labelToggle = HostLabelToggle.Enum.MAC;
90 expect(component.hostName()).toBe('00:00:00:00:00:30/None');
91
92 });
Sean Condon0c577f62018-11-18 22:40:05 +000093});