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