Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 64268d8

Browse files
committed
fix(slider): Add missing code coverage foundation tests
1 parent 5326bf0 commit 64268d8

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/unit/mdc-slider/foundation.test.js

+74
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,32 @@ test('on touchstart calls preventDefault', () => {
297297
td.verify(evt.preventDefault());
298298
});
299299

300+
test('on touchmove call returns if is IE', () => {
301+
const { foundation, mockAdapter } = setupTest();
302+
const handlers = captureHandlers(mockAdapter, 'registerHandler');
303+
const evt = {
304+
preventDefault: td.func('evt.preventDefault'),
305+
};
306+
307+
td.when(mockAdapter.detectIsIE()).thenReturn(true);
308+
foundation.init();
309+
handlers.touchmove(evt);
310+
td.verify(evt.preventDefault(), { times: 0 });
311+
});
312+
313+
test('on touchmove call returns if pointerType not touch', () => {
314+
const { foundation, mockAdapter } = setupTest();
315+
const handlers = captureHandlers(mockAdapter, 'registerHandler');
316+
const evt = {
317+
preventDefault: td.func('evt.preventDefault'),
318+
pointerType: 'other',
319+
};
320+
321+
foundation.init();
322+
handlers.touchmove(evt);
323+
td.verify(evt.preventDefault(), { times: 0 });
324+
});
325+
300326
test('on mousedown calls preventDefault', () => {
301327
const { foundation, mockAdapter } = setupTest();
302328
const handlers = captureHandlers(mockAdapter, 'registerRootHandler');
@@ -318,6 +344,27 @@ test('on mousedown calls preventDefault', () => {
318344
td.verify(evt.preventDefault());
319345
});
320346

347+
test('on mousedown returns if target not parentElement', () => {
348+
const { foundation, mockAdapter } = setupTest();
349+
const handlers = captureHandlers(mockAdapter, 'registerRootHandler');
350+
const target = {};
351+
const evt = {
352+
preventDefault: td.func('evt.preventDefault'),
353+
target,
354+
};
355+
356+
const nativeInput = {
357+
max: 100,
358+
parentElement: {},
359+
getBoundingClientRect: () => ({ width: 100, left: 0, top: 10 }),
360+
dispatchEvent: () => undefined,
361+
};
362+
td.when(mockAdapter.getNativeInput()).thenReturn(nativeInput);
363+
foundation.init();
364+
handlers.mousedown(evt);
365+
td.verify(evt.preventDefault(), { times: 0 });
366+
});
367+
321368
test('on mousedown calls dispatchEvent', () => {
322369
const { foundation, mockAdapter } = setupTest();
323370
const handlers = captureHandlers(mockAdapter, 'registerRootHandler');
@@ -339,6 +386,33 @@ test('on mousedown calls dispatchEvent', () => {
339386
td.verify(nativeInput.dispatchEvent(td.matchers.anything()));
340387
});
341388

389+
test("#on mousedown dispatches a mouse event with the supplied data where MouseEvent isn't available", () => {
390+
const { foundation, mockAdapter } = setupTest();
391+
const handlers = captureHandlers(mockAdapter, 'registerRootHandler');
392+
const target = {};
393+
const evt = {
394+
preventDefault: td.func('evt.preventDefault'),
395+
target,
396+
};
397+
398+
const nativeInput = {
399+
max: 100,
400+
parentElement: target,
401+
getBoundingClientRect: () => ({ width: 100, left: 0, top: 10 }),
402+
dispatchEvent: td.func('input.dispatchEvent'),
403+
};
404+
td.when(mockAdapter.getNativeInput()).thenReturn(nativeInput);
405+
foundation.init();
406+
const { MouseEvent } = window;
407+
window.MouseEvent = undefined;
408+
try {
409+
handlers.mousedown(evt);
410+
} finally {
411+
window.MouseEvent = MouseEvent;
412+
}
413+
td.verify(nativeInput.dispatchEvent(td.matchers.anything()));
414+
});
415+
342416
test('on mouseup calls target.blur()', () => {
343417
const { foundation, mockAdapter } = setupTest();
344418
const handlers = captureHandlers(mockAdapter, 'registerHandler');

0 commit comments

Comments
 (0)