blob: c8bd2c82c19c341f2be28d9587252a7f1bbad4e6 [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,
Sean Condon5ca00262018-09-06 17:55:25 +010023 IconComponent,
Sean Condon5ca00262018-09-06 17:55:25 +010024 LogService,
Sean Condon5ca00262018-09-06 17:55:25 +010025 TableFilterPipe,
26 ThemeService,
27 UrlFnService,
Sean Condon95fb5742019-04-02 12:16:55 +010028 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010029} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053030import { ActivatedRoute, Params } from '@angular/router';
31import { of } from 'rxjs';
32import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
33import { FormsModule } from '@angular/forms';
Bhavesh72ead492018-07-19 16:29:18 +053034import { RouterTestingModule } from '@angular/router/testing';
35import { DebugElement } from '@angular/core';
36import { By } from '@angular/platform-browser';
37
38class MockActivatedRoute extends ActivatedRoute {
39 constructor(params: Params) {
40 super();
41 this.queryParams = of(params);
42 }
43}
44
Bhavesh72ead492018-07-19 16:29:18 +053045class MockIconService {
46 loadIconDef() { }
47}
48
Bhavesh72ead492018-07-19 16:29:18 +053049class MockThemeService { }
50
51class MockUrlFnService { }
52
53class MockWebSocketService {
54 createWebSocket() { }
55 isConnected() { return false; }
56 unbindHandlers() { }
57 bindHandlers() { }
58}
59
60/**
61 * ONOS GUI -- Group View Module - Unit Tests
62 */
63describe('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 Condon95fb5742019-04-02 12:16:55 +010099 declarations: [
100 GroupComponent,
101 IconComponent,
102 TableFilterPipe,
103 LoadingComponent
104 ],
Bhavesh72ead492018-07-19 16:29:18 +0530105 providers: [
Bhavesh72ead492018-07-19 16:29:18 +0530106 { provide: FnService, useValue: fs },
107 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +0530108 { 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});