blob: 27572839bc62e7295de714d32659e8a5d0c90a93 [file] [log] [blame]
Bhavesh Kumard0b8bae2018-07-31 16:56: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 { DebugElement } from '@angular/core';
19import { By } from '@angular/platform-browser';
Sean Condon5ca00262018-09-06 17:55:25 +010020import {
21 FnService,
22 IconService,
23 IconComponent,
Sean Condon5ca00262018-09-06 17:55:25 +010024 LogService,
Sean Condon95fb5742019-04-02 12:16:55 +010025 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010026} from 'gui2-fw-lib';
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053027import { of } from 'rxjs';
28import { } from 'jasmine';
29import { RouterTestingModule } from '@angular/router/testing';
30import { PartitionComponent } from './partition.component';
Sean Condon95fb5742019-04-02 12:16:55 +010031import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053032
33class MockActivatedRoute extends ActivatedRoute {
34 constructor(params: Params) {
35 super();
36 this.queryParams = of(params);
37 }
38}
39
40class MockIconService {
41 loadIconDef() { }
42}
43
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053044class MockWebSocketService {
45 createWebSocket() { }
46 isConnected() { return false; }
47 unbindHandlers() { }
48 bindHandlers() { }
49}
50
51/**
52 * ONOS GUI -- Partition View Module - Unit Tests
53 */
54describe('PartitionComponent', () => {
55 let fs: FnService;
56 let ar: MockActivatedRoute;
57 let windowMock: Window;
58 let logServiceSpy: jasmine.SpyObj<LogService>;
59 let component: PartitionComponent;
60 let fixture: ComponentFixture<PartitionComponent>;
61
62 beforeEach(async(() => {
63 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
64 ar = new MockActivatedRoute({ 'debug': 'txrx' });
65
66 windowMock = <any>{
67 location: <any>{
68 partitionname: 'foo',
69 partition: 'foo',
70 port: '80',
71 protocol: 'http',
72 search: { debug: 'true' },
73 href: 'ws://foo:123/onos/ui/websock/path',
74 absUrl: 'ws://foo:123/onos/ui/websock/path'
75 }
76 };
77 fs = new FnService(ar, logSpy, windowMock);
78
79 TestBed.configureTestingModule({
Sean Condon95fb5742019-04-02 12:16:55 +010080 imports: [BrowserAnimationsModule, RouterTestingModule],
81 declarations: [
82 PartitionComponent,
83 IconComponent,
84 LoadingComponent
85 ],
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053086 providers: [
87 { provide: FnService, useValue: fs },
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053088 { provide: IconService, useClass: MockIconService },
89 { provide: LogService, useValue: logSpy },
90 { provide: WebSocketService, useClass: MockWebSocketService },
91 ]
92 })
93 .compileComponents();
94 logServiceSpy = TestBed.get(LogService);
95 }));
96
97 beforeEach(() => {
98 fixture = TestBed.createComponent(PartitionComponent);
99 component = fixture.componentInstance;
100 fixture.detectChanges();
101 });
102
103 it('should create', () => {
104 expect(component).toBeTruthy();
105 });
106
107 it('should have a div.tabular-header inside a div#ov-partition', () => {
108 const metDe: DebugElement = fixture.debugElement;
109 const divDe = metDe.query(By.css('div#ov-partition div.tabular-header'));
110 expect(divDe).toBeTruthy();
111 });
112
113 it('should have a h2 inside the div.tabular-header', () => {
114 const metDe: DebugElement = fixture.debugElement;
115 const divDe = metDe.query(By.css('div#ov-partition div.tabular-header h2'));
116 const div: HTMLElement = divDe.nativeElement;
117 expect(div.textContent).toEqual('Partitions (0 total)');
118 });
119
120 it('should have a refresh button inside the div.tabular-header', () => {
121 const metDe: DebugElement = fixture.debugElement;
122 const divDe = metDe.query(By.css('div#ov-partition div.tabular-header div.ctrl-btns div.refresh'));
123 expect(divDe).toBeTruthy();
124 });
125
126
127 it('should have a div.summary-list inside a div#ov-partition', () => {
128 const partDe: DebugElement = fixture.debugElement;
129 const divDe = partDe.query(By.css('div#ov-partition div.summary-list'));
130 expect(divDe).toBeTruthy();
131 });
132
133 it('should have a div.table-header inside a div.summary-list inside a div#ov-partition', () => {
134 const partDe: DebugElement = fixture.debugElement;
135 const divDe = partDe.query(By.css('div#ov-partition div.summary-list div.table-header'));
136 expect(divDe).toBeTruthy();
137 });
138
139 it('should have a div.table-body inside a div.summary-list inside a div#ov-partition', () => {
140 const partDe: DebugElement = fixture.debugElement;
141 const divDe = partDe.query(By.css('div#ov-partition div.summary-list div.table-body'));
142 expect(divDe).toBeTruthy();
143 });
144});