Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for drag & drop #59

Open
chasenlehara opened this issue Dec 16, 2021 · 0 comments
Open

Add tests for drag & drop #59

chasenlehara opened this issue Dec 16, 2021 · 0 comments

Comments

@chasenlehara
Copy link

Currently, there is no test coverage for the code here:

'li dragstart': function (el, evt) {
evt.stopPropagation()
let $el = $(el)
let dt = evt.dataTransfer
dt.effectAllowed = 'move'
dt.setData('text/html', null)
this.viewModel.attr('dragItemIndex', $el.index())
$(this.element).find('element-options-pane').hide()
},
'li dragenter': function (el, evt) {
evt.stopPropagation()
let $el = $(el)
let dropIndex = this.viewModel.attr('dropItemIndex')
// add placeholder class to the dragged element (dropIndex is null) and
// when the element receiving the dragenter event is at a different index
// than the dragged element (dragenter is fired multiple times).
if (dropIndex == null || (dropIndex != null && dropIndex !== $el.index())) {
this.viewModel.setDragPlaceholderFlag()
}
},
'li dragover': function ($el, evt) {
evt.preventDefault()
let dt = evt.dataTransfer
dt.dropEffect = 'move'
},
// this event won't be dispatched if the source node is moved during the
// drag, causing the placeholder to stay visible after the elemet has been
// dropped.
'li dragend': function () {
this.viewModel.removeDragPlaceholderFlag()
this.viewModel.attr({
dragItemIndex: null,
dropItemIndex: null
})
},
'li drop': function (el, evt) {
evt.stopPropagation()
this.viewModel.removeDragPlaceholderFlag()
let $el = $(el)
this.viewModel.attr('dropItemIndex', $el.index())
this.viewModel.attr({
dragItemIndex: null,
dropItemIndex: null
})
},
// to workaround the issue with the `dragend` event not being dispatched,
// we have to make the document a valid drop target, in order to do that
// we need to set listeners for `dragstart` and `dragover` events.
'{document} dragstart': function () {},
'{document} dragover': function ($el, evt) {
evt.preventDefault()
this.viewModel.removeDragPlaceholderFlag()
},
// if a template is not being droppped within the boundaries of one the
// items, we need to make sure the placeholder class is removed anyways,
// the dragged item will remain at its last valid position.
'{document} drop': function ($el, evt) {
evt.preventDefault()
this.viewModel.removeDragPlaceholderFlag()
},

We should be able to use FuncUnit’s drag method or Syn, which is what FuncUnit uses under the hood and provides many more options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant