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