1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
3 import { RouterTestingModule } from '@angular/router/testing';
5 import { NgxDatatableModule } from '@swimlane/ngx-datatable';
7 import { ComponentsModule } from '../../components/components.module';
8 import { TableComponent } from '../table/table.component';
9 import { TableKeyValueComponent } from './table-key-value.component';
11 describe('TableKeyValueComponent', () => {
12 let component: TableKeyValueComponent;
13 let fixture: ComponentFixture<TableKeyValueComponent>;
15 beforeEach(async(() => {
16 TestBed.configureTestingModule({
17 declarations: [ TableComponent, TableKeyValueComponent ],
18 imports: [ FormsModule, NgxDatatableModule, ComponentsModule, RouterTestingModule ]
24 fixture = TestBed.createComponent(TableKeyValueComponent);
25 component = fixture.componentInstance;
28 it('should create', () => {
29 expect(component).toBeTruthy();
32 it('should make key value object pairs out of arrays with length two', () => {
38 expect(component.tableData.length).toBe(2);
39 expect(component.tableData[0].key).toBe('someKey');
40 expect(component.tableData[1].value).toBe('something');
43 it('should transform arrays', () => {
45 ['someKey', [1, 2, 3]],
49 expect(component.tableData.length).toBe(2);
50 expect(component.tableData[0].key).toBe('someKey');
51 expect(component.tableData[0].value).toBe('1, 2, 3');
52 expect(component.tableData[1].value).toBe('something');
55 it('should remove pure object values', () => {
58 ['will be removed', { a: 3, b: 4, c: 5}]
61 expect(component.tableData.length).toBe(1);
62 expect(component.tableData[0].value).toBe('something');
65 it('should make key value object pairs out of an object', () => {
71 expect(component.tableData.length).toBe(2);
72 expect(component.tableData[0].value).toBe('something');
73 expect(component.tableData[1].key).toBe('someKey');
76 it('should make do nothing if data is correct', () => {
88 expect(component.tableData.length).toBe(2);
89 expect(component.tableData[0].value).toBe('something');
90 expect(component.tableData[1].key).toBe('someKey');
93 it('should throw error if miss match', () => {
95 expect(() => component.ngOnInit()).toThrowError('Wrong data format');
96 component.data = [['someKey', 0, 3]];
97 expect(() => component.ngOnInit()).toThrowError('Wrong array format');