|
| 1 | +/* tslint:disable:no-unused-variable */ |
| 2 | + |
| 3 | +import { RouterTestingModule } from '@angular/router/testing'; |
| 4 | +import { HttpClientModule } from '@angular/common/http'; |
| 5 | +import { NO_ERRORS_SCHEMA, SecurityContext } from '@angular/core'; |
| 6 | +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; |
| 7 | +import { DataTableDirective, DataTablesModule } from 'angular-datatables'; |
| 8 | +import { MarkdownModule } from 'ngx-markdown'; |
| 9 | +import { BaseDemoComponent } from '../base-demo/base-demo.component'; |
| 10 | +import { AppRoutingModule } from '../app.routing'; |
| 11 | +import { FormsModule } from '@angular/forms'; |
| 12 | +import { UpperCasePipe } from '@angular/common'; |
| 13 | +import { By } from '@angular/platform-browser'; |
| 14 | +import { UsingNgTemplateRefComponent } from './using-ng-template-ref.component'; |
| 15 | +import { DemoNgComponent } from './demo-ng-template-ref.component'; |
| 16 | + |
| 17 | + |
| 18 | +let fixture: ComponentFixture<UsingNgTemplateRefComponent>, component: UsingNgTemplateRefComponent = null; |
| 19 | + |
| 20 | +describe('UsingNgTemplateRefComponent', () => { |
| 21 | + beforeEach(() => { |
| 22 | + fixture = TestBed.configureTestingModule({ |
| 23 | + declarations: [ |
| 24 | + BaseDemoComponent, |
| 25 | + UsingNgTemplateRefComponent, |
| 26 | + DemoNgComponent, |
| 27 | + DataTableDirective |
| 28 | + ], |
| 29 | + imports: [ |
| 30 | + AppRoutingModule, |
| 31 | + RouterTestingModule, |
| 32 | + DataTablesModule.forRoot(), |
| 33 | + HttpClientModule, |
| 34 | + MarkdownModule.forRoot( |
| 35 | + { |
| 36 | + sanitize: SecurityContext.NONE |
| 37 | + } |
| 38 | + ), |
| 39 | + FormsModule |
| 40 | + ], |
| 41 | + schemas: [NO_ERRORS_SCHEMA], |
| 42 | + providers: [ |
| 43 | + UpperCasePipe |
| 44 | + ] |
| 45 | + }).createComponent(UsingNgTemplateRefComponent); |
| 46 | + |
| 47 | + component = fixture.componentInstance; |
| 48 | + |
| 49 | + fixture.detectChanges(); // initial binding |
| 50 | + }); |
| 51 | + |
| 52 | + it('should create the app', waitForAsync(() => { |
| 53 | + const app = fixture.debugElement.componentInstance; |
| 54 | + expect(app).toBeTruthy(); |
| 55 | + })); |
| 56 | + |
| 57 | + it('should have title "Using Angular TemplateRef"', waitForAsync(() => { |
| 58 | + const app = fixture.debugElement.componentInstance as UsingNgTemplateRefComponent; |
| 59 | + expect(app.pageTitle).toBe('Using Angular TemplateRef'); |
| 60 | + })); |
| 61 | + |
| 62 | + it('should have firstName, lastName columns have text in uppercase', async () => { |
| 63 | + const app = fixture.debugElement.componentInstance as UsingNgTemplateRefComponent; |
| 64 | + await fixture.whenStable(); |
| 65 | + |
| 66 | + const query = fixture.debugElement.query(By.directive(DataTableDirective)); |
| 67 | + const dir = query.injector.get(DataTableDirective); |
| 68 | + expect(dir).toBeTruthy(); |
| 69 | + |
| 70 | + expect(app.message).toBe(''); |
| 71 | + |
| 72 | + const row: HTMLTableRowElement = fixture.nativeElement.querySelector('tbody tr:first-child'); |
| 73 | + const button: HTMLButtonElement = row.querySelector('button.btn-sm'); |
| 74 | + button.click(); |
| 75 | + |
| 76 | + expect(app.message).toBe(`Event 'action1' with data '{}`); |
| 77 | + |
| 78 | + }); |
| 79 | + |
| 80 | +}); |
0 commit comments