1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
4 import { NgxDatatableModule, TableColumn } from '@swimlane/ngx-datatable';
6 import { TableComponent } from './table.component';
8 describe('TableComponent', () => {
9 let component: TableComponent;
10 let fixture: ComponentFixture<TableComponent>;
11 const columns: TableColumn[] = [];
12 const createFakeData = (n) => {
14 for (let i = 0; i < n; i++) {
26 TestBed.configureTestingModule({
27 declarations: [TableComponent],
28 imports: [NgxDatatableModule, FormsModule]
29 }).compileComponents();
34 fixture = TestBed.createComponent(TableComponent);
35 component = fixture.componentInstance;
39 component.data = createFakeData(100);
48 it('should create', () => {
49 expect(component).toBeTruthy();
52 it('should have rows', () => {
53 expect(component.data.length).toBe(100);
54 expect(component.rows.length).toBe(component.data.length);
57 it('should have an int in setLimit parsing a string', () => {
58 expect(component.limit).toBe(10);
59 expect(component.limit).toEqual(jasmine.any(Number));
61 const e = {target: {value: '1'}};
62 component.setLimit(e);
63 expect(component.limit).toBe(1);
64 expect(component.limit).toEqual(jasmine.any(Number));
65 e.target.value = '-20';
66 component.setLimit(e);
67 expect(component.limit).toBe(1);
70 it('should search for 13', () => {
71 component.search = '13';
72 expect(component.rows.length).toBe(100);
73 component.updateFilter(true);
74 expect(component.rows[0].a).toBe(13);
75 expect(component.rows[1].b).toBe(1369);
76 expect(component.rows[2].b).toBe(3136);
77 expect(component.rows.length).toBe(3);
80 it('should restore full table after search', () => {
81 component.search = '13';
82 expect(component.rows.length).toBe(100);
83 component.updateFilter(true);
84 expect(component.rows.length).toBe(3);
85 component.updateFilter();
86 expect(component.rows.length).toBe(100);