diff --git a/scripts/test/helper.js b/scripts/test/helper.js index ea171c06..058f5885 100644 --- a/scripts/test/helper.js +++ b/scripts/test/helper.js @@ -74,3 +74,40 @@ export function triggerEvent(element, type, data = {}) { element.dispatchEvent(event); return event; } + +/** + * A stub of the Plugin class + * + * @class PluginStub + */ +export class PluginStub { + + /** + * Constructor. + * + * @param {Draggable} draggable + */ + constructor(draggable) { + this.attachWasCalled = false; + this.detachWasCalled = false; + this.draggable = draggable; + this.numTimesAttachCalled = 0; + this.numTimesDetachCalled = 0; + } + + /** + * Set a testable property when `attach` is called + */ + attach() { + this.attachWasCalled = true; + this.numTimesAttachCalled++; + } + + /** + * Set a testable property when `detach` is called + */ + detach() { + this.detachWasCalled = true; + this.numTimesDetachCalled++; + } +} diff --git a/src/Draggable/Draggable.js b/src/Draggable/Draggable.js index 84385bf9..a1fc4a3f 100644 --- a/src/Draggable/Draggable.js +++ b/src/Draggable/Draggable.js @@ -36,7 +36,7 @@ const onDragStop = Symbol('onDragStop'); const onDragPressure = Symbol('onDragPressure'); const getAppendableContainer = Symbol('getAppendableContainer'); -const defaults = { +export const defaultOptions = { draggable: '.draggable-source', handle: null, delay: 100, @@ -83,7 +83,7 @@ export default class Draggable { throw new Error('Draggable containers are expected to be of type `NodeList`, `HTMLElement[]` or `HTMLElement`'); } - this.options = {...defaults, ...options}; + this.options = {...defaultOptions, ...options}; this.callbacks = {}; /** @@ -279,7 +279,7 @@ export default class Draggable { * @return {String|null} */ getClassNameFor(name) { - return this.options.classes[name] || defaults.classes[name]; + return this.options.classes[name] || defaultOptions.classes[name]; } /** diff --git a/src/Draggable/tests/Draggable.test.js b/src/Draggable/tests/Draggable.test.js index a5330a30..7b1c68de 100644 --- a/src/Draggable/tests/Draggable.test.js +++ b/src/Draggable/tests/Draggable.test.js @@ -1,10 +1,30 @@ import { createSandbox, triggerEvent, + PluginStub, } from 'helper'; -import Draggable from './..'; -import {DragStartEvent} from './../DragEvent'; +import Draggable, { + defaultOptions, +} from './../Draggable'; + +import { + DragStartEvent, + DragMoveEvent, + DragStopEvent, +} from './../DragEvent'; + +import { + DraggableInitializedEvent, + DraggableDestroyEvent, +} from './../DraggableEvent'; + +import {Accessibility, Mirror} from './../Plugins'; + +import { + MouseSensor, + TouchSensor, +} from './../Sensors'; const sampleMarkup = `