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'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 20 | import { LionService } from '../../util/lion.service'; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 21 | |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 22 | import { ConsoleLoggerService } from '../../consolelogger.service'; |
| 23 | import { LogService } from '../../log.service'; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 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': { |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 35 | test: 'test1', |
| 36 | dlg_confirm_action: 'Confirm' |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 37 | } |
| 38 | }; |
| 39 | const mockLion = (key) => { |
| 40 | return bundleObj[key] || '%' + key + '%'; |
| 41 | }; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 42 | |
| 43 | beforeEach(async(() => { |
| 44 | log = new ConsoleLoggerService(); |
| 45 | TestBed.configureTestingModule({ |
| 46 | imports: [ BrowserAnimationsModule ], |
| 47 | declarations: [ ConfirmComponent ], |
| 48 | providers: [ |
| 49 | { provide: LogService, useValue: log }, |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 50 | { |
| 51 | provide: LionService, useFactory: (() => { |
| 52 | return { |
| 53 | bundle: ((bundleId) => mockLion), |
| 54 | ubercache: new Array(), |
| 55 | loadCbs: new Map<string, () => void>([]) |
| 56 | }; |
| 57 | }) |
| 58 | }, |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 59 | ] |
| 60 | }); |
| 61 | })); |
| 62 | |
| 63 | beforeEach(() => { |
| 64 | fixture = TestBed.createComponent(ConfirmComponent); |
| 65 | component = fixture.debugElement.componentInstance; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 66 | component.title = 'Confirm'; |
| 67 | component.message = 'A message'; |
| 68 | component.warning = 'A warning'; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 69 | fixture.detectChanges(); |
| 70 | }); |
| 71 | |
| 72 | it('should create', () => { |
| 73 | expect(component).toBeTruthy(); |
| 74 | }); |
| 75 | |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 76 | 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 Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 80 | expect(div.textContent).toEqual(' Confirm '); |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 81 | }); |
| 82 | |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 83 | 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 | }); |