blob: 9692e3a1814daea9a2b9882311effc0916313cb6 [file] [log] [blame]
Sean Condon2aa86092018-07-16 09:04:05 +01001/*
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 { BrowserAnimationsModule } from '@angular/platform-browser/animations';
18import { DebugElement } from '@angular/core';
19import { By } from '@angular/platform-browser';
Sean Condon5ca00262018-09-06 17:55:25 +010020import { LionService } from '../../util/lion.service';
Sean Condon2aa86092018-07-16 09:04:05 +010021
Sean Condon5ca00262018-09-06 17:55:25 +010022import { ConsoleLoggerService } from '../../consolelogger.service';
23import { LogService } from '../../log.service';
Sean Condon2aa86092018-07-16 09:04:05 +010024import { ConfirmComponent } from './confirm.component';
25
26/**
27 * ONOS GUI -- Layer -- Confirm Component - Unit Tests
28 */
29describe('ConfirmComponent', () => {
30 let log: LogService;
31 let component: ConfirmComponent;
32 let fixture: ComponentFixture<ConfirmComponent>;
prai9d445962018-07-27 13:27:43 +053033 const bundleObj = {
34 'core.view.App': {
Sean Condon87b78502018-09-17 20:53:24 +010035 test: 'test1',
36 dlg_confirm_action: 'Confirm'
prai9d445962018-07-27 13:27:43 +053037 }
38 };
39 const mockLion = (key) => {
40 return bundleObj[key] || '%' + key + '%';
41 };
Sean Condon2aa86092018-07-16 09:04:05 +010042
43 beforeEach(async(() => {
44 log = new ConsoleLoggerService();
45 TestBed.configureTestingModule({
46 imports: [ BrowserAnimationsModule ],
47 declarations: [ ConfirmComponent ],
48 providers: [
49 { provide: LogService, useValue: log },
prai9d445962018-07-27 13:27:43 +053050 {
51 provide: LionService, useFactory: (() => {
52 return {
53 bundle: ((bundleId) => mockLion),
54 ubercache: new Array(),
55 loadCbs: new Map<string, () => void>([])
56 };
57 })
58 },
Sean Condon2aa86092018-07-16 09:04:05 +010059 ]
60 });
61 }));
62
63 beforeEach(() => {
64 fixture = TestBed.createComponent(ConfirmComponent);
65 component = fixture.debugElement.componentInstance;
Sean Condon87b78502018-09-17 20:53:24 +010066 component.title = 'Confirm';
67 component.message = 'A message';
68 component.warning = 'A warning';
Sean Condon2aa86092018-07-16 09:04:05 +010069 fixture.detectChanges();
70 });
71
72 it('should create', () => {
73 expect(component).toBeTruthy();
74 });
75
prai9d445962018-07-27 13:27:43 +053076 it('should have a h3 inside a div#app-dialog', () => {
77 const appDe: DebugElement = fixture.debugElement;
78 const divDe = appDe.query(By.css('div#app-dialog h3'));
79 const div: HTMLElement = divDe.nativeElement;
Sean Condon87b78502018-09-17 20:53:24 +010080 expect(div.textContent).toEqual(' Confirm ');
prai9d445962018-07-27 13:27:43 +053081 });
82
Sean Condon2aa86092018-07-16 09:04:05 +010083 it('should have a div.dialog-button inside a div#app-dialog', () => {
84 const appDe: DebugElement = fixture.debugElement;
85 const divDe = appDe.query(By.css('div#app-dialog div.dialog-button'));
86 const div: HTMLElement = divDe.nativeElement;
87 // It selects the first one
88 expect(div.textContent).toEqual('OK');
89 });
90});