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

Do you have a sample test ? #29

Closed
tarjei opened this issue Jan 1, 2015 · 17 comments
Closed

Do you have a sample test ? #29

tarjei opened this issue Jan 1, 2015 · 17 comments

Comments

@tarjei
Copy link

tarjei commented Jan 1, 2015

Hi, do you have a sample code for testing a drag and drop interaction?

@mukeshsoni
Copy link

It's in the examples folder in the repo. And the README has link to live demo for the same code.

@tarjei
Copy link
Author

tarjei commented Jan 4, 2015

AFAIK the examples folder only contains demos - not tests. I'm looking for code to use for writing my own tests testing the dnd interactions.

@gaearon
Copy link
Member

gaearon commented Jan 4, 2015

Ah, I get it now. No, this project has no tests. We use it extensively in production though.

If you find a meaningful way to test it (a lot of its logic has to do with browser differences, for example), please let me know!

@tarjei
Copy link
Author

tarjei commented Jan 4, 2015

I'm mainly looking for ways to simulate drag and drop, but I'll let you
know. Thanks for a nice library!

2015-01-04 14:49 GMT+01:00 Dan Abramov notifications@github.com:

Ah, I get it now. No, this project has no tests. We use it extensively in
production though.

If you find a meaningful way to test it (a lot of its logic has to do with
browser differences, for example), please let me know!


Reply to this email directly or view it on GitHub
#29 (comment).


Tarjei Huse
Mobil: 920 63 413

@gaearon
Copy link
Member

gaearon commented Jan 4, 2015

I'm just not familiar with React testing infrastructure. If it allows simulating dragstart / dragover / dragend you'll be fine. If not, maybe you can suggest some way in which I can add test helpers. I'm just not sure what kind of API is needed there.

@stefvhuynh
Copy link

I would also be interested in this. But at an even more basic level, how would you propose writing a simple unit test for a component that uses the DragDropMixin?

This is a fantastic library, by the way. I'm using it for some production code, but I'm required to write some unit tests for code using it.

@gaearon
Copy link
Member

gaearon commented Jan 6, 2015

Thanks!

We can probably go two routes here:

  1. Simulate "logical" states in library
  2. Simulate actual DOM events on some window and have library catch it

Which is closer to what you'd like to test? Do you run your tests in a browser or in some fake DOM env?

(Disclaimer: I never wrote tests for UI in my life and know very little about it.)

@stefvhuynh
Copy link

I'm using jest by facebook right now and i believe jest tests run in a virtual DOM.

@gaearon
Copy link
Member

gaearon commented Jan 6, 2015

Can you share a minimal Jest example for the kind of thing you'd like to test?
Just something I can get running to see what I can do.

@stefvhuynh
Copy link

i think it would be great if there's some way to determine whether a component is being dragged, dropped, etc. so, if a test could do something like

/* 
 * Code to simulate mouseDown, mouseMove on someComponentInstance
 */
expect(ReactDnD.getDragState(someComponentInstance)).toBeTrue();

I'm not sure if this is a great example, as I am really new to UI testing, myself.

@stefvhuynh
Copy link

So, using Jest, I was able to test drag and drop functionality with this function. I used React's TestUtils and simulated dragstart and drop events. Some code in the configDataTransfer file required some attributes on the event that were not provided by jest, so those necessary properties are included. Do you have suggesting for what kind of mock data should be included in the dataTransfer object?

simulateDragAndDrop: function(dragComponent, dropComponent) {
    TestUtils.Simulate.dragStart(
        dragComponent,
        { nativeEvent: { dataTransfer: {} } }
    );

    TestUtils.Simulate.drop(
        dropComponent,
        { dataTransfer: { types: [] } }
    );
}

@gaearon
Copy link
Member

gaearon commented Jan 15, 2015

Hmm.. I think you should just add whatever stuff necessary to make it work and see :-)
Anything you want to test in particular that this approach doesn't give you yet?

@stefvhuynh
Copy link

not at the moment. i will get back to you if something comes up or if i come up with a better solution.

@gaearon
Copy link
Member

gaearon commented Feb 8, 2015

Closing, as it's not really an issue. We will try to make the testing story better after v1.0 with #55.

@gaearon gaearon closed this as completed Feb 8, 2015
@gaearon
Copy link
Member

gaearon commented May 19, 2015

Testing is now supported, even without the browser: http://gaearon.github.io/react-dnd/docs-testing.html

@tarjei
Copy link
Author

tarjei commented May 19, 2015

Great work - and a brilliant component!

Thanks!

2015-05-19 14:11 GMT+02:00 Dan Abramov notifications@github.com:

Testing is now supported, even without the browser:
http://gaearon.github.io/react-dnd/docs-testing.html


Reply to this email directly or view it on GitHub
#29 (comment).


Tarjei Huse
Mobil: 920 63 413

@stefvhuynh
Copy link

looks great!

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

No branches or pull requests

4 participants