blob: b32538b549aca1f54845a4ba4530d3f64346cef3 [file] [log] [blame]
prai9d445962018-07-27 13:27:43 +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';
17import { ActivatedRoute, Params } from '@angular/router';
18import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { FormsModule } from '@angular/forms';
20import { DebugElement } from '@angular/core';
21import { By } from '@angular/platform-browser';
22import { ConfirmComponent } from '../../../fw/layer/confirm/confirm.component';
23import { FlashComponent } from '../../../fw/layer/flash/flash.component';
24
25import { LogService } from '../../../log.service';
26import { FnService } from '../../../fw/util/fn.service';
27import { IconComponent } from '../../../fw/svg/icon/icon.component';
28import { IconService } from '../../../fw/svg/icon.service';
29import { LoadingService } from '../../../fw/layer/loading.service';
30import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe';
31import { WebSocketService } from '../../../fw/remote/websocket.service';
32import { of } from 'rxjs';
33import { } from 'jasmine';
34
35import { IntentComponent } from './intent.component';
36
37class MockActivatedRoute extends ActivatedRoute {
38 constructor(params: Params) {
39 super();
40 this.queryParams = of(params);
41 }
42}
43
44class MockIconService {
45 loadIconDef() { }
46}
47
48class MockLoadingService {
49 startAnim() { }
50 stop() { }
51 waiting() { }
52}
53
54class MockWebSocketService {
55 createWebSocket() { }
56 isConnected() { return false; }
57 unbindHandlers() { }
58 bindHandlers() { }
59}
60
61describe('IntentComponent', () => {
62 let fs: FnService;
63 let ar: MockActivatedRoute;
64 let windowMock: Window;
65 let logServiceSpy: jasmine.SpyObj<LogService>;
66 let component: IntentComponent;
67 let fixture: ComponentFixture<IntentComponent>;
68
69 const bundleObj = {
70 'core.view.Intent': {
71 test: 'test1'
72 }
73 };
74
75 beforeEach(async(() => {
76 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
77 ar = new MockActivatedRoute({ 'debug': 'txrx' });
78
79 windowMock = <any>{
80 location: <any>{
81 hostname: 'foo',
82 host: 'foo',
83 port: '80',
84 protocol: 'http',
85 search: { debug: 'true' },
86 href: 'ws://foo:123/onos/ui/websock/path',
87 absUrl: 'ws://foo:123/onos/ui/websock/path'
88 }
89 };
90 fs = new FnService(ar, logSpy, windowMock);
91 TestBed.configureTestingModule({
92 imports: [BrowserAnimationsModule, FormsModule],
93 declarations: [IntentComponent, IconComponent, TableFilterPipe, ConfirmComponent, FlashComponent],
94 providers: [
95 { provide: FnService, useValue: fs },
96 { provide: IconService, useClass: MockIconService },
97 { provide: LoadingService, useClass: MockLoadingService },
98 { provide: LogService, useValue: logSpy },
99 { provide: WebSocketService, useClass: MockWebSocketService },
100 { provide: 'Window', useValue: windowMock },
101 ]
102 })
103 .compileComponents();
104 logServiceSpy = TestBed.get(LogService);
105 }));
106
107 beforeEach(() => {
108 fixture = TestBed.createComponent(IntentComponent);
109 component = fixture.componentInstance;
110 fixture.detectChanges();
111 });
112
113 it('should create', () => {
114 expect(component).toBeTruthy();
115 });
116
117 it('should have a div.tabular-header inside a div#ov-intent', () => {
118 const hostDe: DebugElement = fixture.debugElement;
119 const divDe = hostDe.query(By.css('div#ov-intent div.tabular-header'));
120 expect(divDe).toBeTruthy();
121 });
122
123 it('should have a h2 inside the div.tabular-header', () => {
124 const hostDe: DebugElement = fixture.debugElement;
125 const divDe = hostDe.query(By.css('div#ov-intent div.tabular-header h2'));
126 const div: HTMLElement = divDe.nativeElement;
127 expect(div.textContent).toEqual(' Intents (0 total) ');
128 });
129
130 it('should have a refresh button inside the div.tabular-header', () => {
131 const hostDe: DebugElement = fixture.debugElement;
132 const divDe = hostDe.query(By.css('div#ov-intent div.tabular-header div.ctrl-btns div.refresh'));
133 expect(divDe).toBeTruthy();
134 });
135
136 it('should have a div.summary-list inside a div#ov-intent', () => {
137 const hostDe: DebugElement = fixture.debugElement;
138 const divDe = hostDe.query(By.css('div#ov-intent div.summary-list'));
139 expect(divDe).toBeTruthy();
140 });
141
142 it('should have a div.table-header inside a div.summary-list inside a div#ov-intent', () => {
143 const hostDe: DebugElement = fixture.debugElement;
144 const divDe = hostDe.query(By.css('div#ov-intent div.summary-list div.table-header'));
145 expect(divDe).toBeTruthy();
146 });
147
148 it('should have a div.table-body inside a div.summary-list inside a div#ov-intent', () => {
149 const hostDe: DebugElement = fixture.debugElement;
150 const divDe = hostDe.query(By.css('div#ov-intent div.summary-list div.table-body'));
151 expect(divDe).toBeTruthy();
152 });
153});