forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktopTooltip.tests.js
More file actions
369 lines (296 loc) · 16.7 KB
/
desktopTooltip.tests.js
File metadata and controls
369 lines (296 loc) · 16.7 KB
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
import { DesktopTooltipStrategy } from '__internal/scheduler/tooltip_strategies/m_desktop_tooltip_strategy';
import { FunctionTemplate } from 'core/templates/function_template';
import { extend } from 'core/utils/extend';
import Tooltip from 'ui/tooltip';
import List from '__internal/ui/list/list.edit';
import Button from 'ui/button';
import support from '__internal/core/utils/m_support';
const stubComponent = {
option: sinon.stub().returns('stubOption'),
focus: sinon.stub(),
setAria: () => {},
};
const stubCreateComponent = sinon.stub().returns(stubComponent);
const stubShowAppointmentPopup = sinon.stub();
const stubAddDefaultTemplates = sinon.stub();
const stubGetAppointmentTemplate = sinon.stub().returns('template');
const stubCheckAndDeleteAppointment = sinon.stub();
const stubCreateFormattedDateText = sinon.stub().returns('text');
const stubGetAppointmentDisabled = sinon.stub().returns(false);
const stubIsAppointmentInAllDayPanel = sinon.stub().returns(true);
const environment = {
createSimpleTooltip: function(tooltipOptions) {
return new DesktopTooltipStrategy(tooltipOptions);
},
tooltipOptions: {
createComponent: stubCreateComponent,
container: '<div>',
addDefaultTemplates: stubAddDefaultTemplates,
getAppointmentTemplate: stubGetAppointmentTemplate,
showAppointmentPopup: stubShowAppointmentPopup,
createFormattedDateText: stubCreateFormattedDateText,
getAppointmentDisabled: stubGetAppointmentDisabled,
checkAndDeleteAppointment: stubCheckAndDeleteAppointment,
isAppointmentInAllDayPanel: stubIsAppointmentInAllDayPanel
},
extraOptions: {
rtlEnabled: true,
focusStateEnabled: true,
editing: true,
offset: 'offset',
isButtonClick: false,
},
afterEach: function() {
stubCreateComponent.resetHistory();
stubComponent.option.resetHistory();
stubShowAppointmentPopup.resetHistory();
stubAddDefaultTemplates.resetHistory();
stubGetAppointmentTemplate.resetHistory();
stubCreateFormattedDateText.resetHistory();
stubCreateFormattedDateText.resetHistory();
stubCheckAndDeleteAppointment.resetHistory();
}
};
QUnit.module('Tooltip', environment);
QUnit.test('Show tooltip', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
assert.ok(tooltip, 'tooltip is created');
assert.equal(stubComponent.option.callCount, 2);
assert.deepEqual(stubComponent.option.getCall(0).args, ['position', {
'at': 'top',
'collision': 'fit flipfit',
'my': 'bottom',
boundary: '<div>',
offset: 'offset',
}], 'tooltip has correct position');
assert.deepEqual(stubComponent.option.getCall(1).args, ['visible', true], 'tooltip is visible');
assert.ok(stubCreateComponent.calledOnce);
});
QUnit.test('Shouldn\'t show tooltip if data is not array', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = 12;
tooltip.show('target', dataList, this.extraOptions);
assert.ok(!stubCreateComponent.called);
});
QUnit.test('createComponent should be called with correct options', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
assert.equal(stubCreateComponent.getCall(0).args[0][0].className, 'dx-scheduler-appointment-tooltip-wrapper');
assert.deepEqual(stubCreateComponent.getCall(0).args[1], Tooltip);
assert.equal(Object.keys(stubCreateComponent.getCall(0).args[2]).length, 7);
assert.equal(stubCreateComponent.getCall(0).args[2].target, 'target');
assert.equal(stubCreateComponent.getCall(0).args[2].maxHeight, 200);
assert.equal(stubCreateComponent.getCall(0).args[2].rtlEnabled, true);
assert.ok(stubCreateComponent.getCall(0).args[2].onShown);
assert.ok(stubCreateComponent.getCall(0).args[2].contentTemplate);
});
QUnit.test('contentTemplate passed to createComponent should work correct', async function(assert) {
const _touch = support.touch;
try {
support.touch = false;
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
assert.equal(stubCreateComponent.getCall(1).args[0][0].nodeName, 'DIV');
assert.equal(stubCreateComponent.getCall(1).args[1], List);
assert.equal(Object.keys(stubCreateComponent.getCall(1).args[2]).length, 7);
assert.equal(stubCreateComponent.getCall(1).args[2].dataSource, dataList);
assert.equal(stubCreateComponent.getCall(1).args[2].showScrollbar, 'onHover');
assert.ok(stubCreateComponent.getCall(1).args[2].onContentReady);
assert.ok(stubCreateComponent.getCall(1).args[2].onItemClick);
assert.ok(stubCreateComponent.getCall(1).args[2].itemTemplate);
assert.equal(stubCreateComponent.getCall(1).args[2].pageLoadMode, 'scrollBottom'); // T1062566
} finally {
support.touch = _touch;
}
});
QUnit.test('Tooltip should update the content after call method "show" several times', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubComponent.option.reset();
tooltip.show('target', ['updatedData1', 'updatedData2'], this.extraOptions);
assert.equal(stubComponent.option.callCount, 5);
assert.deepEqual(stubComponent.option.getCall(0).args, ['visible', false]);
assert.deepEqual(stubComponent.option.getCall(1).args, ['target', 'target']);
assert.deepEqual(stubComponent.option.getCall(2).args, ['dataSource', ['updatedData1', 'updatedData2']]);
assert.deepEqual(stubComponent.option.getCall(3).args, ['position', {
'at': 'top',
'collision': 'fit flipfit',
'my': 'bottom',
boundary: '<div>',
offset: 'offset'
}]);
assert.deepEqual(stubComponent.option.getCall(4).args, ['visible', true]);
});
QUnit.test('onShown passed to createComponent should work correct, one element in tooltip', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
stubComponent.option.reset();
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(0).args[2].onShown();
assert.equal(stubComponent.option.callCount, 1);
assert.deepEqual(stubComponent.option.getCall(0).args, ['focusStateEnabled', true]);
});
QUnit.test('onShown passed to createComponent should work correct, several elements in tooltip', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, extend(this.extraOptions, { isButtonClick: true }));
stubComponent.option.reset();
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(0).args[2].onShown();
assert.equal(stubComponent.option.callCount, 2);
assert.deepEqual(stubComponent.option.getCall(1).args, ['focusedElement', null]);
assert.ok(stubComponent.focus.called);
});
QUnit.test('contentTemplate passed to createComponent should pass correct showScrollbar option for touch device', async function(assert) {
const _touch = support.touch;
try {
support.touch = true;
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
assert.equal(stubCreateComponent.getCall(1).args[2].showScrollbar, 'always');
} finally {
support.touch = _touch;
}
});
QUnit.test('onContentReady passed to createComponent should work correct', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
assert.equal(stubCreateComponent.getCall(1).args[2].onContentReady(), undefined, 'called without errors');
});
QUnit.test('onContentReady passed to createComponent should work correct, with dragBehavior', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const dragBehavior = sinon.spy();
tooltip.show('target', dataList, extend(this.extraOptions, { dragBehavior: dragBehavior }));
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
assert.equal(stubCreateComponent.getCall(1).args[2].onContentReady(), undefined, 'called without errors');
assert.ok(dragBehavior.called);
});
QUnit.test('onItemClick passed to createComponent should work correct', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const event = { itemData: { appointment: 'appointment', targetedAppointment: 'targetedAppointment' } };
tooltip.show('target', dataList, this.extraOptions);
stubComponent.option.reset();
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].onItemClick(event);
assert.deepEqual(stubComponent.option.getCall(0).args, ['visible', false], 'tooltip is hide');
assert.deepEqual(stubShowAppointmentPopup.getCall(0).args, [event.itemData.appointment, false, event.itemData.targetedAppointment]);
});
QUnit.test('onItemClick passed to createComponent should work correct, with clickEvent', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const event = { itemData: { appointment: 'appointment', targetedAppointment: 'targetedAppointment' } };
const clickEvent = sinon.spy();
tooltip.show('target', dataList, extend(this.extraOptions, { clickEvent: clickEvent }));
stubComponent.option.reset();
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].onItemClick(event);
assert.deepEqual(stubComponent.option.getCall(0).args, ['visible', false], 'tooltip is hide');
assert.deepEqual(stubShowAppointmentPopup.getCall(0).args, [event.itemData.appointment, false, event.itemData.targetedAppointment]);
assert.ok(clickEvent.called);
});
QUnit.test('itemTemplate passed to createComponent should work correct', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const item = { appointment: 'data', targetedAppointment: 'currentData', color: { then: sinon.spy() } };
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
const itemTemplate = stubCreateComponent.getCall(1).args[2].itemTemplate(item, 'index');
assert.ok(itemTemplate instanceof FunctionTemplate);
assert.ok(stubAddDefaultTemplates.getCall(0).args[0]['appointmentTooltip'] instanceof FunctionTemplate);
assert.equal(stubGetAppointmentTemplate.getCall(0).args[0], 'appointmentTooltipTemplate');
assert.deepEqual(stubCreateFormattedDateText.getCall(0).args, [item.appointment, item.targetedAppointment]);
// create delete button
assert.equal(stubCreateComponent.getCall(2).args[0][0].className, 'dx-tooltip-appointment-item-delete-button');
assert.deepEqual(stubCreateComponent.getCall(2).args[1], Button);
assert.equal(stubCreateComponent.getCall(2).args[2].icon, 'trash');
assert.equal(stubCreateComponent.getCall(2).args[2].stylingMode, 'text');
assert.ok(stubCreateComponent.getCall(2).args[2].onClick);
// check onClick function
stubComponent.option.reset();
const e = { event: { stopPropagation: sinon.spy() } };
stubCreateComponent.getCall(2).args[2].onClick(e);
assert.deepEqual(stubComponent.option.getCall(0).args, ['visible', false], 'tooltip is hide');
assert.ok(e.event.stopPropagation.called);
assert.deepEqual(stubCheckAndDeleteAppointment.getCall(0).args, [item.appointment, item.targetedAppointment]);
});
QUnit.test('Delete button shouldn\'t createed, editing = false', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const item = { appointment: 'appointment', targetedAppointment: 'appointment', color: { then: sinon.spy() } };
tooltip.show('target', dataList, extend(this.extraOptions, { editing: false }));
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].itemTemplate(item, 'index');
assert.equal(stubCreateComponent.getCall(2), undefined);
});
QUnit.test('Delete button shouldn\'t created, appointment is disabled', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = [{ data: 'data1', disabled: true }, { data: 'data2', disabled: true }];
const item = { appointment: dataList[0], targetedAppointment: 'currentData', color: { then: sinon.spy() } };
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].itemTemplate(item, 'index');
assert.equal(stubCreateComponent.getCall(2), undefined);
});
QUnit.test('isAlreadyShown method, tooltip is not created', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const target = ['target'];
assert.ok(!tooltip.isAlreadyShown(target), 'tooltip is not created and haven\'t data');
});
QUnit.test('isAlreadyShown method, tooltip is created and shown', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = [{ data: 'data1' }, { data: 'data2' }];
const target = ['target'];
const callback = sinon.stub();
callback.withArgs('target').returns(target);
callback.withArgs('visible').returns(true);
stubComponent.option = callback;
tooltip.show(target, dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
assert.ok(tooltip.isAlreadyShown(target), 'tooltip is shown and have the same target');
assert.ok(!tooltip.isAlreadyShown(['target_1']), 'tooltip is shown and have another target');
});
QUnit.test('isAlreadyShown method, tooltip is hide', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = [{ data: 'data1' }, { data: 'data2' }];
const target = ['target'];
const callback = sinon.stub();
callback.withArgs('target').returns(target);
callback.withArgs('visible').returns(false);
stubComponent.option = callback;
tooltip.show(target, dataList, this.extraOptions);
assert.ok(!tooltip.isAlreadyShown(target), 'tooltip is hidden');
});
QUnit.test('appointmentTooltipTemplate equal to "appointmentTooltipTemplate"', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const item = { appointment: 'appointment', targetedAppointment: 'targetedAppointment', color: { then: sinon.spy() } };
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].itemTemplate(item, 'index');
assert.ok(stubAddDefaultTemplates.getCall(0).args[0]['appointmentTooltip'] instanceof FunctionTemplate);
assert.equal(stubGetAppointmentTemplate.getCall(0).args[0], 'appointmentTooltipTemplate');
});
QUnit.test('appointmentTooltipTemplate equal to custom template', async function(assert) {
const tooltip = this.createSimpleTooltip(this.tooltipOptions);
const dataList = ['data1', 'data2'];
const item = { appointment: 'appointment', targetedAppointment: 'targetedAppointment', color: { then: sinon.spy() } };
tooltip.show('target', dataList, this.extraOptions);
stubCreateComponent.getCall(0).args[2].contentTemplate('<div>');
stubCreateComponent.getCall(1).args[2].itemTemplate(item, 'index');
assert.ok(stubAddDefaultTemplates.getCall(0).args[0]['appointmentTooltip'] instanceof FunctionTemplate);
assert.equal(stubGetAppointmentTemplate.getCall(0).args[0], 'appointmentTooltipTemplate');
});