Skip to content

Commit bf83483

Browse files
Adding commented tests
1 parent 0dedf6f commit bf83483

File tree

2 files changed

+54
-55
lines changed

2 files changed

+54
-55
lines changed

src/vuedraggable.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ const draggableComponent = defineComponent({
193193

194194
methods: {
195195
getIsFunctional() {
196-
//TODO check this logic
197-
const { fnOptions } = this.mainNode;
198-
return fnOptions && fnOptions.functional;
196+
return typeof this.mainNode.type === "function";
199197
},
200198

201199
updateOptions(newOptionValue) {
@@ -213,20 +211,20 @@ const draggableComponent = defineComponent({
213211
} = this;
214212
if (noneFunctionalComponentMode) {
215213
//TODO check
216-
return this.defaultSlots[0].children;
214+
return defaultSlots[0].children;
217215
//return this.$children[0].$slots.default();
218216
}
219-
//const rawNodes = this.defaultSlots;
217+
220218
if (transitionMode) {
221219
const [{ children }] = defaultSlots;
222220
if (Array.isArray(children)) {
223221
return children;
224222
}
225-
//TODO check transition with tag
226223
return [...this.rootContainer.children]
227224
.map(c => c.__vnode)
228225
.filter(node => !!node.transition);
229226
}
227+
230228
return defaultSlots.length === 1 && defaultSlots[0].el.nodeType === 3
231229
? defaultSlots[0].children
232230
: defaultSlots;

tests/unit/vuedraggable.spec.js

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -318,34 +318,35 @@ describe("draggable.vue when initialized with list", () => {
318318
});
319319
});
320320

321-
// TODO check
322-
// test.each([
323-
// [true, Fake],
324-
// [false, FakeFunctional],
325-
// ])(
326-
// "compute noneFunctionalComponentMode as %p when using component as tag",
327-
// (expectedNoneFunctionalComponentMode, component) => {
328-
// wrapper = mount(draggable, {
329-
// propsData: {
330-
// tag: "child",
331-
// },
332-
// slots: {
333-
// default: () => [],
334-
// },
335-
// global: {
336-
// components: {
337-
// child: component,
338-
// },
339-
// },
340-
// });
341-
// const {
342-
// vm: { noneFunctionalComponentMode },
343-
// } = wrapper;
344-
// expect(noneFunctionalComponentMode).toBe(
345-
// expectedNoneFunctionalComponentMode
346-
// );
347-
// }
348-
// );
321+
describe("when creating a component", () => {
322+
test.each([
323+
["Fake", true, Fake],
324+
["FakeFunctional", false, FakeFunctional]
325+
])(
326+
"when using component with tag %p compute noneFunctionalComponentMode as %p ",
327+
(_, expectedNoneFunctionalComponentMode, component) => {
328+
wrapper = mount(draggable, {
329+
propsData: {
330+
tag: "child"
331+
},
332+
slots: {
333+
default: () => []
334+
},
335+
global: {
336+
components: {
337+
child: component
338+
}
339+
}
340+
});
341+
const {
342+
vm: { noneFunctionalComponentMode }
343+
} = wrapper;
344+
expect(noneFunctionalComponentMode).toBe(
345+
expectedNoneFunctionalComponentMode
346+
);
347+
}
348+
);
349+
});
349350

350351
it("keeps a reference to Sortable instance", () => {
351352
expect(vm._sortable).toBe(SortableFake);
@@ -1098,15 +1099,15 @@ describe("draggable.vue when initialized with a transition group", () => {
10981099
items = ["a", "b", "c"];
10991100
wrapper = mount(draggable, {
11001101
props: {
1101-
modelValue: items,
1102+
modelValue: items
11021103
},
11031104
slots: {
11041105
default() {
11051106
return h("transition-group", {}, [
1106-
...items.map(item => h("div", {key: item}, item))
1107+
...items.map(item => h("div", { key: item }, item))
11071108
]);
1108-
},
1109-
},
1109+
}
1110+
}
11101111
});
11111112
vm = wrapper.vm;
11121113
props = vm.$options.props;
@@ -1148,15 +1149,15 @@ describe("draggable.vue when initialized with a transition group", () => {
11481149
it("sends a start event", async () => {
11491150
await nextTick();
11501151
expect(wrapper.emitted()).toEqual({
1151-
start: [[evt]],
1152+
start: [[evt]]
11521153
});
11531154
});
11541155

11551156
it("sets context", async () => {
11561157
await nextTick();
11571158
expect(vm.context).toEqual({
11581159
element: "b",
1159-
index: 1,
1160+
index: 1
11601161
});
11611162
});
11621163

@@ -1166,7 +1167,7 @@ describe("draggable.vue when initialized with a transition group", () => {
11661167
const remove = getEvent("onRemove");
11671168
remove({
11681169
item,
1169-
oldIndex: 1,
1170+
oldIndex: 1
11701171
});
11711172
});
11721173

@@ -1205,7 +1206,7 @@ describe("draggable.vue when initialized with a transition group", () => {
12051206
item,
12061207
oldIndex: 1,
12071208
newIndex: 0,
1208-
from: transitionRoot,
1209+
from: transitionRoot
12091210
});
12101211
});
12111212

@@ -1226,15 +1227,15 @@ describe("draggable.vue when initialized with a transition group", () => {
12261227
item,
12271228
oldIndex: 1,
12281229
newIndex: 0,
1229-
from: element.children[0],
1230+
from: element.children[0]
12301231
};
12311232
expect(wrapper.emitted().update).toEqual([[expectedEvt]]);
12321233
});
12331234

12341235
it("sends a change event", async () => {
12351236
await nextTick();
12361237
const expectedEvt = {
1237-
moved: { element: "b", oldIndex: 1, newIndex: 0 },
1238+
moved: { element: "b", oldIndex: 1, newIndex: 0 }
12381239
};
12391240
expect(wrapper.emitted().change).toEqual([[expectedEvt]]);
12401241
});
@@ -1251,10 +1252,10 @@ describe("draggable.vue when initialized with a transition group", () => {
12511252
evt = {
12521253
to: element.children[0],
12531254
related: element.children[0].children[1],
1254-
willInsertAfter: false,
1255+
willInsertAfter: false
12551256
};
12561257
originalEvt = {
1257-
domInfo: true,
1258+
domInfo: true
12581259
};
12591260
doMove = () => getEvent("onMove")(evt, originalEvt);
12601261
});
@@ -1264,17 +1265,17 @@ describe("draggable.vue when initialized with a transition group", () => {
12641265
draggedContext: {
12651266
element: "b",
12661267
futureIndex: 1,
1267-
index: 1,
1268+
index: 1
12681269
},
12691270
relatedContext: {
12701271
component: vm,
12711272
element: "b",
12721273
index: 1,
1273-
list: ["a", "b", "c"],
1274+
list: ["a", "b", "c"]
12741275
},
12751276
to: element.children[0],
12761277
related: element.children[0].children[1],
1277-
willInsertAfter: false,
1278+
willInsertAfter: false
12781279
};
12791280
doMove();
12801281
expect(move.mock.calls).toEqual([[expectedEvt, originalEvt]]);
@@ -1285,7 +1286,7 @@ describe("draggable.vue when initialized with a transition group", () => {
12851286
let endEvt;
12861287
beforeEach(() => {
12871288
endEvt = {
1288-
data: "data",
1289+
data: "data"
12891290
};
12901291
const onEnd = getEvent("onEnd");
12911292
onEnd(endEvt);
@@ -1304,17 +1305,17 @@ describe("draggable.vue when initialized with a transition group", () => {
13041305
items = ["a", "b", "c"];
13051306
wrapper = mount(draggable, {
13061307
props: {
1307-
list: items,
1308+
list: items
13081309
},
13091310
attrs: {
13101311
sortableOption: "value",
1311-
"to-be-camelized": true,
1312+
"to-be-camelized": true
13121313
},
13131314
slots: {
1314-
default: () => items.map((item) => h("div", {key: item}, item)),
1315+
default: () => items.map(item => h("div", { key: item }, item)),
13151316
header: () => h("header"),
1316-
footer: () => h("footer"),
1317-
},
1317+
footer: () => h("footer")
1318+
}
13181319
});
13191320
vm = wrapper.vm;
13201321
props = vm.$options.props;

0 commit comments

Comments
 (0)