Newer
Older
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AccordionModule } from 'ngx-bootstrap';
import { DatatableSectionComponent } from './datatable.component';
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Dataset } from '../../../metamodel/model';
import { ATTRIBUTE_LIST, DATASET_LIST } from '../../../../settings/test-data';
describe('[Search][Result] Component: DatatableComponent', () => {
@Component({ selector: 'app-img', template: '' })
class ImgStubComponent {
@Input() src: string;
}
@Component({ selector: 'app-thumbnail', template: '' })
class ThumbnailStubComponent {
@Input() src: string;
@Input() attributeName: string;
}
@Component({ selector: 'app-link', template: '' })
class LinkStubComponent {
@Input() href: string;
}
@Component({ selector: 'app-btn', template: '' })
class BtnStubComponent {
@Input() href: string;
}
@Component({ selector: 'app-detail', template: '' })
class DetailStubComponent {
@Input() style: string;
@Input() datasetName: string;
@Input() data: string | number;
}
@Component({ selector: 'app-download', template: '' })
class DownloadStubComponent {
@Input() href: string;
}
@Component({ selector: 'app-json-renderer', template: '' })
class JsonStubComponent {
@Input() attributeName: string;
@Input() json: string;
}
@Component({ selector: 'pagination', template: '' })
class PaginationStubComponent {
@Input() totalItems: number;
@Input() boundaryLinks: boolean;
@Input() rotate: boolean;
@Input() maxSize: number;
}
let component: DatatableSectionComponent;
let fixture: ComponentFixture<DatatableSectionComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
ImgStubComponent,
ThumbnailStubComponent,
LinkStubComponent,
BtnStubComponent,
DetailStubComponent,
DownloadStubComponent,
JsonStubComponent,
PaginationStubComponent
],
imports: [AccordionModule.forRoot(), BrowserAnimationsModule]
});
fixture = TestBed.createComponent(DatatableSectionComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
it('#getOutputList() should return filtered output list', () => {
component.outputList = [2]
component.datasetAttributeList = ATTRIBUTE_LIST;
const outputList = component.getOutputList();
expect(outputList.length).toBe(1);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
});
it('#getDataset() should return dataset object', () => {
component.datasetList = DATASET_LIST;
component.datasetName = 'cat_1';
const dataset: Dataset = component.getDataset();
expect(dataset.name).toBe('cat_1');
expect(dataset.label).toBe('Cat 1');
});
it('#getAttributeId(attributeName) should return id of attributeName', () => {
component.datasetAttributeList = ATTRIBUTE_LIST;
expect(component.getAttributeId('name_one')).toBe(1);
});
it('#getAttributeRenderer(attributeName) should return renderer type of attributeName', () => {
component.datasetAttributeList = ATTRIBUTE_LIST;
expect(component.getAttributeRenderer('name_one')).toBe('btn');
});
it('#getAttributeUriAction(attributeName, datum) should return uri action of attributeName', () => {
component.datasetAttributeList = ATTRIBUTE_LIST;
expect(component.getAttributeUriAction('name_one', 'test')).toBe('test');
expect(component.getAttributeUriAction('name_two', 'test')).toBe('http://test.com/test');
});
it('#toggleSelection(datum) should return add datum to selectedData', () => {
const datum = { label_one: 123456 };
component.datasetAttributeList = ATTRIBUTE_LIST;
component.selectedData = [];
component.addSelectedData.subscribe((event: any) => expect(event).toBe(123456));
component.toggleSelection(datum);
});
it('#toggleSelection(datum) should return remove datum to selectedData', () => {
const datum = { label_one: 123456 };
component.selectedData = [123456];
component.datasetAttributeList = ATTRIBUTE_LIST;
component.deleteSelectedData.subscribe((event: any) => expect(event).toBe(123456));
component.toggleSelection(datum);
});
it('#isSelected(datum) should return true datum is selected', () => {
const datum = { label_one: 123456 };
component.datasetAttributeList = ATTRIBUTE_LIST;
component.selectedData = [123456];
expect(component.isSelected(datum)).toBeTruthy();
});
it('#isSelected(datum) should return false datum is not selected', () => {
const datum = { label_one: 123456 };
component.datasetAttributeList = ATTRIBUTE_LIST;
component.selectedData = [];
expect(component.isSelected(datum)).toBeFalsy();
});
it('#noSelectedData() should return true if no selectedData', () => {
component.selectedData = [];
expect(component.noSelectedData()).toBeTruthy();
});
it('#noSelectedData() should return false if there are selectedData', () => {
component.selectedData = [123456];
expect(component.noSelectedData()).toBeFalsy();
});
it('#emitProcess() should raise executeProcess event and transmit process type', () => {
component.executeProcess.subscribe((event: string) => expect(event).toBe('test'));
component.emitProcess('test');
});
it('#changePage() should change page value and raise getSearchData event', () => {
component.sortedCol = 1;
component.sortedOrder = 'a';
component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([2, 10, 1, 'a']));
component.changePage(2);
});
it('#changeNbItems() should change nbItems value and raise getSearchData event', () => {
component.sortedCol = 1;
component.sortedOrder = 'a';
component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 20, 1, 'a']));
component.changeNbItems(20);
});
it('#ngOnInit() should init sortedCol and sortedOrder values', () => {
component.datasetAttributeList = ATTRIBUTE_LIST;
component.ngOnInit();
expect(component.sortedCol).toEqual(1);
expect(component.sortedOrder).toBe('a');
});
it('#sort() should raise getSearchData event with correct parameters', () => {
component.sortedOrder = 'a';
let subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
component.sort(1);
subscribtion.unsubscribe();
component.sortedCol = 1;
component.sortedOrder = 'a';
subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'd']));
component.sort(1);
subscribtion.unsubscribe();
component.sortedCol = 1;
component.sortedOrder = 'd';
subscribtion = component.getSearchData.subscribe((event: [number, number, number, string]) => expect(event).toEqual([1, 10, 1, 'a']));
component.sort(1);
});