-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
tests: improve drag-and-drop coverage #9314
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great thanks so much for taking this up @Remexllee!
@@ -17,8 +15,12 @@ testHelpers.setupJsDomGlobals(); | |||
|
|||
const DragAndDrop = require('../app/src/drag-and-drop.js'); | |||
|
|||
function assertUIReset() { | |||
assert.ok(!document.querySelector('.drop_zone').classList.contains('dropping')); | |||
function createCustomEvent(type, key, value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: WDYT about the caller passing {key: value}
to make it a little clearer below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean add a comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's ignore this comment in favor of #9314 (comment)
expect(mockCallback).toBeCalledWith('mock file'); | ||
}); | ||
|
||
it('document responds to drop event without file', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('document responds to drop event without file', () => { | |
it('document ignores drop event without file', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix it. thanks for suggestion.
assert.ok(!document.querySelector('.drop_zone').classList.contains('dropping')); | ||
function createCustomEvent(type, key, value) { | ||
const customDropEvent = new window.CustomEvent(type); | ||
if (key && value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now it's a bit odd that the callers do createCustomEvent('drag', 'dataTransfer', null)
when it seems like that doesn't really do anything, is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing this fn entirely would be better.
// create custom drop event with mock files in dataTransfer
const event = new CustomEvent('drop');
event.dataTransfer = {
files: ['mock file'],
};
document.dispatchEvent(event);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah ignore what I was saying, let's go with @connorjclark !
// eslint-disable-next-line no-unused-vars | ||
const dragAndDrop = new DragAndDrop(); | ||
it('document responds to mouseleave event when not dragging', () => { | ||
new DragAndDrop(jest.fn); | ||
|
||
document.dispatchEvent(new window.CustomEvent('mouseleave')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we align on createCustomEvent
while we're at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, I will made the change align it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up with #9314 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
I fixed the unit test in drag-and-drop-test.js file
This is a refactoring of unit test
Related Issues/PRs