blob: b42147bf899a790ec6e44e115381a886f579c2ef [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';
Sean Condon4e55c802019-12-03 22:13:34 +000017import {ActivatedRoute, Params} from '@angular/router';
prai9d445962018-07-27 13:27:43 +053018import { 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';
Sean Condon4e55c802019-12-03 22:13:34 +000037import {RouterTestingModule} from '@angular/router/testing';
prai9d445962018-07-27 13:27:43 +053038
39class MockActivatedRoute extends ActivatedRoute {
40 constructor(params: Params) {
41 super();
42 this.queryParams = of(params);
43 }
44}
45
46class MockIconService {
47 loadIconDef() { }
48}
49
prai9d445962018-07-27 13:27:43 +053050class MockWebSocketService {
51 createWebSocket() { }
52 isConnected() { return false; }
53 unbindHandlers() { }
54 bindHandlers() { }
55}
56
57describe('IntentComponent', () => {
58 let fs: FnService;
59 let ar: MockActivatedRoute;
60 let windowMock: Window;
61 let logServiceSpy: jasmine.SpyObj<LogService>;
62 let component: IntentComponent;
63 let fixture: ComponentFixture<IntentComponent>;
64
65 const bundleObj = {
66 'core.view.Intent': {
67 test: 'test1'
68 }
69 };
70
71 beforeEach(async(() => {
72 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
73 ar = new MockActivatedRoute({ 'debug': 'txrx' });
74
75 windowMock = <any>{
76 location: <any>{
77 hostname: 'foo',
78 host: 'foo',
79 port: '80',
80 protocol: 'http',
81 search: { debug: 'true' },
82 href: 'ws://foo:123/onos/ui/websock/path',
83 absUrl: 'ws://foo:123/onos/ui/websock/path'
84 }
85 };
86 fs = new FnService(ar, logSpy, windowMock);
87 TestBed.configureTestingModule({
Sean Condon4e55c802019-12-03 22:13:34 +000088 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
Sean Condon95fb5742019-04-02 12:16:55 +010089 declarations: [
90 IntentComponent,
91 IconComponent,
92 TableFilterPipe,
93 ConfirmComponent,
94 FlashComponent,
95 LoadingComponent
96 ],
prai9d445962018-07-27 13:27:43 +053097 providers: [
98 { provide: FnService, useValue: fs },
99 { provide: IconService, useClass: MockIconService },
prai9d445962018-07-27 13:27:43 +0530100 { 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});