|
| 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 { RowClickEventComponent } from './row-click-event.component'; |
| 13 | + |
| 14 | + |
| 15 | +let fixture: ComponentFixture<RowClickEventComponent>, component: RowClickEventComponent = null; |
| 16 | + |
| 17 | +describe('RowClickEventComponent', () => { |
| 18 | + beforeEach(() => { |
| 19 | + fixture = TestBed.configureTestingModule({ |
| 20 | + declarations: [ |
| 21 | + BaseDemoComponent, |
| 22 | + RowClickEventComponent, |
| 23 | + DataTableDirective |
| 24 | + ], |
| 25 | + imports: [ |
| 26 | + AppRoutingModule, |
| 27 | + RouterTestingModule, |
| 28 | + DataTablesModule.forRoot(), |
| 29 | + HttpClientModule, |
| 30 | + MarkdownModule.forRoot( |
| 31 | + { |
| 32 | + sanitize: SecurityContext.NONE |
| 33 | + } |
| 34 | + ), |
| 35 | + FormsModule |
| 36 | + ], |
| 37 | + schemas: [NO_ERRORS_SCHEMA] |
| 38 | + }).createComponent(RowClickEventComponent); |
| 39 | + |
| 40 | + component = fixture.componentInstance; |
| 41 | + |
| 42 | + fixture.detectChanges(); // initial binding |
| 43 | + }); |
| 44 | + |
| 45 | + it('should create the app', waitForAsync(() => { |
| 46 | + const app = fixture.debugElement.componentInstance; |
| 47 | + expect(app).toBeTruthy(); |
| 48 | + })); |
| 49 | + |
| 50 | + it('should have title "Row click event"', waitForAsync(() => { |
| 51 | + const app = fixture.debugElement.componentInstance as RowClickEventComponent; |
| 52 | + expect(app.pageTitle).toBe('Row click event'); |
| 53 | + })); |
| 54 | + |
| 55 | + it('should display row data on table cell click', async () => { |
| 56 | + const app = fixture.debugElement.componentInstance as RowClickEventComponent; |
| 57 | + await fixture.whenStable(); |
| 58 | + |
| 59 | + // Test |
| 60 | + const tr1 = fixture.nativeElement.querySelector('tbody tr:nth-child(1)'); |
| 61 | + $('td:first-child', tr1).trigger('click'); |
| 62 | + expect(app.message).toBe('3 - Cartman'); |
| 63 | + |
| 64 | + // Test 2 |
| 65 | + const tr4 = fixture.nativeElement.querySelector('tbody tr:nth-child(4)'); |
| 66 | + $('td:first-child', tr4).trigger('click'); |
| 67 | + expect(app.message).toBe('22 - Luke'); |
| 68 | + |
| 69 | + // Test 3 |
| 70 | + const tr7 = fixture.nativeElement.querySelector('tbody tr:nth-child(7)'); |
| 71 | + $('td:first-child', tr7).trigger('click'); |
| 72 | + expect(app.message).toBe('32 - Batman'); |
| 73 | + }); |
| 74 | + |
| 75 | +}); |
0 commit comments