ng2-dragula icon indicating copy to clipboard operation
ng2-dragula copied to clipboard

don't crash angular when source model is not defined

Open evanjmg opened this issue 7 years ago • 6 comments

When I drag an item between to scroll lists a couple of times and drop it in between them, I get sourceModel is undefined. This workaround fixes the issue. Perhaps this stems from a bigger issue?

evanjmg avatar Aug 07 '18 10:08 evanjmg

Codecov Report

Merging #883 into master will decrease coverage by 0.27%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #883      +/-   ##
==========================================
- Coverage      84%   83.72%   -0.28%     
==========================================
  Files           8        8              
  Lines         300      301       +1     
  Branches       38       39       +1     
==========================================
  Hits          252      252              
  Misses         31       31              
- Partials       17       18       +1
Impacted Files Coverage Δ
...ules/ng2-dragula/src/components/dragula.service.ts 80% <0%> (-0.71%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 808d33c...014eb3c. Read the comment docs.

codecov[bot] avatar Aug 07 '18 10:08 codecov[bot]

Sure, there could be more checks, in which case you wouldn't put them in just one branch of the if.

But are you sure you're not just passing in a null model? Can you provide a minimal repro? There is a test suite for the code that puts models where they are meant to be. Can you write a test that fails?

cormacrelf avatar Aug 07 '18 13:08 cormacrelf

It's pretty hard to write a test that fails since it's a drag between interaction of the columns. I'd have to log out and mock the inputs in the listener. When I have a chance, I'll definitely do that.

evanjmg avatar Aug 07 '18 13:08 evanjmg

Maybe start with a stackblitz (there's a link in the bug report issue template).

If you wanted to test for it, then the existing ones for DragulaService are decent as examples. Right off the bat it might be worth putting a test for 'should do nothing if either model is null' in there!

cormacrelf avatar Aug 07 '18 15:08 cormacrelf

It would be quite similar to this one

https://github.com/valor-software/ng2-dragula/blob/master/modules/ng2-dragula/src/spec/dragula.service.spec.ts#L172-L197

cormacrelf avatar Aug 07 '18 15:08 cormacrelf

I should also be clear that if either model is null, then that's pretty likely to be a bug in your own code, and silently exiting in the lib is just going to make that bug harder to find.

cormacrelf avatar Aug 07 '18 15:08 cormacrelf