Skip to content

Commit 9c30fc0

Browse files
committed
adding more tests for the igCombo
for model binding and changes from 99d6538
1 parent 0bd90dc commit 9c30fc0

File tree

4 files changed

+114
-3
lines changed

4 files changed

+114
-3
lines changed

test/app/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ <h1>igCombo</h1>
9191
<input type="text" ng-model="combo.value1"/>
9292
<ig-combo id="combo1" allow-custom-value="true" data-source="northwind" value-key-type="number" value-key="ProductID" text-key-type="string" text-Key="ProductName" ng-model="combo.value1">
9393
</ig-combo>
94-
<ig-combo id="combo2" data-source="northwind" value-key-type="number" value-key="ProductID" text-key-type="string" text-Key="ProductName" ng-model="combo.value1">
94+
<ig-combo id="combo2" data-source="northwind" value-key-type="number" value-key="ProductID" text-key-type="string" text-Key="ProductName" ng-model="combo.value2">
95+
<multi-selection enabled="true"></multi-selection>
9596
</ig-combo>
9697
<br/>
9798
<ul id="combomodel">
@@ -162,6 +163,7 @@ <h1>igEditors</h1>
162163
<script type="text/javascript" src="//cdn-na.infragistics.com/igniteui/latest/js/modules/infragistics.ui.combo.js"></script>
163164
<script type="text/javascript" src="//cdn-na.infragistics.com/igniteui/latest/js/modules/infragistics.ui.validator.js"></script>
164165
<script type="text/javascript" src="../../src/igniteui-angular.js"></script>
166+
<script type="text/javascript" src="js/my-app-utils.js"></script>
165167
<script type="text/javascript" src="js/my-app.js"></script>
166168
</body>
167169
</html>

test/app/js/my-app-utils.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
function testEventListener(widget, elementId, event) {
2+
return $("#" + elementId).data(widget).options[event] != undefined;
3+
}
4+
5+
function typeInInput(characters, element, callback) {
6+
var keyDown = jQuery.Event("keydown"),
7+
keyPress = jQuery.Event("keypress"),
8+
keyUp = jQuery.Event("keyup"),
9+
value = "";
10+
11+
characters.split('').forEach(function (ch) {
12+
keyDown.keyCode = keyUp.keyCode = keyPress.keyCode = ch.charCodeAt(0);
13+
keyDown.charCode = keyUp.charCode = keyPress.charCode = ch.charCodeAt(0);
14+
element.trigger(keyDown);
15+
element.trigger(keyPress);
16+
value = value + ch;
17+
element.val(value);
18+
element.trigger(keyUp);
19+
element.trigger("input"); // also throw input for Angular, ngModel only listens for that when supported
20+
if (callback) {
21+
callback();
22+
}
23+
});
24+
}
25+
26+
function typeInInputWrap(characters, element, scopeEval) {
27+
var editUpdateFlag = false,
28+
scope = element.scope(),
29+
originalValue = scope.$eval(scopeEval);
30+
typeInInput(characters, element, function () {
31+
//check scope value remains unchanged during search entry
32+
if (scope.$eval(scopeEval) != originalValue) {
33+
editUpdateFlag = true;
34+
}
35+
});
36+
return editUpdateFlag;
37+
}
38+
39+
function keyInteraction(key, target, special) {
40+
keyDownChar(key, target, special);
41+
keyPressChar(key, target, special);
42+
keyUpChar(key, target, special);
43+
}
44+
function keyDownChar(key, target, special) {
45+
var evt = $.Event("keydown");
46+
evt.keyCode = key;
47+
evt.charCode = key;
48+
if (special) {
49+
evt[special] = true;
50+
}
51+
target.trigger(evt);
52+
}
53+
function keyPressChar(key, target, special) {
54+
var evt = $.Event("keypress");
55+
evt.keyCode = key;
56+
evt.charCode = key;
57+
if (special) {
58+
evt[special] = true;
59+
}
60+
target.trigger(evt);
61+
}
62+
function keyUpChar(key, target, special) {
63+
var evt = $.Event("keyup");
64+
evt.keyCode = key;
65+
evt.charCode = key;
66+
if (special) {
67+
evt[special] = true;
68+
}
69+
target.trigger(evt);
70+
}

test/app/js/my-app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ var NorthwindCtrl = function ($scope, $element, $compile) {
12561256
};
12571257
$scope.combo = {
12581258
value1: 20,
1259-
value2: "Chang"
1259+
value2: []
12601260
};
12611261
$scope.deleteDo = function (ix) {
12621262
$scope.dataObject.splice(ix, 1);

test/e2e/scenarios.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,54 @@ describe('my app', function() {
559559
});
560560

561561
describe("Combo", function() {
562+
var scope = 'angular.element("#combo1").scope()',
563+
combo = '$("#combo1")',
564+
combo2 = '$("#combo2")';
565+
562566
it("should be initialized", function () {
563567
util.resetNorthwindScope();
564568
util.isInitialized('combo1', 'igCombo');
565569
util.isInitialized('combo2', 'igCombo');
566570
});
567571

568-
it("should update its view when model is changed", function() {
572+
it("should be initialized with a value from the scope", function() {
573+
expect(util.getResult(combo + '.igCombo("value")')).toBe(20);
574+
expect(util.getResult(combo2 + '.igCombo("value").length')).toBe(0);
575+
});
576+
577+
it("should update its value when model is changed", function() {
578+
util.executeScript(scope + '.combo.value1 = 2;');
579+
util.executeScript(scope + '.$apply();');
580+
expect(util.getResult(combo + '.igCombo("value")')).toBe(2);
581+
expect(util.getResult('$("#combo1").val()')).toBe("Chang");
569582
util.executeScript('$("input[ng-model=\'combo.value1\']:eq(0)").val("5").trigger("input");');
570583
expect(util.getResult('$("#combo1").val()')).toBe("Chef Anton's Gumbo Mix");
584+
585+
util.executeScript(scope + '.combo.value2 = [1];');
586+
util.executeScript(scope + '.$apply();');
587+
expect(util.getResult(combo2 + '.igCombo("value")[0]')).toBe(1);
588+
expect(util.getResult('$("#combo2").val()')).toBe('Chai');
589+
});
590+
591+
it("should set model on clear", function() {
592+
util.executeScript(combo2 + ".igCombo('comboWrapper').find('.ui-igcombo-clear').click();");
593+
expect(util.getResult(scope + '.combo.value2.length')).toBe(0);
594+
});
595+
596+
it("should update model on change with multi selection", function() {
597+
util.executeScript(combo2 + ".igCombo('comboWrapper').find('.ui-igcombo-button').click();");
598+
util.executeScript(combo2 + ".igCombo('dropDown').find('li').not('.ui-helper-hidden').eq(0).trigger($.Event('mousedown', { which: 1 })).trigger($.Event('mouseup', { which: 1 }));");
599+
util.executeScript(combo2 + ".igCombo('dropDown').find('li').not('.ui-helper-hidden').eq(1).trigger($.Event('mousedown', { which: 1 })).trigger($.Event('mouseup', { which: 1 }));");
600+
expect(util.getResult(scope + '.combo.value2.toString()')).toBe('1,2');
601+
});
602+
603+
it("should update model on change of combo input", function() {
604+
util.executeScript(combo + ".focus();");
605+
//check scope value remains unchanged during search entry
606+
expect(util.getResult('typeInInputWrap("Chang", ' + combo + ', "combo.value1");')).toBe(false);
607+
// wait for sleep resolve:
608+
expect(browser.driver.sleep(250)).toBe(undefined); //util.getResult(combo + '.igCombo("option", "delayInputChangeProcessing");')
609+
expect(util.getResult(scope + '.combo.value1')).toBe(2);
571610
});
572611
});
573612

0 commit comments

Comments
 (0)