Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 1 | /* |
| 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 Condon | f9ff66a | 2020-03-23 08:40:55 +0000 | [diff] [blame] | 16 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 17 | |
Sean Condon | f9ff66a | 2020-03-23 08:40:55 +0000 | [diff] [blame] | 18 | import {HostNodeSvgComponent} from './hostnodesvg.component'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 19 | import {ActivatedRoute, Params} from '@angular/router'; |
| 20 | import {of} from 'rxjs'; |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 21 | import {LogService} from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | f9ff66a | 2020-03-23 08:40:55 +0000 | [diff] [blame] | 22 | import {Host, HostLabelToggle} from '../../models'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 23 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
| 24 | import {ChangeDetectorRef} from '@angular/core'; |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 25 | import {BadgeSvgComponent} from '../badgesvg/badgesvg.component'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 26 | |
| 27 | class MockActivatedRoute extends ActivatedRoute { |
| 28 | constructor(params: Params) { |
| 29 | super(); |
| 30 | this.queryParams = of(params); |
| 31 | } |
| 32 | } |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 33 | |
| 34 | describe('HostNodeSvgComponent', () => { |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 35 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 36 | let component: HostNodeSvgComponent; |
| 37 | let fixture: ComponentFixture<HostNodeSvgComponent>; |
| 38 | let ar: MockActivatedRoute; |
| 39 | let testHost: Host; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 40 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 41 | 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 Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 46 | |
Sean Condon | f9ff66a | 2020-03-23 08:40:55 +0000 | [diff] [blame] | 47 | const topo2BaseData = require('../../tests/topo2Highlights-base-data.json'); |
| 48 | const topo2BaseHostsData: Host[] = <Host[]><unknown>(topo2BaseData.payload.hosts[2]); |
| 49 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 50 | TestBed.configureTestingModule({ |
| 51 | imports: [ BrowserAnimationsModule ], |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 52 | declarations: [ HostNodeSvgComponent, BadgeSvgComponent ], |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 53 | 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 Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 62 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 63 | 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 Condon | f9ff66a | 2020-03-23 08:40:55 +0000 | [diff] [blame] | 73 | |
| 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 Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 93 | }); |