Skip to content

Commit 8e007f0

Browse files
Testing clone mode
1 parent 8a089d6 commit 8e007f0

File tree

1 file changed

+72
-11
lines changed

1 file changed

+72
-11
lines changed

tests/unit/vuedraggable.spec.js

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ describe("draggable.vue when initialized with list", () => {
103103
wrapper = shallowMount(draggable, {
104104
attachToDocument: true,
105105
propsData: {
106-
element: "li"
106+
element: "li"
107107
},
108108
slots: {
109109
default: ""
110110
}
111111
});
112-
expect(console.warn).toBeCalledWith( "Element props is deprecated please use tag props instead. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#element-props");
112+
expect(console.warn).toBeCalledWith("Element props is deprecated please use tag props instead. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#element-props");
113113
});
114114

115115
});
@@ -576,6 +576,70 @@ describe("draggable.vue when initialized with list", () => {
576576
})
577577
});
578578

579+
580+
describe("when initiating a drag operation in clone context", () => {
581+
let evt;
582+
beforeEach(() => {
583+
resetMocks();
584+
wrapper = shallowMount(draggable, {
585+
attachToDocument: true,
586+
propsData: {
587+
list: items
588+
},
589+
attrs: {
590+
group: { pull: "clone" }
591+
},
592+
slots: {
593+
default: items.map(item => `<div>${item}</div>`),
594+
}
595+
});
596+
vm = wrapper.vm;
597+
element = wrapper.element;
598+
item = element.children[1];
599+
evt = { item };
600+
const start = getEvent("onStart");
601+
start(evt);
602+
});
603+
604+
describe("when remove is called", () => {
605+
beforeEach(() => {
606+
var clone = item.cloneNode(true);
607+
wrapper.element.insertBefore(clone, item);
608+
wrapper.element.removeChild(item);
609+
const remove = getEvent("onRemove");
610+
remove({
611+
item,
612+
clone,
613+
oldIndex: 1
614+
});
615+
})
616+
617+
it("DOM changes should be reverted", async () => {
618+
await Vue.nextTick();
619+
expect(wrapper.html()).toEqual(initialRenderRaw);
620+
})
621+
622+
it("list should be not updated", async () => {
623+
await Vue.nextTick();
624+
expect(vm.list).toEqual(["a", "b", "c"]);
625+
})
626+
627+
it("does not send a remove event", async () => {
628+
await Vue.nextTick();
629+
expect(wrapper.emitted().remove).toEqual([[{
630+
item,
631+
clone: item,
632+
oldIndex: 1
633+
}]]);
634+
})
635+
636+
it("does not send a change event", async () => {
637+
await Vue.nextTick();
638+
expect(wrapper.emitted().change).toBeUndefined();
639+
})
640+
})
641+
});
642+
579643
describe("when attribute changes:", () => {
580644
const { error } = console;
581645
beforeEach(() => {
@@ -597,14 +661,11 @@ describe("draggable.vue when initialized with list", () => {
597661
);
598662

599663
test.each(["Start", "Add", "Remove", "Update", "End", "Choose", "Sort", "Filter", "Clone", "Move"])
600-
("do not call option when updating option on%s",
601-
(callBack) =>{
602-
vm.$attrs = { [`on${callBack}`]: jest.fn() };
603-
expect(SortableFake.option).not.toHaveBeenCalled();
604-
});
605-
606-
607-
664+
("do not call option when updating option on%s",
665+
(callBack) => {
666+
vm.$attrs = { [`on${callBack}`]: jest.fn() };
667+
expect(SortableFake.option).not.toHaveBeenCalled();
668+
});
608669
});
609670

610671
test.each([
@@ -630,7 +691,7 @@ describe("draggable.vue when initialized with list", () => {
630691

631692
it("does not throw when sortable is not set", () => {
632693
delete vm._sortable;
633-
expect(() =>wrapper.destroy()).not.toThrow();
694+
expect(() => wrapper.destroy()).not.toThrow();
634695
});
635696
})
636697

0 commit comments

Comments
 (0)