Skip to content

Commit fabc12e

Browse files
committed
Fix unit test and typos #8462
1 parent e917de3 commit fabc12e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/dragdrop/ranking-choices.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export class DragDropRankingChoices extends DragDropChoices {
8282
const node = this.domAdapter.draggedElementShortcut.querySelector<HTMLElement>(".sv-ranking-item");
8383
node.style.cursor = "grabbing";
8484
};
85-
public getIndixies(model: any, fromChoicesArray: Array<ItemValue>, toChoicesArray: Array<ItemValue>) {
85+
public getIndices(model: any, fromChoicesArray: Array<ItemValue>, toChoicesArray: Array<ItemValue>) {
8686
let fromIndex = fromChoicesArray.indexOf(this.draggedElement);
8787
let toIndex = toChoicesArray.indexOf(this.dropTarget);
88-
if(fromIndex < 0) {
88+
if(fromIndex < 0 && !!this.draggedElement) {
8989
this.draggedElement = ItemValue.getItemByValue(fromChoicesArray, this.draggedElement.value) || this.draggedElement;
9090
fromIndex = fromChoicesArray.indexOf(this.draggedElement);
9191
}
@@ -103,7 +103,7 @@ export class DragDropRankingChoices extends DragDropChoices {
103103
}
104104

105105
protected afterDragOver(dropTargetNode: HTMLElement): void {
106-
const { fromIndex, toIndex } = this.getIndixies(this.parentElement, this.parentElement.rankingChoices, this.parentElement.rankingChoices);
106+
const { fromIndex, toIndex } = this.getIndices(this.parentElement, this.parentElement.rankingChoices, this.parentElement.rankingChoices);
107107
this.reorderRankedItem(this.parentElement as QuestionRankingModel, fromIndex, toIndex);
108108
}
109109

src/dragdrop/ranking-select-to-rank.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class DragDropRankingSelectToRank extends DragDropRankingChoices {
7878
): void {
7979
const questionModel: any = this.parentElement;
8080

81-
let { fromIndex, toIndex } = this.getIndixies(questionModel, fromChoicesArray, toChoicesArray);
81+
let { fromIndex, toIndex } = this.getIndices(questionModel, fromChoicesArray, toChoicesArray);
8282

8383
rankFunction(questionModel, fromIndex, toIndex, dropTargetNode);
8484
}

tests/dragdrophelpertests.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,56 +318,56 @@ QUnit.test("DragDropRankingSelectToRank reorderRankedItem", function (assert) {
318318
assert.equal(questionModel.rankingChoices.length, 2, "rankingChoices count");
319319
});
320320

321-
QUnit.test("DragDropRankingSelectToRank getIndixies", function (assert) {
321+
QUnit.test("DragDropRankingSelectToRank getIndices", function (assert) {
322322
const withDefaultValue = true;
323323
const dndModel = new DragDropRankingSelectToRank();
324324
const questionModel = createRankingQuestionModel(withDefaultValue);
325-
let toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
325+
let toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
326326
assert.equal(toIndex, 2);
327-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
327+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
328328
assert.equal(toIndex, 2);
329329

330330
dndModel.draggedElement = questionModel.rankingChoices[0];
331331
dndModel.dropTarget = questionModel.rankingChoices[1];
332332
dndModel["_isBottom"] = false;
333-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
333+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
334334
assert.equal(toIndex, 0);
335335

336336
dndModel.draggedElement = questionModel.rankingChoices[0];
337337
dndModel.dropTarget = questionModel.rankingChoices[1];
338338
dndModel["_isBottom"] = true;
339-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
339+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
340340
assert.equal(toIndex, 1);
341341

342342
dndModel.draggedElement = questionModel.rankingChoices[1];
343343
dndModel.dropTarget = questionModel.rankingChoices[0];
344344
dndModel["_isBottom"] = false;
345-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
345+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
346346
assert.equal(toIndex, 0);
347347

348348
dndModel.draggedElement = questionModel.rankingChoices[1];
349349
dndModel.dropTarget = questionModel.rankingChoices[0];
350350
dndModel["_isBottom"] = true;
351-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
351+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
352352
assert.equal(toIndex, 1);
353353

354354
dndModel.dropTarget = questionModel.unRankingChoices[0];
355355
dndModel.draggedElement = questionModel.rankingChoices[1];
356356
dndModel["_isBottom"] = true;
357-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
357+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
358358
assert.equal(toIndex, 1);
359359

360360
dndModel["_isBottom"] = false;
361361
dndModel.dropTarget = questionModel.unRankingChoices[0];
362362
dndModel.draggedElement = questionModel.rankingChoices[1];
363-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
363+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex;
364364
assert.equal(toIndex, 0);
365365

366366
questionModel.value = ["11", "22", "33"];
367367
dndModel.draggedElement = questionModel.rankingChoices[0];
368368
dndModel.dropTarget = questionModel.rankingChoices[1];
369369
dndModel["_isBottom"] = true;
370-
toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
370+
toIndex = dndModel.getIndices(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex;
371371
assert.equal(toIndex, 1);
372372
});
373373
// EO selectToRankEnabled

0 commit comments

Comments
 (0)