Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TableComponent, PaginationSettings } from '.';
describe('TableComponent', () => {
let component: TableComponent;
let fixture: ComponentFixture<TableComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [TableComponent]
// imports: [],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TableComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('should check component initialization: ngOnInit()', () => {
const ngOnInitSpy = spyOn(component, 'ngOnInit').and.callFake(() => {});
component.ngOnInit();
expect(ngOnInitSpy).toHaveBeenCalled();
});
it('should initialize values', () => {
expect(component.tabIdx).toEqual('0');
expect(component.paginationSettings).toBeUndefined();
expect(component.tableSettings).toBeUndefined();
expect(component.columns).toBeUndefined();
expect(component.rows).toEqual([]);
expect(component.loading).toBe(true);
expect(component.imgProperty).toBe(null);
expect(component.linkNotify).toBeTruthy();
expect(component.btnNotify).toBeTruthy();
expect(component.imgNotify).toBeTruthy();
expect(component.extNotify).toBeTruthy();
expect(component.sortNotify).toBeTruthy();
expect(component.rowVal).toBeFalsy(); // @ViewChild('rowVal')
expect(component.pageSizes).toEqual([10, 25, 50, 100]); // kinda over-specific
expect(component.currentPage).toBe(1);
expect(component.selectAll).toBe(false);
expect(component.metaData).toBeUndefined();
expect(component.data).toBeUndefined();
// WARNING!!! Karma locks up if you try to use component.noRows, don't do it!
// expect(component.noRows).toBe(null); //@ViewChild('noRows')
});
it('should ngOnInit() initialize values', () => {
component.ngOnInit();
expect(component.tabIdx).toEqual('0');
expect(component.paginationSettings).toBeUndefined();
expect(component.tableSettings).toBeUndefined();
expect(component.columns).toBeUndefined();
expect(component.rows).toEqual([]);
expect(component.loading).toBe(true);
expect(component.imgProperty).toBe(null);
expect(component.linkNotify).toBeTruthy();
expect(component.btnNotify).toBeTruthy();
expect(component.imgNotify).toBeTruthy();
expect(component.extNotify).toBeTruthy();
expect(component.sortNotify).toBeTruthy();
expect(component.rowVal).toBeFalsy(); // @ViewChild('rowVal')
expect(component.pageSizes).toEqual([10, 25, 50, 100]); // kinda over-specific
expect(component.currentPage).toBe(1);
expect(component.selectAll).toBe(false);
expect(component.metaData).toBeUndefined();
expect(component.data).toBeUndefined();
// WARNING!!! Karma locks up if you try to use component.noRows, don't do it!
// expect(component.noRows).toBe(null); //@ViewChild('noRows')
});
it('should isNum_or_MM_DD_YYYY', () => {
expect(component.isNum_or_MM_DD_YYYY(0)).toBe(true);
expect(component.isNum_or_MM_DD_YYYY(99999)).toBe(true);
expect(component.isNum_or_MM_DD_YYYY(-888888)).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('0')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('99999')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('-888888')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('00/00/0000')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('99/99/9999')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('12/34/5678')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('99/76/5432')).toBe(true);
expect(component.isNum_or_MM_DD_YYYY('9/76/5432')).toBe(false);
expect(component.isNum_or_MM_DD_YYYY('9/6/5432')).toBe(false);
expect(component.isNum_or_MM_DD_YYYY('9/6/54')).toBe(false);
expect(component.isNum_or_MM_DD_YYYY('2018/06/14')).toBe(false);
expect(component.isNum_or_MM_DD_YYYY('2018-06-14')).toBe(false);
expect(component.isNum_or_MM_DD_YYYY('20180614')).toBe(true); // it _is_ a number
});
it('should alignCol true => right', () => {
// fake out so we don't have to test isNum_or_MM_DD_YYYY cases.
const isNum_or_MM_DD_YYYYSpy = spyOn(
component,
'isNum_or_MM_DD_YYYY'
).and.callFake(any => true);
expect(component.alignCol('dummy')).toEqual({ 'text-align': 'right' });
});
it('should alignCol false => left', () => {
// fake out so we don't have to test isNum_or_MM_DD_YYYY cases.
const isNum_or_MM_DD_YYYYSpy = spyOn(
component,
'isNum_or_MM_DD_YYYY'
).and.callFake(any => false);
expect(component.alignCol('dummy')).toEqual({ 'text-align': 'left' });
});
it('should selectItems true and false', () => {
// add some fake rows
let init = false;
let post = !init;
let test: boolean;
component.rows = [
{ n: 1, row_selected: init },
{ n: 2, row_selected: init },
{ n: 3, row_selected: init },
{ n: 4, row_selected: init }
];
post = !init;
component.selectItems(post);
test = true;
component.rows.forEach(val => {
if (val.row_selected !== post) {
test = false;
}
});
expect(test).toEqual(true);
init = false;
component.rows = [
{ n: 1, row_selected: init },
{ n: 2, row_selected: init },
{ n: 3, row_selected: init },
{ n: 4, row_selected: init }
];
post = !init;
component.selectItems(post);
test = true;
component.rows.forEach(val => {
if (val.row_selected !== post) {
test = false;
}
});
expect(test).toEqual(true);
});
it('should sortImg(property) distinguish Sort/Free and Asc/Dsc', () => {
// Only check that it gives different strings based on
// component.paginationSettings.sortColumn === property and
// component.paginationSettings.descending
// we don't judge whether they are "good"
component.paginationSettings = new PaginationSettings();
component.paginationSettings.sortColumn = 'test';
component.paginationSettings.descending = true;
const imgSortDsc = component.sortImg('test');
const imgFreeDsc = component.sortImg('other');
component.paginationSettings.descending = false;
const imgSortAsc = component.sortImg('test');
const imgFreeAsc = component.sortImg('other');
expect(typeof imgSortDsc).toBe('string');
expect(typeof imgFreeDsc).toBe('string');
expect(typeof imgSortAsc).toBe('string');
expect(typeof imgFreeAsc).toBe('string');
// Check all combinations (even identity, for symmetry)
// Sort images only match themselves
expect(imgSortDsc === imgSortDsc).toBe(true);
expect(imgSortDsc === imgSortAsc).toBe(false);
expect(imgSortDsc === imgFreeAsc).toBe(false);
expect(imgSortDsc === imgFreeDsc).toBe(false);
expect(imgSortAsc === imgSortDsc).toBe(false);
expect(imgSortAsc === imgSortAsc).toBe(true);
expect(imgSortAsc === imgFreeDsc).toBe(false);
expect(imgSortAsc === imgFreeAsc).toBe(false);
// Free images only match other Free images (Asc or Dsc)
expect(imgFreeDsc === imgSortDsc).toBe(false);
expect(imgFreeDsc === imgSortAsc).toBe(false);
expect(imgFreeDsc === imgFreeDsc).toBe(true);
expect(imgFreeDsc === imgFreeAsc).toBe(true);
expect(imgFreeAsc === imgSortDsc).toBe(false);
expect(imgFreeAsc === imgSortAsc).toBe(false);
expect(imgFreeAsc === imgFreeDsc).toBe(true);
expect(imgFreeAsc === imgFreeAsc).toBe(true);
});
});