|
| 1 | +import {TestBed, async} from '@angular/core/testing'; |
| 2 | +import {ComponentFixture} from '@angular/core/testing'; |
| 3 | +import {DebugElement} from '@angular/core'; |
| 4 | +import {By} from '@angular/platform-browser'; |
| 5 | +import {AppComponent} from './app.component'; |
| 6 | +import {AuModalOpenOnClickDirective} from "./au-modal/au-modal-open-on-click.directive"; |
| 7 | +import {AuModalComponent} from "./au-modal/au-modal.component"; |
| 8 | +import {AuInputModule} from "au-input"; |
| 9 | +import {AuTabPanelModule} from "au-tab-panel"; |
| 10 | +import {AuModalModule} from "./au-modal/au-modal.module"; |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +describe('AppComponent', () => { |
| 15 | + |
| 16 | + let component: AppComponent, |
| 17 | + fixture: ComponentFixture<AppComponent>, |
| 18 | + el: DebugElement, |
| 19 | + modal: DebugElement; |
| 20 | + |
| 21 | + |
| 22 | + beforeEach(async(() => { |
| 23 | + TestBed.configureTestingModule({ |
| 24 | + declarations: [ |
| 25 | + AppComponent |
| 26 | + ], |
| 27 | + imports: [ |
| 28 | + AuInputModule, |
| 29 | + AuTabPanelModule, |
| 30 | + AuModalModule.forRoot() |
| 31 | + ] |
| 32 | + |
| 33 | + }).compileComponents(); |
| 34 | + })); |
| 35 | + |
| 36 | + beforeEach(() => { |
| 37 | + |
| 38 | + fixture = TestBed.createComponent(AppComponent); |
| 39 | + component = fixture.debugElement.componentInstance; |
| 40 | + el = fixture.debugElement; |
| 41 | + modal = el.query(By.css('#testModal')); |
| 42 | + |
| 43 | + fixture.detectChanges(); |
| 44 | + |
| 45 | + }); |
| 46 | + |
| 47 | + |
| 48 | + it('should create the test application', async(() => { |
| 49 | + |
| 50 | + expect(component).toBeTruthy(); |
| 51 | + |
| 52 | + })); |
| 53 | + |
| 54 | + |
| 55 | + it('should not add the modal to the page, if the modal is closed', async(() => { |
| 56 | + |
| 57 | + expect(modal).toBeFalsy(); |
| 58 | + |
| 59 | + })); |
| 60 | + |
| 61 | + |
| 62 | + it('should open the modal when the test button is clicked', async(() => { |
| 63 | + |
| 64 | + fixture.nativeElement.querySelector("#testButton").click(); |
| 65 | + |
| 66 | + fixture.detectChanges(); |
| 67 | + |
| 68 | + const openedModal = fixture.nativeElement.querySelector("#testModal"); |
| 69 | + |
| 70 | + |
| 71 | + expect(openedModal).toBeTruthy(); |
| 72 | + |
| 73 | + })); |
| 74 | + |
| 75 | + |
| 76 | +}); |
0 commit comments