Skip to content

Commit

Permalink
Merge pull request Shopify#80 from timrourke/feature/add-draggable-tests
Browse files Browse the repository at this point in the history
Feature/add draggable tests
  • Loading branch information
tsov authored Jan 10, 2018
2 parents 1bd10f0 + 05c77b1 commit a3e74c6
Show file tree
Hide file tree
Showing 3 changed files with 659 additions and 14 deletions.
37 changes: 37 additions & 0 deletions scripts/test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
6 changes: 3 additions & 3 deletions src/Draggable/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};

/**
Expand Down Expand Up @@ -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];
}

/**
Expand Down
Loading

0 comments on commit a3e74c6

Please sign in to comment.