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