Newer
Older
1
2
3
4
5
6
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AccordionModule } from 'ngx-bootstrap';
import { DatatableComponent } from './datatable.component';
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: DatatableComponent;
let fixture: ComponentFixture<DatatableComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
DatatableComponent,
ImgStubComponent,
ThumbnailStubComponent,
LinkStubComponent,
BtnStubComponent,
DetailStubComponent,
DownloadStubComponent,
JsonStubComponent,
PaginationStubComponent
],
imports: [AccordionModule.forRoot(), BrowserAnimationsModule]
});
fixture = TestBed.createComponent(DatatableComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
82
83
84
85
86
87
88
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('#initDatatable() should raise initSearchMeta and getSearchData events', () => {
component.getSearchData.subscribe((event: number) => expect(event).toBe(1));
component.initDatatable();
});
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();
});
});