Matteo Scandolo | 44b7d6b | 2016-12-08 13:48:01 -0800 | [diff] [blame^] | 1 | /// <reference path="../../typings/index.d.ts"/> |
| 2 | |
| 3 | import { Observable } from 'rxjs/Rx'; |
| 4 | import {BehaviorSubject} from 'rxjs'; |
| 5 | import { TestBed } from '@angular/core/testing'; |
| 6 | import { XosTableComponent } from './../../src/app/components/tables/table.component'; |
| 7 | import {IXosTableConfig} from '../../src/app/interfaces/xos-components/table.interface'; |
| 8 | import * as $ from 'jquery'; |
| 9 | |
| 10 | describe('Component: XosTableComponent', () => { |
| 11 | let component: XosTableComponent; |
| 12 | let fixture; |
| 13 | let compiled; |
| 14 | let subject: BehaviorSubject<any>; |
| 15 | let observable: Observable<any>; |
| 16 | |
| 17 | beforeEach(() => { |
| 18 | |
| 19 | subject = new BehaviorSubject([]); |
| 20 | observable = subject.asObservable(); |
| 21 | |
| 22 | TestBed.configureTestingModule({ |
| 23 | declarations: [XosTableComponent], |
| 24 | imports: [] |
| 25 | }); |
| 26 | |
| 27 | fixture = TestBed.createComponent(XosTableComponent); |
| 28 | component = fixture.componentInstance; |
| 29 | }); |
| 30 | |
| 31 | it('should exist', () => { |
| 32 | expect(component).toBeDefined(); |
| 33 | }); |
| 34 | |
| 35 | describe('when configured', () => { |
| 36 | beforeEach(() => { |
| 37 | component.config = { |
| 38 | columns: [ |
| 39 | { |
| 40 | label: 'Col 1', |
| 41 | prop: 'foo' |
| 42 | }, |
| 43 | { |
| 44 | label: 'Col 2', |
| 45 | prop: 'bar' |
| 46 | } |
| 47 | ] |
| 48 | }; |
| 49 | |
| 50 | subject.next([ |
| 51 | {foo: 'foo1', bar: 'baz1'}, |
| 52 | {foo: 'foo2', bar: 'baz2'} |
| 53 | ]); |
| 54 | |
| 55 | component.data = observable; |
| 56 | |
| 57 | // manually trigger data bindng |
| 58 | fixture.detectChanges(); |
| 59 | compiled = fixture.nativeElement; |
| 60 | }); |
| 61 | |
| 62 | it('should print labels', () => { |
| 63 | const th1 = $(compiled).find('table tr:first-child th:first-child'); |
| 64 | const th2 = $(compiled).find('table tr:first-child th:last-child'); |
| 65 | expect(th1.text()).toBe('Col 1'); |
| 66 | expect(th2.text()).toBe('Col 2'); |
| 67 | }); |
| 68 | |
| 69 | it('should print content in rows', () => { |
| 70 | const td1_1 = $(compiled).find('table tr:nth-child(2) td:first-child'); |
| 71 | const td1_2 = $(compiled).find('table tr:nth-child(2) td:last-child'); |
| 72 | expect(td1_1.text().trim()).toBe('foo1'); |
| 73 | expect(td1_2.text().trim()).toBe('baz1'); |
| 74 | |
| 75 | const td2_1 = $(compiled).find('table tr:nth-child(3) td:first-child'); |
| 76 | const td2_2 = $(compiled).find('table tr:nth-child(3) td:last-child'); |
| 77 | expect(td2_1.text().trim()).toBe('foo2'); |
| 78 | expect(td2_2.text().trim()).toBe('baz2'); |
| 79 | }); |
| 80 | }); |
| 81 | }); |