Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 18 | import { DebugElement } from '@angular/core'; |
| 19 | import { By } from '@angular/platform-browser'; |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame^] | 20 | import { LionService } from '../../../fw/util/lion.service'; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 21 | |
| 22 | import { ConsoleLoggerService } from '../../../consolelogger.service'; |
| 23 | import { LogService } from '../../../log.service'; |
| 24 | import { ConfirmComponent } from './confirm.component'; |
| 25 | |
| 26 | /** |
| 27 | * ONOS GUI -- Layer -- Confirm Component - Unit Tests |
| 28 | */ |
| 29 | describe('ConfirmComponent', () => { |
| 30 | let log: LogService; |
| 31 | let component: ConfirmComponent; |
| 32 | let fixture: ComponentFixture<ConfirmComponent>; |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame^] | 33 | const bundleObj = { |
| 34 | 'core.view.App': { |
| 35 | test: 'test1' |
| 36 | } |
| 37 | }; |
| 38 | const mockLion = (key) => { |
| 39 | return bundleObj[key] || '%' + key + '%'; |
| 40 | }; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 41 | |
| 42 | beforeEach(async(() => { |
| 43 | log = new ConsoleLoggerService(); |
| 44 | TestBed.configureTestingModule({ |
| 45 | imports: [ BrowserAnimationsModule ], |
| 46 | declarations: [ ConfirmComponent ], |
| 47 | providers: [ |
| 48 | { provide: LogService, useValue: log }, |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame^] | 49 | { |
| 50 | provide: LionService, useFactory: (() => { |
| 51 | return { |
| 52 | bundle: ((bundleId) => mockLion), |
| 53 | ubercache: new Array(), |
| 54 | loadCbs: new Map<string, () => void>([]) |
| 55 | }; |
| 56 | }) |
| 57 | }, |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 58 | ] |
| 59 | }); |
| 60 | })); |
| 61 | |
| 62 | beforeEach(() => { |
| 63 | fixture = TestBed.createComponent(ConfirmComponent); |
| 64 | component = fixture.debugElement.componentInstance; |
| 65 | fixture.detectChanges(); |
| 66 | }); |
| 67 | |
| 68 | it('should create', () => { |
| 69 | expect(component).toBeTruthy(); |
| 70 | }); |
| 71 | |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame^] | 72 | it('should have a h3 inside a div#app-dialog', () => { |
| 73 | const appDe: DebugElement = fixture.debugElement; |
| 74 | const divDe = appDe.query(By.css('div#app-dialog h3')); |
| 75 | const div: HTMLElement = divDe.nativeElement; |
| 76 | expect(div.textContent).toEqual(' %dlg_confirm_action% '); |
| 77 | }); |
| 78 | |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 79 | it('should have a div.dialog-button inside a div#app-dialog', () => { |
| 80 | const appDe: DebugElement = fixture.debugElement; |
| 81 | const divDe = appDe.query(By.css('div#app-dialog div.dialog-button')); |
| 82 | const div: HTMLElement = divDe.nativeElement; |
| 83 | // It selects the first one |
| 84 | expect(div.textContent).toEqual('OK'); |
| 85 | }); |
| 86 | }); |