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

tests: improve drag-and-drop coverage #9314

Merged
merged 6 commits into from
Jul 8, 2019

Conversation

Remexllee
Copy link
Contributor

Summary

I fixed the unit test in drag-and-drop-test.js file

This is a refactoring of unit test

Related Issues/PRs

@Remexllee Remexllee changed the title Fixed and added unit test in lighthouse-viewer's drag-and-drop-test.js feat('fix-add-test-case-viewer'): fixed and add test cases in lighthouse-viewer's drag-and-drop-test.js Jun 30, 2019
@Remexllee Remexllee changed the title feat('fix-add-test-case-viewer'): fixed and add test cases in lighthouse-viewer's drag-and-drop-test.js feat('fix-unit-test'): fixed and add test cases in lighthouse-viewer's drag-and-drop-test.js Jun 30, 2019
@Remexllee Remexllee changed the title feat('fix-unit-test'): fixed and add test cases in lighthouse-viewer's drag-and-drop-test.js feat('fix-test): fixed test case in drag-and-drop-test.js file Jun 30, 2019
@Remexllee Remexllee changed the title feat('fix-test): fixed test case in drag-and-drop-test.js file tests('fix-test): fixed test case in drag-and-drop-test.js file Jun 30, 2019
@patrickhulce patrickhulce changed the title tests('fix-test): fixed test case in drag-and-drop-test.js file tests: improved drag-and-drop coverage Jul 1, 2019
@patrickhulce patrickhulce changed the title tests: improved drag-and-drop coverage tests: improve drag-and-drop coverage Jul 1, 2019
Copy link
Collaborator

@patrickhulce patrickhulce left a 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) {
Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

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', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('document responds to drop event without file', () => {
it('document ignores drop event without file', () => {

Copy link
Contributor Author

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) {
Copy link
Collaborator

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?

Copy link
Collaborator

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);

Copy link
Collaborator

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'));
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

@vercel vercel bot temporarily deployed to staging July 2, 2019 02:02 Inactive
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

4 participants