-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathdrop-down-list.spec.ts
1564 lines (1535 loc) · 67.2 KB
/
drop-down-list.spec.ts
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
81
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Dropdownlist spec document
*/
import { EmitType, Browser, createElement, isNullOrUndefined, setCulture, L10n, extend } from '@syncfusion/ej2-base';
import { DropDownBase, FilteringEventArgs, dropDownBaseClasses } from '../../src/drop-down-base/drop-down-base';
import { DropDownList } from '../../src/drop-down-list/drop-down-list';
import { DataManager, ODataV4Adaptor, ODataAdaptor, Query, WebApiAdaptor, Predicate } from '@syncfusion/ej2-data';
import { isCollide } from '@syncfusion/ej2-popups';
import '../../node_modules/es6-promise/dist/es6-promise';
let templateDataSource: { [key: string]: Object }[] = [
{ Name: 'Andrew Fuller', Eimg: '7', Designation: 'Team Lead', Country: 'England' },
{ Name: 'Anne Dodsworth', Eimg: '1', Designation: 'Developer', Country: 'USA' },
{ Name: 'Janet Leverling', Eimg: '3', Designation: 'HR', Country: 'USA' },
{ Name: 'Laura Callahan', Eimg: '2', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Margaret Peacock', Eimg: '6', Designation: 'Developer', Country: 'USA' },
{ Name: 'Michael Suyama', Eimg: '9', Designation: 'Team Lead', Country: 'USA' },
{ Name: 'Nancy Davolio', Eimg: '4', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Robert King', Eimg: '8', Designation: 'Developer ', Country: 'England' },
{ Name: 'Steven Buchanan', Eimg: '10', Designation: 'CEO', Country: 'England' }
];
let data: JSON[] = ([
{ OrderID: 10248, CustomerID: 'VINET', EmployeeID: 5, Freight: 32.38 },
{ OrderID: 10249, CustomerID: 'AANAR', EmployeeID: 2, Freight: 11.61 },
{ OrderID: 10250, CustomerID: 'VICTE', EmployeeID: 7, Freight: 65.83 },
{ OrderID: 10251, CustomerID: 'TOMSP', EmployeeID: 7, Freight: 70.63 },
{ OrderID: 10252, CustomerID: 'SUPRD', EmployeeID: 6, Freight: 45.45 }
] as Object) as JSON[];
type MockAjaxReturn = { promise: Promise<Object>, request: JasmineAjaxRequest };
type ResponseType = { result: Object[], count: number | string };
let mockAjax: Function = (d: { data: { [o: string]: Object | Object[] } | Object[], dm?: DataManager }, query: Query | Function, response?: Object):
MockAjaxReturn => {
jasmine.Ajax.install();
let dataManager = d.dm || new DataManager({
url: 'https://services.syncfusion.com/js/production/api/Employees',
adaptor: new WebApiAdaptor,
crossDomain: true
});
let prom: Promise<Object> = dataManager.executeQuery(query);
let request: JasmineAjaxRequest;
let defaults: Object = {
'status': 200,
'contentType': 'application/json',
'responseText': JSON.stringify(d.data)
};
let responses: Object = {};
request = jasmine.Ajax.requests.mostRecent();
extend(responses, defaults, response);
request.respondWith(responses);
return {
promise: prom,
request: request
}
};
describe('DropDownList', () => {
let css: string = ".e-spinner-pane::after { content: 'Material'; display: none;} ";
let style: HTMLStyleElement = document.createElement('style'); style.type = 'text/css';
let styleNode: Node = style.appendChild(document.createTextNode(css));
document.getElementsByTagName('head')[0].appendChild(style);
// template supports
describe('Template support Issue EJ2-9023', () => {
let element: HTMLInputElement;
let listObj: DropDownList;
let popup: HTMLElement;
let liEle: HTMLElement;
let divNode: HTMLDivElement;
let textContent: string;
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: templateDataSource,
fields: { text: 'Name', value: 'Eimg' },
popupHeight: "200px",
allowFiltering: true,
headerTemplate: '<div class="header"> <span>Photo</span> <span class="info">Employee Info</span></div>',
// set the template content for list items
itemTemplate: '<div><img class="empImage"' +
' src="http://npmci.syncfusion.com/development/demos/src/combobox/Employees/${Eimg}.png"' +
'alt="employee"/>' +
'<div class="ename"> ${Name} </div><div class="job"> ${Designation} </div></div>',
});
listObj.appendTo(element);
});
it("Items values", function () {
listObj.open = function (args) {
popup = document.getElementById('dropdownlist_popup');
liEle = popup.querySelector('li');
divNode = liEle.querySelectorAll("div.ename")[0] as HTMLDivElement;
textContent = divNode.innerText;
expect(textContent).toEqual('Andrew Fuller');
listObj.hidePopup();
// listObj.open = null;
};
listObj.close = function (args) {
listObj.close = null;
};
listObj.showPopup();
});
it("Items Recheck values", function () {
listObj.open = function (args) {
popup = document.getElementById('dropdownlist_popup');
liEle = popup.querySelector('li');
divNode = liEle.querySelectorAll("div.ename")[0] as HTMLDivElement;
textContent = divNode.innerText;
expect(textContent).toEqual('Andrew Fuller');
listObj.hidePopup();
listObj.open = null;
};
listObj.close = function (args) {
listObj.close = null;
};
listObj.showPopup();
});
afterAll(() => {
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
});
describe('EJ2-10838 - Change event trigger while component initial render with empty and then set the data at any action', () => {
let ddlObj: any;
let isfocused: boolean = false;
let ddlEle: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'ddl', attrs: { autofocus: 'autofocus' } });
let empList: { [key: string]: Object }[] = [
{ id: 'level1', sports: 'American Football' }, { id: 'level2', sports: 'Badminton' },
{ id: 'level3', sports: 'Basketball' }, { id: 'level4', sports: 'Cricket' },
{ id: 'level5', sports: 'Football' }, { id: 'level6', sports: 'Golf' },
{ id: 'level7', sports: 'Hockey' }, { id: 'level8', sports: 'Rugby' },
{ id: 'level9', sports: 'Snooker' }, { id: 'level10', sports: 'Tennis' },
];
beforeAll(() => {
document.body.appendChild(ddlEle);
ddlObj = new DropDownList({
dataSource: empList,
fields: { text: 'sports', value: 'id' },
focus: function () {
isfocused = true;
}
});
ddlObj.appendTo(ddlEle);
});
afterAll(() => {
ddlObj.destroy();
ddlEle.remove();
});
it('EJ2-10873 - check whether the autofocus is applied', () => {
expect(isfocused).toBe(true);
});
it('EJ2-10838 - check whether the previous and value are same during render', () => {
expect(ddlObj.previousValue === ddlObj.value).toBe(true)
});
});
describe('EJ2-11038 - Value set through ngModel is not maintained after changing dataSource.', () => {
let ddlObj: any;
let ddlEle: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'ddl' });
let empList: { [key: string]: Object }[] = [
{ Id: 'Game1', Game: 'American Football' },
{ Id: 'Game2', Game: 'Badminton' },
{ Id: 'Game3', Game: 'Basketball' },
{ Id: 'Game4', Game: 'Cricket' },
{ Id: 'Game5', Game: 'Football' }
];
beforeAll(() => {
document.body.appendChild(ddlEle);
ddlObj = new DropDownList({
dataSource: empList,
fields: { text: 'Game', value: 'Id' },
value: "Game3"
});
ddlObj.appendTo(ddlEle);
});
afterAll(() => {
ddlObj.destroy();
ddlEle.remove();
});
it('check whether the value is maintained after updating the datasource', () => {
ddlObj.dataSource = [
{ Id: 'Game3', Game: 'Golf' },
{ Id: 'Game4', Game: 'Hockey' },
{ Id: 'Game5', Game: 'Rugby' },
{ Id: 'Game6', Game: 'Snooker' },
{ Id: 'Game7', Game: 'Tennis' }];
ddlObj.dataBind();
expect(ddlObj.value).toBe("Game3");
expect(ddlObj.text).toBe("Golf");
expect(ddlObj.inputElement.value).toBe("Golf");
});
it('check whether the value is not maintained after updating the different datasource', () => {
ddlObj.dataSource = [
{ Id: 'Game6', Game: 'Golf' },
{ Id: 'Game7', Game: 'Hockey' },
{ Id: 'Game8', Game: 'Rugby' },
{ Id: 'Game9', Game: 'Snooker' },
{ Id: 'Game10', Game: 'Tennis' }];
ddlObj.dataBind();
expect(ddlObj.value).toBe(null);
expect(ddlObj.text).toBe(null);
expect(ddlObj.inputElement.value).toBe('');
});
});
describe('EJ2-11073 - Change event is not triggered when clicking showClearButton in dropdown components.', () => {
let ddlObj: any;
let isChangeCalled: boolean = false;
let ddlEle: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'ddl' });
let empList: { [key: string]: Object }[] = [
{ Id: 'Game1', Game: 'American Football' },
{ Id: 'Game2', Game: 'Badminton' },
{ Id: 'Game3', Game: 'Basketball' },
{ Id: 'Game4', Game: 'Cricket' },
{ Id: 'Game5', Game: 'Football' }
];
beforeAll(() => {
document.body.appendChild(ddlEle);
ddlObj = new DropDownList({
dataSource: empList,
fields: { text: 'Game', value: 'Id' },
value: "Game3",
showClearButton: true,
change: function () {
isChangeCalled = true;
}
});
ddlObj.appendTo(ddlEle);
});
afterAll(() => {
ddlObj.destroy();
ddlEle.remove();
});
it('check whether the change event is triggered when selected item is removed using clear icons ', () => {
ddlObj.focusIn();
var event = new Event('mousedown');
ddlObj.inputWrapper.clearButton.dispatchEvent(event);
expect(isChangeCalled).toBe(true);
});
});
describe('EJ2-14939 - CssClass applied to the DropDown element is not removed when it is changes dynamically', () => {
let ddlObj: any;
let ddlEle: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'ddl' });
let empList: { [key: string]: Object }[] = [
{ Id: 'Game1', Game: 'American Football' },
{ Id: 'Game2', Game: 'Badminton' },
{ Id: 'Game3', Game: 'Basketball' },
{ Id: 'Game4', Game: 'Cricket' },
{ Id: 'Game5', Game: 'Football' }
];
beforeAll(() => {
document.body.appendChild(ddlEle);
ddlObj = new DropDownList({
dataSource: empList,
fields: { text: 'Game', value: 'Id' },
cssClass: 'abc'
});
ddlObj.appendTo(ddlEle);
});
afterAll(() => {
ddlObj.destroy();
ddlEle.remove();
});
it('check whether the change cssclass dynamically', () => {
expect(ddlObj.inputWrapper.container.classList.contains('abc')).toBe(true);
ddlObj.cssClass = 'dce';
ddlObj.dataBind();
expect(ddlObj.inputWrapper.container.classList.contains('abc')).not.toBe(true);
expect(ddlObj.inputWrapper.container.classList.contains('dce')).toBe(true);
});
});
describe('EJ2-15393 - Multiple requests are made to server', () => {
let listObj: any;
let popupObj: any;
let mouseEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
target: null
};
let element: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
let dataSource = new DataManager({
url: 'https://services.syncfusion.com/js/production/api/Employees',
adaptor: new WebApiAdaptor,
crossDomain: true
});
let query = new Query().select('FirstName').take(0).requiresCount();
let query1 = new Query().select('FirstName').take(3).requiresCount();
let originalTimeout: number;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 8000;
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: dataSource,
query: query,
fields: { text: 'FirstName', value: 'FirstName' },
actionComplete: (e: any) => {
expect(e.name === 'actionComplete').toBe(true);
}
});
listObj.appendTo(element);
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
// it('when "no records" template is added to the dropdownlist', (done) => {
// setTimeout(function () {
// listObj.showPopup();
// }, 200);
// setTimeout(() => {
// expect(listObj.list.classList.contains('e-nodata')).toBe(true);
// expect(listObj.isDataFetched).toBe(true);
// listObj.hidePopup();
// listObj.showPopup();
// expect(listObj.list.classList.contains('e-nodata')).toBe(true);
// expect(listObj.isDataFetched).toBe(true);
// done();
// }, 4000);
// });
it('dynamic change datascource ', (done) => {
listObj.hidePopup();
listObj.dataSource = dataSource;
listObj.query = query1;
listObj.dataBind();
setTimeout(function () {
listObj.showPopup();
}, 200);
setTimeout(() => {
if (listObj.liCollections.length > 0) {
expect(listObj.list.classList.contains('e-nodata')).not.toBe(true);
}
expect(listObj.isDataFetched).not.toBe(true);
if (listObj && listObj.listData) {
expect(listObj.listData.length === 3).toBe(true);
}
done();
}, 5000);
});
// it('set empty datasource ', (done) => {
// listObj.hidePopup();
// listObj.dataSource = dataSource;
// listObj.query = query;
// listObj.dataBind();
// listObj.showPopup();
// setTimeout(() => {
// expect(listObj.list.classList.contains('e-nodata')).toBe(true);
// expect(listObj.isDataFetched).toBe(true);
// listObj.hidePopup();
// listObj.showPopup();
// expect(listObj.list.classList.contains('e-nodata')).toBe(true);
// expect(listObj.isDataFetched).toBe(true);
// done();
// }, 4000);
// });
it('set null datasource ', (done) => {
listObj.hidePopup();
listObj.dataSource = null;
listObj.query = null;
listObj.dataBind();
listObj.showPopup();
setTimeout(() => {
expect(listObj.list.classList.contains('e-nodata')).toBe(true);
done();
}, 2000);
});
});
describe('EJ2-26552 - Defult value maintained in from reset', () => {
let element: HTMLInputElement;
let data: ['American Football', 'Cricket', 'FootBall', 'Hockey', 'BasketBall'];
let listObj: DropDownList;
beforeAll(() => {
element = <HTMLInputElement>createElement('form', { id: 'form1' });
element.innerHTML = `<input type="text" id="ddl">
<input type="reset" id="resetForm"/>`;
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
value: 'American Football',
allowFiltering: true
});
listObj.appendTo('#ddl');
listObj.showPopup();
});
afterAll(() => {
document.body.innerHTML = '';
});
it('reset the form', (done) => {
document.getElementById('resetForm').click();
setTimeout(() => {
expect(listObj.value === 'American Football').toBe(true);
done();
});
});
});
describe('EJ2-16375: Form reset', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA', icon: 'icon' },
{ id: 'list2', text: 'C#' },
{ id: 'list3', text: 'C++' },
{ id: 'list4', text: '.NET', icon: 'icon' },
{ id: 'list5', text: 'Oracle' }
];
let listObj: DropDownList;
beforeAll(() => {
element = <HTMLInputElement>createElement('form', { id: 'form1' });
element.innerHTML = `<input type="text" id="ddl">
<input type="reset" id="resetForm"/>`;
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
fields: { text: "text", value: "id" },
value: 'list1'
});
listObj.appendTo('#ddl');
});
afterAll(() => {
document.body.innerHTML = '';
});
it(' reset the form', (done) => {
document.getElementById('resetForm').click();
setTimeout(() => {
expect(listObj.value === 'list1').toBe(true);
done();
})
});
});
describe('EJ2-16375: Form inside form reset', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA', icon: 'icon' },
{ id: 'list2', text: 'C#' },
{ id: 'list3', text: 'C++' },
{ id: 'list4', text: '.NET', icon: 'icon' },
{ id: 'list5', text: 'Oracle' }
];
let listObj: DropDownList;
beforeAll(() => {
element = <HTMLInputElement>createElement('form', { id: 'form1' });
element.innerHTML = `<input type="text" id="DropDownList">
<div id="dynamic"></div>`;
document.body.appendChild(element);
let dynamicEle: HTMLElement = document.getElementById('dynamic');
let form2: Element = createElement('form');
form2.id = 'form2';
form2.innerHTML = '<input id="tempInput" type="text"/> <input type="reset" id="resetForm"/>';
dynamicEle.appendChild(form2);
listObj = new DropDownList({
dataSource: data,
fields: { text: "text", value: "id" },
value: 'list1'
});
listObj.appendTo('#DropDownList');
});
afterAll(() => {
document.body.innerHTML = '';
});
it(' reset the form', (done) => {
let input: HTMLInputElement = document.getElementById("tempInput") as HTMLInputElement;
input.value = "test";
document.getElementById('resetForm').click();
setTimeout(() => {
expect(listObj.value === 'list1').toBe(true);
expect(input.value === '').toBe(true);
done();
})
});
});
describe('EJ2-27976 - Dynamic filtering issue', () => {
let keyEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
keyCode: 74,
metaKey: false
};
let listObj: any;
let element: HTMLSelectElement;
beforeAll(() => {
element = <HTMLSelectElement>createElement('select', { id: 'list' });
element.innerHTML = `<option value="0">American Football</option>
<option value="1">Badminton</option>
<option value="2">Basketball</option>
<option value="3">Cricket</option>
<option value="4">Football</option>
<option value="5">Golf</option>
<option value="6">Hockey</option>
<option value="7">Rugby</option>
<option value="8">Snooker</option>
<option value="9">Tennis</option>`;
document.body.appendChild(element);
listObj = new DropDownList({
});
listObj.appendTo(element);
listObj.allowFiltering = true
listObj.dataBind();
listObj.showPopup();
});
afterAll(() => {
if (element) { element.remove(); };
document.body.innerHTML = '';
});
it('filter a suggestion list with select element', () => {
listObj.filterInput.value = "C";
listObj.onInput(keyEventArgs);
listObj.onFilterUp(keyEventArgs);
let element = document.querySelector(".e-list-parent");
expect(element.childNodes[0].textContent === 'Cricket').toBe(true);
let li: any = listObj.list.getElementsByClassName('e-list-item');
let len: number = listObj.list.getElementsByClassName('e-list-item').length;
li[0].click();
listObj.hidePopup();
let len2: number = listObj.list.getElementsByClassName('e-list-item').length;
expect(len === len2 ).toBe(true);
});
});
describe('EJ2-17694 - Multiple time ajax request while change the dataSource ', () => {
let listObj: any;
let controlEle: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'auto' });
let result: any = [];
beforeAll((done) => {
document.body.appendChild(controlEle);
let mAjax: MockAjaxReturn = mockAjax({
data: {
d: new DataManager(data).executeLocal(new Query().take(10).select(['OrderID', 'CustomerID', 'EmployeeID']))
}
}, new Query());
mAjax.promise.then((e: ResponseType) => {
result = e.result;
done();
});
});
afterAll(() => {
listObj.destroy();
controlEle.remove();
jasmine.Ajax.uninstall();
});
it('change the dataSource dynamically ', (done) => {
let count: number = 0;
listObj = new DropDownList({
fields: { text: 'CustomerID', value: "OrderID" },
placeholder: 'Select a name',
actionComplete: () => {
count++;
}
});
listObj.appendTo(controlEle);
listObj.focusIn();
listObj.showPopup();
setTimeout(() => {
expect(listObj.list.classList.contains('e-nodata')).toBe(true);
listObj.hidePopup();
count = 0;
setTimeout(() => {
listObj.dataSource = result;
listObj.query = new Query().take(3);
listObj.dataBind();
expect(count === 1).toBe(true);
done();
}, 400);
}, 400);
});
});
describe('focus event', () => {
let listObj: any;
let popupObj: any;
let data: string[] = ['JAVA', 'C#']
let element: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
let mouseEventArgs: any = { preventDefault: function () { }, target: null };
beforeAll(() => {
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
focus: function (e) {
expect((e as any).isInteracted).toBe(true);
}
});
listObj.appendTo(element);
});
afterAll(() => {
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
it('focus the dropdown', () => {
expect(listObj.inputWrapper.container).not.toBe(null);
mouseEventArgs.target = listObj.inputWrapper.container;
listObj.dropDownClick(mouseEventArgs);
});
});
describe(' dynamic datasource changes', () => {
let element: HTMLInputElement;
let listObj: DropDownList;
let popup: HTMLElement;
let liEle: HTMLElement;
let divNode: HTMLDivElement;
let textContent: string;
let empList: { [key: string]: Object }[] = [
{ Name: 'Andrew Fuller', Eimg: '7', Designation: 'Team Lead', Country: 'England' },
{ Name: 'Anne Dodsworth', Eimg: '1', Designation: 'Developer', Country: 'USA' },
{ Name: 'Janet Leverling', Eimg: '3', Designation: 'HR', Country: 'USA' },
{ Name: 'Laura Callahan', Eimg: '2', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Margaret Peacock', Eimg: '6', Designation: 'Developer', Country: 'USA' },
{ Name: 'Michael Suyama', Eimg: '9', Designation: 'Team Lead', Country: 'USA' },
{ Name: 'Nancy Davolio', Eimg: '4', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Robert King', Eimg: '8', Designation: 'Developer ', Country: 'England' },
{ Name: 'Steven Buchanan', Eimg: '10', Designation: 'CEO', Country: 'England' }
];
let changeData: any = [
{ Name: 'Andrew Fuller', Eimg: '7', Designation: 'Team Lead', Country: 'England' },
{ Name: 'Anne Dodsworth', Eimg: '1', Designation: 'Developer', Country: 'USA' },
{ Name: 'Janet Leverling', Eimg: '3', Designation: 'HR', Country: 'USA' },
{ Name: 'Laura Callahan', Eimg: '2', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Margaret Peacock', Eimg: '6', Designation: 'Developer', Country: 'USA' },
{ Name: 'Michael Suyama', Eimg: '9', Designation: 'Team Lead', Country: 'USA' },
{ Name: '111Nancy Davolio', Eimg: '4', Designation: 'hahahProduct Manager111', Country: 'USA11' },
{ Name: 'Robert King', Eimg: '8', Designation: 'Developer ', Country: 'England' },
{ Name: 'Steven Buchanan', Eimg: '10', Designation: 'CEO', Country: 'England' }
];
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: empList,
fields: { text: 'Name', value: 'Eimg' },
itemTemplate: '<div class="ename"> ${Name}</div><div class="job"> ${Designation} </div>',
valueTemplate: '<div class="name" style="display:inline;"> ${Name} </div>',
value: '4',
});
listObj.appendTo(element);
});
it("value template changes", function () {
expect(listObj.value === '4').toBe(true);
expect(listObj.text === 'Nancy Davolio').toBe(true);
listObj.dataSource = changeData;
listObj.dataBind();
expect(listObj.value === '4').toBe(true);
expect(listObj.text === '111Nancy Davolio').toBe(true);
});
afterAll(() => {
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
});
describe('template item not generate', () => {
let element: HTMLInputElement;
let listObj: DropDownList;
let popup: HTMLElement;
let liEle: HTMLElement;
let divNode: HTMLDivElement;
let textContent: string;
let empList: { [key: string]: Object }[] = [
{ Name: 'Andrew Fuller', Eimg: '7', Designation: 'Team Lead', Country: 'England' },
{ Name: 'Anne Dodsworth', Eimg: '1', Designation: 'Developer', Country: 'USA' }
];
let changeData: any = [
{ Name: 'Janet Leverling', Eimg: '3', Designation: 'HR', Country: 'USA' },
{ Name: 'Laura Callahan', Eimg: '2', Designation: 'Product Manager', Country: 'USA' },
{ Name: 'Margaret Peacock', Eimg: '6', Designation: 'Developer', Country: 'USA' },
{ Name: 'Michael Suyama', Eimg: '9', Designation: 'Team Lead', Country: 'USA' },
{ Name: '111Nancy Davolio', Eimg: '4', Designation: 'hahahProduct Manager111', Country: 'USA11' },
{ Name: 'Robert King', Eimg: '8', Designation: 'Developer ', Country: 'England' },
{ Name: 'Steven Buchanan', Eimg: '10', Designation: 'CEO', Country: 'England' }
];
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: empList,
fields: { text: 'Name', value: 'Eimg' },
itemTemplate: '<div class="ename"> ${Name}</div><div class="job"> ${Designation} </div>',
valueTemplate: '<div class="name" style="display:inline;"> ${Name} </div>'
});
listObj.appendTo(element);
});
it("while change the datasource dynamically", function () {
listObj.showPopup();
expect(((listObj as any).ulElement.querySelector('li').firstElementChild as HTMLElement).innerText === 'Andrew Fuller').toBe(true);
expect((listObj as any).ulElement.querySelectorAll('li').length === 2).toBe(true);
listObj.dataSource = changeData;
listObj.dataBind();
expect(((listObj as any).ulElement.querySelector('li').firstElementChild as HTMLElement).innerText === 'Janet Leverling').toBe(true);
expect((listObj as any).ulElement.querySelectorAll('li').length === (listObj.dataSource as any).length).toBe(true);
});
afterAll(() => {
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
});
describe(' add item with Template', () => {
let element: HTMLInputElement;
let listObj: DropDownList;
let popup: HTMLElement;
let liEle: HTMLElement;
let divNode: HTMLDivElement;
let textContent: string;
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: templateDataSource,
fields: { text: 'Name', value: 'Eimg' },
popupHeight: "200px",
// set the template content for list items
itemTemplate: '<div class ="ename" style="color:red;">${Name}</div>',
});
listObj.appendTo(element);
});
it("item template with add item values", function (done) {
expect((listObj.dataSource as string[]).length === templateDataSource.length).toBe(true);
listObj.addItem({ Name: 'dropdown', Eimg: 100 });
listObj.open = function (args) {
popup = document.getElementById('dropdownlist_popup');
divNode = popup.querySelectorAll("li div.ename")[templateDataSource.length] as HTMLDivElement;
textContent = divNode.innerText;
expect(textContent).toEqual('dropdown');
expect((listObj as any).listData.length === 10).toBe(true);
listObj.hidePopup();
listObj.open = null;
};
listObj.close = function (args) {
done();
listObj.close = null;
};
listObj.showPopup();
});
afterAll(() => {
if (element) {
element.remove();
document.body.innerHTML = '';
}
});
});
describe('EJ2-24975: Form reset clear icon', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA', icon: 'icon' },
{ id: 'list2', text: 'C#' },
{ id: 'list3', text: 'C++' },
{ id: 'list4', text: '.NET', icon: 'icon' },
{ id: 'list5', text: 'Oracle' }
];
let listObj: DropDownList;
beforeAll(() => {
element = <HTMLInputElement>createElement('form', { id: 'form1' });
element.innerHTML = `<input type="text" id="ddl">
<input type="reset" id="resetForm"/>`;
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
showClearButton: true,
fields: { text: "text", value: "id" },
value: 'list1'
});
listObj.appendTo('#ddl');
});
afterAll(() => {
document.body.innerHTML = '';
});
it(' reset the form', (done) => {
document.getElementById('resetForm').click();
setTimeout(() => {
expect(listObj.value === 'list1').toBe(true);
expect((listObj as any).inputWrapper.container.querySelector('.e-clear-icon').classList.contains('e-clear-icon-hide')).toBe(true);
done();
})
});
});
describe('EJ2-24995: re selected value not set', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA' },
{ id: 'list2', text: 'C#' }
];
let data1: any = [
{ id: 'list3', text: 'C++' },
{ id: 'list4', text: '.NET' },
{ id: 'list5', text: 'Oracle' }
]
let listObj: DropDownList;
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'ddl' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
fields: { text: "text", value: "id" }
});
listObj.appendTo('#ddl');
});
afterAll(() => {
document.body.innerHTML = '';
});
it(' when datasource is observable using AsyncPipe', () => {
listObj.dataSource = data1;
listObj.dataBind();
listObj.showPopup();
expect((listObj as any).list.querySelectorAll('li').length === data1.length).toBe(true);
listObj.dataSource = data;
listObj.value = 'list2';
listObj.dataBind();
expect((listObj as any).inputElement.value === 'C#').toBe(true);
});
});
describe('BLAZ-762: float values are rounded to int', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA', value: 0.01 },
{ id: 'list2', text: 'C#', value: 0.02 }
];
let mouseEventArgs: any = { preventDefault: function () { }, target: null };
let listObj: any;
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'ddl' });
document.body.appendChild(element);
listObj = new DropDownList({
dataSource: data,
fields: { text: "text", value: "value" }
});
listObj.appendTo('#ddl');
});
afterAll(() => {
document.body.innerHTML = '';
});
it(' value select', () => {
listObj.showPopup();
let item: any = (listObj as any).popupObj.element.querySelectorAll('li')[1];
mouseEventArgs.target = item;
mouseEventArgs.type = 'click';
listObj.onMouseClick(mouseEventArgs);
expect(listObj.value === 0.02).toBe(true);
});
});
describe('EJ2-36017: dropdown cascading', () => {
let element: HTMLInputElement, element1: HTMLInputElement, element2: HTMLInputElement;
var country = [
{ countryName: 'United States', countryId: '1' },
{ countryName: 'Australia', countryId: '2' }
];
var state = [
{ stateName: 'New York', countryId: '1', stateId: '101' },
{ stateName: 'Virginia ', countryId: '1', stateId: '102' },
{ stateName: 'Queensland', countryId: '2', stateId: '103' },
{ stateName: 'Tasmania ', countryId: '2', stateId: '104' }
];
var cities = [
{ cityName: 'Albany', stateId: '101', cityId: 201 },
{ cityName: 'Beacon ', stateId: '101', cityId: 202 },
{ cityName: 'Alexandria', stateId: '102', cityId: 203 },
{ cityName: 'Hampton ', stateId: '102', cityId: 204 },
{ cityName: 'Aberdeen', stateId: '103', cityId: 205 },
{ cityName: 'Colville ', stateId: '103', cityId: 206 },
{ cityName: 'Townsville', stateId: '104', cityId: 207 },
{ cityName: 'Brisbane ', stateId: '104', cityId: 208 }
];
let mouseEventArgs: any = { preventDefault: function () { }, target: null };
let listObj: any, listObj1: any, listObj2: any;
beforeAll(() => {
element = <HTMLInputElement>createElement('input', { id: 'list' });
element1 = <HTMLInputElement>createElement('input', { id: 'list1' });
element2 = <HTMLInputElement>createElement('input', { id: 'list2' });
document.body.appendChild(element);
document.body.appendChild(element1);
document.body.appendChild(element2);
listObj = new DropDownList({
dataSource: country,
fields: { value: 'countryId', text: 'countryName' },
allowFiltering: true,
change: function () {
listObj1.enabled = true;
var tempQuery = new Query().where('countryId', 'equal', listObj.value);
listObj1.query = tempQuery;
listObj1.dataBind();
listObj1.value = null;
listObj2.value = null;
listObj2.enabled = false;
}
});
listObj.appendTo('#list');
listObj1 = new DropDownList({
dataSource: state,
fields: { value: 'stateId', text: 'stateName' },
enabled: false,
allowFiltering: true,
change: function () {
listObj2.enabled = true;
var tempQuery1 = new Query().where('stateId', 'equal', listObj1.value);
listObj2.query = tempQuery1;
listObj2.value = null;
listObj2.dataBind();
},
});
listObj1.appendTo('#list1');
listObj2 = new DropDownList({
dataSource: cities,
fields: { text: 'cityName' },
allowFiltering: true,
enabled: false,
});
listObj2.appendTo('#list2');
});
afterAll(() => {
document.body.innerHTML = '';
});
it('previous value maintained', () => {
listObj.showPopup();
let item: any = (listObj as any).popupObj.element.querySelectorAll('li')[0];
mouseEventArgs.target = item;
mouseEventArgs.type = 'click';
listObj.onMouseClick(mouseEventArgs);
expect(listObj.value === '1').toBe(true);
listObj1.showPopup();
let item1: any = (listObj1 as any).popupObj.element.querySelectorAll('li')[0];
mouseEventArgs.target = item1;
mouseEventArgs.type = 'click';
listObj1.onMouseClick(mouseEventArgs);
expect(listObj1.value === '101').toBe(true);
listObj2.showPopup();
let item2: any = (listObj2 as any).popupObj.element.querySelectorAll('li')[0];
mouseEventArgs.target = item2;
mouseEventArgs.type = 'click';
listObj2.onMouseClick(mouseEventArgs);
expect(listObj2.value === 'Albany').toBe(true);
listObj1.showPopup();
let item3: any = (listObj1 as any).popupObj.element.querySelectorAll('li')[1];
mouseEventArgs.target = item3;
mouseEventArgs.type = 'click';
listObj1.onMouseClick(mouseEventArgs);
listObj2.showPopup();
let item4: any = (listObj2 as any).popupObj.element.querySelectorAll('li');
expect(item4.length === 2).toBe(true);
});
});
describe('EJ2-26287: popup collision not working', () => {
let element: HTMLInputElement;
let data: { [key: string]: Object }[] = [
{ id: 'list1', text: 'JAVA' },
{ id: 'list2', text: 'C#' }
];
let listObj: DropDownList;
beforeAll(() => {
let parentEle: any = <HTMLInputElement>createElement('div');
document.body.appendChild(parentEle);
let divEle: any = <HTMLInputElement>createElement('div', { styles: 'height:700px; position: relative;' });
parentEle.appendChild(divEle);
element = <HTMLInputElement>createElement('input', { id: 'ddl' });
parentEle.appendChild(element);
listObj = new DropDownList({
dataSource: data,
fields: { text: "text", value: "id" },
allowFiltering: true
});
listObj.appendTo('#ddl');
});
afterAll(() => {
document.body.innerHTML = '';
});
// it('when enable the filtering', () => {
// listObj.focusIn();
// listObj.showPopup();
// expect((listObj as any).list.querySelectorAll('li').length === data.length).toBe(true);
// expect(parseInt(getComputedStyle((listObj as any).popupObj.element).marginTop) === 0).toBe(true);
// });
});
// describe('EJ2-18309 - Maximum call stack error while emptying dataSource with filtering and remote data', () => {
// let listObj: any;
// let element: HTMLInputElement = <HTMLInputElement>createElement('input', { id: 'dropdownlist' });
// let originalTimeout: number;
// beforeEach((done) => {
// originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
// jasmine.DEFAULT_TIMEOUT_INTERVAL = 6000;
// document.body.appendChild(element);
// listObj = new DropDownList({
// dataSource: new DataManager({