Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | |
| 18 | import { GroupComponent } from './group.component'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | import { |
| 20 | ConsoleLoggerService, |
| 21 | FnService, |
| 22 | IconService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 23 | IconComponent, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 24 | LogService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 25 | TableFilterPipe, |
| 26 | ThemeService, |
| 27 | UrlFnService, |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 28 | WebSocketService, LoadingComponent |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 29 | } from 'gui2-fw-lib'; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 30 | import { ActivatedRoute, Params } from '@angular/router'; |
| 31 | import { of } from 'rxjs'; |
| 32 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 33 | import { FormsModule } from '@angular/forms'; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 34 | import { RouterTestingModule } from '@angular/router/testing'; |
| 35 | import { DebugElement } from '@angular/core'; |
| 36 | import { By } from '@angular/platform-browser'; |
| 37 | |
| 38 | class MockActivatedRoute extends ActivatedRoute { |
| 39 | constructor(params: Params) { |
| 40 | super(); |
| 41 | this.queryParams = of(params); |
| 42 | } |
| 43 | } |
| 44 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 45 | class MockIconService { |
| 46 | loadIconDef() { } |
| 47 | } |
| 48 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 49 | class MockThemeService { } |
| 50 | |
| 51 | class MockUrlFnService { } |
| 52 | |
| 53 | class MockWebSocketService { |
| 54 | createWebSocket() { } |
| 55 | isConnected() { return false; } |
| 56 | unbindHandlers() { } |
| 57 | bindHandlers() { } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * ONOS GUI -- Group View Module - Unit Tests |
| 62 | */ |
| 63 | describe('GroupComponent', () => { |
| 64 | let component: GroupComponent; |
| 65 | let fixture: ComponentFixture<GroupComponent>; |
| 66 | let log: LogService; |
| 67 | let fs: FnService; |
| 68 | let ar: MockActivatedRoute; |
| 69 | let windowMock: Window; |
| 70 | const bundleObj = { |
| 71 | 'core.view.Group': { |
| 72 | test: 'test1', |
| 73 | tt_help: 'Help!' |
| 74 | } |
| 75 | }; |
| 76 | const mockLion = (key) => { |
| 77 | return bundleObj[key] || '%' + key + '%'; |
| 78 | }; |
| 79 | |
| 80 | beforeEach(async(() => { |
| 81 | log = new ConsoleLoggerService(); |
| 82 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 83 | |
| 84 | windowMock = <any>{ |
| 85 | location: <any>{ |
| 86 | hostname: 'foo', |
| 87 | host: 'foo', |
| 88 | port: '80', |
| 89 | protocol: 'http', |
| 90 | search: { debug: 'true' }, |
| 91 | href: 'ws://foo:123/onos/ui/websock/path', |
| 92 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 93 | } |
| 94 | }; |
| 95 | fs = new FnService(ar, log, windowMock); |
| 96 | |
| 97 | TestBed.configureTestingModule({ |
| 98 | imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule], |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 99 | declarations: [ |
| 100 | GroupComponent, |
| 101 | IconComponent, |
| 102 | TableFilterPipe, |
| 103 | LoadingComponent |
| 104 | ], |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 105 | providers: [ |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 106 | { provide: FnService, useValue: fs }, |
| 107 | { provide: IconService, useClass: MockIconService }, |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 108 | { provide: LogService, useValue: log }, |
| 109 | { provide: ThemeService, useClass: MockThemeService }, |
| 110 | { provide: UrlFnService, useClass: MockUrlFnService }, |
| 111 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 112 | { provide: 'Window', useValue: windowMock }, |
| 113 | ] |
| 114 | }) |
| 115 | .compileComponents(); |
| 116 | })); |
| 117 | |
| 118 | beforeEach(() => { |
| 119 | fixture = TestBed.createComponent(GroupComponent); |
| 120 | component = fixture.componentInstance; |
| 121 | fixture.detectChanges(); |
| 122 | }); |
| 123 | |
| 124 | it('should create', () => { |
| 125 | expect(component).toBeTruthy(); |
| 126 | }); |
| 127 | |
| 128 | it('should have a div.tabular-header inside a div#ov-group', () => { |
| 129 | const groupDe: DebugElement = fixture.debugElement; |
| 130 | const divDe = groupDe.query(By.css('div#ov-group div.tabular-header')); |
| 131 | expect(divDe).toBeTruthy(); |
| 132 | }); |
| 133 | |
| 134 | it('should have a h2 inside the div.tabular-header', () => { |
| 135 | const groupDe: DebugElement = fixture.debugElement; |
| 136 | const divDe = groupDe.query(By.css('div#ov-group div.tabular-header h2')); |
| 137 | const div: HTMLElement = divDe.nativeElement; |
| 138 | expect(div.textContent).toEqual(' Groups for Device (0 total) '); |
| 139 | }); |
| 140 | |
| 141 | it('should have a refresh button inside the div.tabular-header', () => { |
| 142 | const groupDe: DebugElement = fixture.debugElement; |
| 143 | const divDe = groupDe.query(By.css('div#ov-group div.tabular-header div.ctrl-btns div.refresh')); |
| 144 | expect(divDe).toBeTruthy(); |
| 145 | }); |
| 146 | |
| 147 | it('should have a div.summary-list inside a div#ov-group', () => { |
| 148 | const groupDe: DebugElement = fixture.debugElement; |
| 149 | const divDe = groupDe.query(By.css('div#ov-group div.summary-list')); |
| 150 | expect(divDe).toBeTruthy(); |
| 151 | }); |
| 152 | |
| 153 | it('should have a div.table-header inside a div.summary-list inside a div#ov-group', () => { |
| 154 | const groupDe: DebugElement = fixture.debugElement; |
| 155 | const divDe = groupDe.query(By.css('div#ov-group div.summary-list div.table-header')); |
| 156 | expect(divDe).toBeTruthy(); |
| 157 | }); |
| 158 | |
| 159 | it('should have a div.table-body inside a div.summary-list inside a div#ov-group', () => { |
| 160 | const groupDe: DebugElement = fixture.debugElement; |
| 161 | const divDe = groupDe.query(By.css('div#ov-group div.summary-list div.table-body')); |
| 162 | expect(divDe).toBeTruthy(); |
| 163 | }); |
| 164 | }); |