Fix spec violations in ee/spec/frontend/related_items_tree/components/tree_root_spec.js
Problem description
The spec file ee/spec/frontend/related_items_tree/components/tree_root_spec.js
contains technical debt and/or antipatterns that need to be fixed. This is a prerequisite for updating our codebase to Vue3
.
Proposal
The following issues have been identified in this spec file:
- overriding method behavior
-
.setData()
usage
Please see the related epic for more details on how these violations can be addressed.
To remove some of the vm
access instances see below
-
getItemId
is only used in another method,getTreeReorderMutation
, which is only used in another method,handleDragOnEnd
, which is triggered by@end="handleDragOnEnd"
-
getItemId
andgetTreeReorderMutation
have tests that reference the method directly onvm
👎 -
getItemId
is a pure function and doesn't reference any values onthis
, so it should be pulled out into a utils method -
getTreeReorderMutation
is also a pure function, but references a prop, but I think this one could also be pulled out into a utils method by modifying the function signature to include the prop (getTreeReorderMutation({ oldIndex, newIndex, targetItem })
=>getTreeReorderMutation({ oldIndex, newIndex, targetItem, children })
-
handleDragOnEnd
needs to be in the mixin, but with the other two methods pulled out into utils and tested there, the existing tests look fine because they usewrapper.findComponent(Draggable).vm.$emit('end', {});
to trigger the method👍
Edited by Alexander Turinske