-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathsplit-button.spec.ts
204 lines (186 loc) · 8.26 KB
/
split-button.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
/* eslint-disable @typescript-eslint/no-explicit-any */
import { SplitButton } from '../src/split-button/split-button';
import { ItemModel } from '../src/common/common-model';
import { createElement } from '@syncfusion/ej2-base';
import { profile , inMB, getMemoryProfile } from './common.spec';
/**
* Split Button spec
*/
describe('Split Button', () => {
beforeAll(() => {
const isDef: any = (o: any) => o !== undefined && o !== null;
if (!isDef(window.performance)) {
console.log('Unsupported environment, window.performance.memory is unavailable');
this.skip(); // skips test (in Chai)
return;
}
});
let button: any;
const items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}];
const element: any = createElement('button', { id: 'splitbtn' });
document.body.appendChild(element);
afterEach(() => {
button.destroy();
});
it('Architecture', () => {
button = new SplitButton({}, '#splitbtn');
expect(element.parentElement.classList).toContain('e-split-btn-wrapper');
expect(element.nextElementSibling.classList).toContain('e-dropdown-btn');
});
it('click event args', () => {
const click: any = (args: any) => {
expect(args.element).toEqual(button.element);
};
button = new SplitButton({ click: click }, '#splitbtn');
button.element.click();
});
it('rtl support', () => {
button = new SplitButton({ enableRtl: true }, '#splitbtn');
expect(element.parentElement.classList).toContain('e-rtl');
button.enableRtl = false;
button.dataBind();
expect(element.parentElement.classList).not.toContain('e-rtl');
button.enableRtl = true;
button.dataBind();
expect(element.parentElement.classList).toContain('e-rtl');
});
it('cssClass support', () => {
button = new SplitButton({ cssClass: 'class1' }, '#splitbtn');
expect(element.parentElement.classList).toContain('class1');
button.cssClass = 'class2';
button.dataBind();
expect(element.parentElement.classList).toContain('class2');
});
it('Disabled support', () => {
button = new SplitButton({ disabled: true }, '#splitbtn');
expect(element.disabled).toBeTruthy();
expect(element.nextElementSibling.disabled).toBeTruthy();
});
it('Create popup on open', () => {
button = new SplitButton({ items: items, createPopupOnClick: true }, '#splitbtn');
expect(button.secondaryBtnObj.dropDown).toEqual(undefined);
button.secondaryBtnObj.element.click();
expect(button.secondaryBtnObj.dropDown.element.classList.contains('e-popup-open')).toEqual(true);
});
it('Text with Icon position top & left testing', () => {
button = new SplitButton({ content: 'SplitButton', iconCss: 'iconcss'});
button.appendTo('#splitbtn');
expect(element.textContent).toEqual('SplitButton');
expect(element.children[0].classList.contains('iconcss')).toEqual(true);
expect(element.children[0].classList.contains('e-icon-left')).toBeTruthy();
button.iconPosition = 'Top';
button.dataBind();
expect(element.children[0].classList.contains('e-icon-top')).toBeTruthy();
button.iconPosition = 'Left';
button.dataBind();
expect(element.children[0].classList.contains('e-icon-top')).toBeFalsy();
expect(element.children[0].classList.contains('e-icon-left')).toBeTruthy();
button.destroy();
});
it('Alt + down key checking', () => {
const altDownEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
action: 'altdownarrow',
type: 'keyup',
target: null
};
button = new SplitButton({ items: items });
button.appendTo('#splitbtn');
altDownEventArgs.target = button.element;
button.btnKeyBoardHandler(altDownEventArgs);
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeTruthy();
});
it('Alt + up key checking', () => {
const altUpEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
altKey: true,
keyCode: 38,
target: null
};
button = new SplitButton({ items: items });
button.appendTo('#splitbtn');
button.keyBoardHandler(altUpEventArgs);
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
});
it('Enter key checking', () => {
const enterEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
keyCode: 13,
target: null
};
const downEventArgs: any = {
preventDefault: (): void => { /** NO Code */ },
key: 'altdownarrow',
type: 'keyup',
target: null
};
button = new SplitButton({ items: items });
button.appendTo('#splitbtn');
button.secondaryBtnObj.element.click();
const li: Element[] = <Element[] & NodeListOf<HTMLLIElement>>button.dropDown.element.querySelectorAll('li');
li[0].classList.add('e-focused');
button.keyBoardHandler(downEventArgs);
enterEventArgs.target = li[1];
button.keyBoardHandler(enterEventArgs);
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.secondaryBtnObj.element.click();
enterEventArgs.target = button.dropDown.element.children[0];
button.keyBoardHandler(enterEventArgs);
});
it('Popup open/close testing by click', () => {
button = new SplitButton({ items: items });
button.appendTo('#splitbtn');
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.secondaryBtnObj.element.click();
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeTruthy();
button.secondaryBtnObj.element.click();
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.secondaryBtnObj.element.click();
button.mousedownHandler({ target: document.body });
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.secondaryBtnObj.element.click();
const ele: HTMLElement = button.dropDown.element.querySelector('.e-item');
ele.classList.add('e-focused');
ele.click();
expect(button.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.mousedownHandler({ target: document.body });
});
it('Toggle method', () => {
button = new SplitButton({ items: items }, '#splitbtn');
expect(button.secondaryBtnObj.dropDown.element.classList.contains('e-popup-open')).toBeFalsy();
button.toggle();
expect(button.secondaryBtnObj.dropDown.element.classList.contains('e-popup-open')).toBeTruthy();
button.toggle();
expect(button.secondaryBtnObj.dropDown.element.classList.contains('e-popup-close')).toBeTruthy();
});
it('Angular support', () => {
document.body.appendChild(createElement('EJS-SPLITBUTTON', { id: 'angsplitbtn' }));
button = new SplitButton({}, '#angsplitbtn');
expect(button.element.parentElement.tagName).toEqual('EJS-SPLITBUTTON');
expect(button.element.parentElement.classList).toContain('e-split-btn-wrapper');
expect(button.element.nextElementSibling.classList).toContain('e-dropdown-btn');
});
it('Native methods Focus', () => {
document.body.appendChild(createElement('EJS-SPLITBUTTON', { id: 'angsplitbtn' }));
button = new SplitButton({}, '#angsplitbtn');
button.focusIn();
});
it('memory leak', () => {
profile.sample();
const average: any = inMB(profile.averageChange);
// check average change in memory samples to not be over 10MB
expect(average).toBeLessThan(10);
const memory: any = inMB(getMemoryProfile());
// check the final memory usage against the first usage, there should be little change if everything was properly deallocated
expect(memory).toBeLessThan(profile.samples[0] + 0.25);
});
});