-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 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,96 @@ | ||
import test from '../../test'; | ||
import * as utils from '../../../src/utils'; | ||
import DropEvent from '../../../src/actions/drop/DropEvent'; | ||
|
||
const dz1 = { target: 'dz1', fire (event) { this.fired = event; } }; | ||
const dz2 = { target: 'dz2', fire (event) { this.fired = event; } }; | ||
const el1 = Symbol('el1'); | ||
const el2 = Symbol('el2'); | ||
const interactable = Symbol('interactable'); | ||
const dragElement = Symbol('drag-el'); | ||
|
||
test('DropEvent constructor', t => { | ||
const interaction = { dropStatus: {} }; | ||
const dragEvent = Object.freeze({ interaction, interactable, target: dragElement, timeStamp: 10 }); | ||
|
||
utils.extend(interaction.dropStatus, { | ||
activeDrops: [ | ||
{ dropzone: dz1, element: el1 }, | ||
{ dropzone: dz2, element: el2 }, | ||
], | ||
cur : { dropzone: dz1, element: el1 }, | ||
prev: { dropzone: dz2, element: el2 }, | ||
events: {}, | ||
}); | ||
|
||
const dropmove = new DropEvent(interaction.dropStatus, dragEvent, 'dropmove'); | ||
|
||
t.equal(dropmove.target, el1, 'dropmove uses dropStatus.cur.element'); | ||
t.equal(dropmove.dropzone, dz1, 'dropmove uses dropStatus.cur.dropzone'); | ||
t.equal(dropmove.relatedTarget, dragElement); | ||
|
||
const dragleave = new DropEvent(interaction.dropStatus, dragEvent, 'dragleave'); | ||
|
||
t.equal(dragleave.target, el2, 'dropmove uses dropStatus.prev.element'); | ||
t.equal(dragleave.dropzone, dz2, 'dropmove uses dropStatus.prev.dropzone'); | ||
t.equal(dragleave.relatedTarget, dragElement); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('DropEvent.reject()', t => { | ||
const interaction = { dropStatus: {} }; | ||
const dragEvent = Object.freeze({ interaction, interactable, target: dragElement, timeStamp: 10 }); | ||
|
||
utils.extend(interaction.dropStatus, { | ||
activeDrops: [ | ||
{ dropzone: dz1, element: el1 }, | ||
{ dropzone: dz2, element: el2 }, | ||
], | ||
cur : { dropzone: null, element: null }, | ||
prev: { dropzone: null, element: null }, | ||
events: {}, | ||
}); | ||
|
||
const dropactivate = new DropEvent(interaction.dropStatus, dragEvent, 'dropactivate'); | ||
|
||
dropactivate.dropzone = dz1; | ||
dropactivate.target = el1; | ||
dropactivate.reject(); | ||
|
||
t.ok(dropactivate.propagationStopped && dropactivate.immediatePropagationStopped, | ||
'rejected event propagation is stopped'); | ||
|
||
t.equal(dz1.fired.type, 'dropdeactivate', 'dropdeactivate is fired on rejected dropzone'); | ||
|
||
t.deepEqual( | ||
interaction.dropStatus.activeDrops, | ||
[{ dropzone: dz2, element: el2 }], | ||
'activeDrop of rejected dropactivate event is removed'); | ||
|
||
t.deepEqual( | ||
interaction.dropStatus.cur, | ||
{ dropzone: null, element: null }, | ||
'dropStatus.cur dropzone and element are set to null after rejecting dropactivate'); | ||
|
||
utils.extend(interaction.dropStatus, { | ||
cur : { dropzone: dz1, element: el1 }, | ||
prev: { dropzone: null, element: null }, | ||
events: {}, | ||
}); | ||
|
||
const dropmove = new DropEvent(interaction.dropStatus, dragEvent, 'dropmove'); | ||
|
||
dropmove.reject(); | ||
|
||
t.deepEqual( | ||
interaction.dropStatus.cur, | ||
{ dropzone: dz1, element: el1 }, | ||
'dropStatus.cur remains the same after rejecting non activate event'); | ||
|
||
t.ok(interaction.dropStatus.rejected, 'dropStatus.rejected === true'); | ||
|
||
t.equal(dz1.fired.type, 'dragleave', 'dragleave is fired on rejected dropzone'); | ||
|
||
t.end(); | ||
}); |