-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from mnoble01/master
Move test-support helpers to addon-test-support
- Loading branch information
Showing
11 changed files
with
178 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import EmberObject from '@ember/object'; | ||
|
||
var c = EmberObject.extend({ | ||
getData: function() { | ||
return this.get('payload'); | ||
}, | ||
|
||
setData: function(dataType,payload) { | ||
this.set("data", {dataType: dataType, payload: payload}); | ||
} | ||
}); | ||
|
||
c.reopenClass({ | ||
makeMockEvent: function(payload) { | ||
var transfer = this.create({payload: payload}); | ||
var res = {dataTransfer: transfer}; | ||
res.preventDefault = function() { | ||
console.log('prevent default'); | ||
}; | ||
res.stopPropagation = function() { | ||
console.log('stop propagation'); | ||
}; | ||
return res; | ||
}, | ||
|
||
createDomEvent: function(type) { | ||
var event = document.createEvent("CustomEvent"); | ||
event.initCustomEvent(type, true, true, null); | ||
event.dataTransfer = { | ||
data: {}, | ||
setData: function(type, val){ | ||
this.data[type] = val; | ||
}, | ||
getData: function(type){ | ||
return this.data[type]; | ||
} | ||
}; | ||
return event; | ||
} | ||
}); | ||
|
||
export default c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {find, triggerEvent} from '@ember/test-helpers'; | ||
import MockEvent from './mock-event'; | ||
|
||
async function dragOver(dropSelector, moves) { | ||
moves = moves || [[{ clientX: 1, clientY: 1 }, dropSelector]]; | ||
|
||
for (const move of moves) { | ||
const position = move[0] || false; | ||
const selector = move[1] || false; | ||
const event = new MockEvent(position); | ||
await triggerEvent(selector || dropSelector, 'dragover', event); | ||
} | ||
} | ||
|
||
async function drop(dragSelector, dragEvent, options) { | ||
let { drop: dropSelector, dropEndOptions, dragOverMoves } = options; | ||
|
||
let dropElement = await find(dropSelector); | ||
if (!dropElement) { | ||
throw(`There are no drop targets by the given selector: '${dropSelector}'`); | ||
} | ||
|
||
await dragOver(dropSelector, dragOverMoves); | ||
|
||
if (options.beforeDrop) { | ||
await options.beforeDrop.call(); | ||
} | ||
|
||
let event = new MockEvent().useDataTransferData(dragEvent); | ||
await triggerEvent(dropSelector, 'drop', event); | ||
|
||
return await triggerEvent(dragSelector, 'dragend', dropEndOptions); | ||
} | ||
|
||
export async function drag(dragSelector, options = {}) { | ||
let dragEvent = new MockEvent(options.dragStartOptions); | ||
|
||
await triggerEvent(dragSelector, 'mouseover'); | ||
|
||
await triggerEvent(dragSelector, 'dragstart', dragEvent); | ||
|
||
if (options.afterDrag) { | ||
await options.afterDrag.call(); | ||
} | ||
|
||
if (options.drop) { | ||
await drop(dragSelector, dragEvent, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class DataTransfer { | ||
constructor() { | ||
this.data = {}; | ||
} | ||
|
||
setData(type, value) { | ||
this.data[type] = value; | ||
return this; | ||
} | ||
|
||
getData(type = "Text") { | ||
return this.data[type]; | ||
} | ||
|
||
setDragImage() { | ||
} | ||
} | ||
|
||
export default class MockEvent { | ||
constructor(options = {}) { | ||
this.dataTransfer = new DataTransfer(); | ||
this.dataTransfer.setData('Text', options.dataTransferData); | ||
this.setProperties(options) | ||
} | ||
|
||
useDataTransferData(otherEvent) { | ||
this.dataTransfer.setData('Text', otherEvent.dataTransfer.getData()); | ||
return this; | ||
} | ||
|
||
setProperties(props) { | ||
for (let prop in props) { | ||
this[prop] = props[prop]; | ||
} | ||
return this; | ||
} | ||
|
||
preventDefault() { | ||
} | ||
|
||
stopPropagation() { | ||
} | ||
} | ||
|
||
export function createDomEvent(type) { | ||
let event = document.createEvent("CustomEvent"); | ||
event.initCustomEvent(type, true, true, null); | ||
event.dataTransfer = new DataTransfer(); | ||
return event; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1 @@ | ||
import EmberObject from '@ember/object'; | ||
|
||
var c = EmberObject.extend({ | ||
getData: function() { | ||
return this.get('payload'); | ||
}, | ||
|
||
setData: function(dataType,payload) { | ||
this.set("data", {dataType: dataType, payload: payload}); | ||
} | ||
}); | ||
|
||
c.reopenClass({ | ||
makeMockEvent: function(payload) { | ||
var transfer = this.create({payload: payload}); | ||
var res = {dataTransfer: transfer}; | ||
res.preventDefault = function() { | ||
console.log('prevent default'); | ||
}; | ||
res.stopPropagation = function() { | ||
console.log('stop propagation'); | ||
}; | ||
return res; | ||
}, | ||
|
||
createDomEvent: function(type) { | ||
var event = document.createEvent("CustomEvent"); | ||
event.initCustomEvent(type, true, true, null); | ||
event.dataTransfer = { | ||
data: {}, | ||
setData: function(type, val){ | ||
this.data[type] = val; | ||
}, | ||
getData: function(type){ | ||
return this.data[type]; | ||
} | ||
}; | ||
return event; | ||
} | ||
}); | ||
|
||
export default c; | ||
export { default } from 'ember-drag-drop/test-support/helpers/data-transfer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,2 @@ | ||
import {find, triggerEvent} from '@ember/test-helpers'; | ||
import MockEvent from './mock-event'; | ||
|
||
async function dragOver(dropSelector, moves) { | ||
moves = moves || [[{ clientX: 1, clientY: 1 }, dropSelector]]; | ||
|
||
for (const move of moves) { | ||
const position = move[0] || false; | ||
const selector = move[1] || false; | ||
const event = new MockEvent(position); | ||
await triggerEvent(selector || dropSelector, 'dragover', event); | ||
} | ||
} | ||
|
||
async function drop(dragElement, dragEvent, options) { | ||
let { drop: dropSelector, dropEndOptions, dragOverMoves } = options; | ||
|
||
let dropElement = await find(dropSelector); | ||
if (!dropElement) { | ||
throw new Error(`There are no drop targets by the given selector: '${dropSelector}'`); | ||
} | ||
|
||
await dragOver(dropSelector, dragOverMoves); | ||
|
||
if (options.beforeDrop) { | ||
await options.beforeDrop.call(); | ||
} | ||
|
||
let event = new MockEvent().useDataTransferData(dragEvent); | ||
await triggerEvent(dropSelector, 'drop', event); | ||
|
||
return await triggerEvent(dragElement, 'dragend', dropEndOptions); | ||
} | ||
|
||
export async function drag(dragSelector, options = {}) { | ||
let dragEvent = new MockEvent(options.dragStartOptions); | ||
const dragElement = document.querySelector(dragSelector); | ||
|
||
await triggerEvent(dragSelector, 'mouseover'); | ||
|
||
await triggerEvent(dragSelector, 'dragstart', dragEvent); | ||
|
||
if (options.afterDrag) { | ||
await options.afterDrag.call(); | ||
} | ||
|
||
if (options.drop) { | ||
await drop(dragElement, dragEvent, options); | ||
} | ||
} | ||
export { default } from 'ember-drag-drop/test-support/helpers/drag-drop'; | ||
export * from 'ember-drag-drop/test-support/helpers/drag-drop'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,2 @@ | ||
class DataTransfer { | ||
constructor() { | ||
this.data = {}; | ||
} | ||
|
||
setData(type, value) { | ||
this.data[type] = value; | ||
return this; | ||
} | ||
|
||
getData(type = "Text") { | ||
return this.data[type]; | ||
} | ||
|
||
setDragImage() { | ||
} | ||
} | ||
|
||
export default class MockEvent { | ||
constructor(options = {}) { | ||
this.dataTransfer = new DataTransfer(); | ||
this.dataTransfer.setData('Text', options.dataTransferData); | ||
this.setProperties(options) | ||
} | ||
|
||
useDataTransferData(otherEvent) { | ||
this.dataTransfer.setData('Text', otherEvent.dataTransfer.getData()); | ||
return this; | ||
} | ||
|
||
setProperties(props) { | ||
for (let prop in props) { | ||
this[prop] = props[prop]; | ||
} | ||
return this; | ||
} | ||
|
||
preventDefault() { | ||
} | ||
|
||
stopPropagation() { | ||
} | ||
} | ||
|
||
export function createDomEvent(type) { | ||
let event = document.createEvent("CustomEvent"); | ||
event.initCustomEvent(type, true, true, null); | ||
event.dataTransfer = new DataTransfer(); | ||
return event; | ||
} | ||
export { default } from 'ember-drag-drop/test-support/helpers/mock-event'; | ||
export * from 'ember-drag-drop/test-support/helpers/mock-event'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { module, test } from 'qunit'; | ||
import * as oldDragDrop from 'dummy/tests/helpers/drag-drop'; | ||
import * as oldDataTransfer from 'dummy/tests/helpers/data-transfer'; | ||
import * as oldMockEvent from 'dummy/tests/helpers/mock-event'; | ||
|
||
import * as newDragDrop from 'ember-drag-drop/test-support/helpers/drag-drop'; | ||
import * as newDataTransfer from 'ember-drag-drop/test-support/helpers/data-transfer'; | ||
import * as newMockEvent from 'ember-drag-drop/test-support/helpers/mock-event'; | ||
|
||
module('test-support exports', function() { | ||
test('helpers/drag-drop', function(assert) { | ||
for (const [key, value] of Object.entries(oldDragDrop)) { | ||
assert.deepEqual(value, newDragDrop[key]); | ||
} | ||
}); | ||
|
||
test('helpers/data-transfer', function(assert) { | ||
for (const [key, value] of Object.entries(oldDataTransfer)) { | ||
assert.deepEqual(value, newDataTransfer[key]); | ||
} | ||
}); | ||
|
||
test('helpers/mock-event', function(assert) { | ||
for (const [key, value] of Object.entries(oldMockEvent)) { | ||
assert.deepEqual(value, newMockEvent[key]); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters