swimlane/ngx-datatable

View on GitHub
projects/swimlane/ngx-datatable/src/lib/components/body/body-cell.component.spec.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { TestBed, ComponentFixture, waitForAsync } from '@angular/core/testing';

import { numericIndexGetter } from '../../utils/column-prop-getters';
import { setColumnDefaults } from '../../utils/column-helper';
import { TableColumn } from '../../types/table-column.type';
import { DataTableBodyCellComponent } from './body-cell.component';

describe('DataTableBodyCellComponent', () => {
  let fixture: ComponentFixture<DataTableBodyCellComponent>;
  let component: DataTableBodyCellComponent;
  let element;

  // provide our implementations or mocks to the dependency injector
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [DataTableBodyCellComponent]
    });
  });

  beforeEach(
    waitForAsync(() => {
      TestBed.compileComponents().then(() => {
        fixture = TestBed.createComponent(DataTableBodyCellComponent);
        component = fixture.componentInstance;
        element = fixture.nativeElement;
      });
    })
  );

  describe('fixture', () => {
    it('should have a component instance', () => {
      expect(component).toBeTruthy();
    });
  });

  describe('prop tests', () => {
    // verify there wasn't a mistake where the falsey 0 value
    // resulted in a code path for missing column prop
    it('should get value from zero-index prop', () => {
      component.row = ['Hello'];
      const columns: TableColumn[] = [{ name: 'First Column', prop: 0 }];
      // users should never set columns on DataTableBodyCellComponent directly
      // setColumnDefaults will be run on columns before they are set on BodyCellComponent
      setColumnDefaults(columns);
      expect(columns[0].$$valueGetter).toBe(numericIndexGetter);

      component.column = columns[0];
      expect(component.value).toEqual('Hello');
    });
  });
});