forked from ariatemplates/ariatemplates
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ariatemplates#980 Correct MultiAutoComplete initialization when b…
…ound data is not empty When freeText option was set to false, items already present in the data model to which the value of the widget is bound were not taken into account. This commit reverts a fix done for another bug within commit 41d50bf: when freeText is equal to false, type some text for which there is no suggestion. Then blur. Then click inside the field and type something for which suggestions are returned. Pressing ENTER would cause all items to be duplicated.
- Loading branch information
Showing
8 changed files
with
286 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
test/aria/widgets/form/autocomplete/multiautocomplete/BaseMultiAutoCompleteTestCase.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright 2013 Amadeus s.a.s. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
Aria.classDefinition({ | ||
$classpath : "test.aria.widgets.form.autocomplete.multiautocomplete.BaseMultiAutoCompleteTestCase", | ||
$extends : "aria.jsunit.TemplateTestCase", | ||
$dependencies : ["aria.utils.Type"], | ||
$constructor : function () { | ||
this.$TemplateTestCase.constructor.call(this); | ||
|
||
this.data = this.data || { | ||
ac_airline_values : [], | ||
freeText : true | ||
}; | ||
this.setTestEnv({ | ||
template : "test.aria.widgets.form.autocomplete.multiautocomplete.template.MultiAutoTpl", | ||
data : this.data | ||
}); | ||
|
||
}, | ||
$prototype : { | ||
|
||
clickAndType : function (text, cb, delay) { | ||
if (aria.utils.Type.isString(text)) { | ||
text = [text]; | ||
} | ||
this.synEvent.click(this._getField(), { | ||
fn : this.type, | ||
scope : this, | ||
args : { | ||
text : text, | ||
cb : cb, | ||
delay : delay || 800 | ||
} | ||
}); | ||
}, | ||
|
||
type : function (evt, args) { | ||
args = args || evt; | ||
this.synEvent.type(this._getField(), args.text[0], { | ||
fn : this.__wait, | ||
scope : this, | ||
args : args | ||
}); | ||
}, | ||
|
||
__wait : function (evt, args) { | ||
var cb; | ||
args.text.splice(0, 1); | ||
if (args.text.length === 0) { | ||
cb = args.cb; | ||
|
||
} else { | ||
cb = { | ||
fn : this.type, | ||
scope : this, | ||
args : args | ||
}; | ||
} | ||
cb.delay = args.delay; | ||
aria.core.Timer.addCallback(cb); | ||
}, | ||
|
||
checkSelectedItems : function (count, labels) { | ||
var container = this._getContainer(); | ||
var actualOptionCount = container.children.length - 1; | ||
this.assertEquals(actualOptionCount, count, "The number of selected options should be " + count | ||
+ ". It is " + actualOptionCount + " instead."); | ||
|
||
if (labels) { | ||
var element, text; | ||
for (var i = 0; i < labels.length; i++) { | ||
element = container.childNodes[i]; | ||
text = element.innerText || element.textContent; | ||
this.assertEquals(text, labels[i], "The Wrong values are added as for Autocomplete."); | ||
} | ||
} | ||
}, | ||
|
||
checkDataModel : function (count, expectedValues) { | ||
var data = this.data.ac_airline_values, message; | ||
this.assertEquals(data.length, count, "The number of items in the data model is not correct."); | ||
if (expectedValues) { | ||
for (var j = 0; j < data.length; j++) { | ||
var message = "Wrong value in position " + j + " of the data model."; | ||
if (aria.utils.Type.isString(data[j])) { | ||
this.assertEquals(data[j], expectedValues[j], message); | ||
} else { | ||
this.assertEquals(data[j].code, expectedValues[j].code, message); | ||
this.assertEquals(data[j].label, expectedValues[j].label, message); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
focusOut : function (cb) { | ||
this.templateCtxt.$focus("justToFocusOut"); | ||
cb.delay = cb.delay || 10; | ||
aria.core.Timer.addCallback(cb); | ||
}, | ||
|
||
checkInputValue : function (value) { | ||
var actualValue = this._getField().value; | ||
this.assertEquals(actualValue, value, "Input field should have value " + value + ". It has " + actualValue | ||
+ " instead."); | ||
}, | ||
|
||
removeByCrossClick : function (index, cb) { | ||
this.synEvent.click(this._getSelectedItemElement(index).lastChild, cb); | ||
}, | ||
|
||
_getField : function () { | ||
return this.getInputField("MultiAutoId"); | ||
}, | ||
|
||
_getContainer : function () { | ||
return this._getField().parentNode; | ||
}, | ||
|
||
_getSelectedItemElement : function (index) { | ||
return this._getContainer().childNodes[index]; | ||
} | ||
|
||
} | ||
}); |
34 changes: 34 additions & 0 deletions
34
test/aria/widgets/form/autocomplete/multiautocomplete/MultiAutoCompleteTestSuite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2013 Amadeus s.a.s. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
Aria.classDefinition({ | ||
$classpath : "test.aria.widgets.form.autocomplete.multiautocomplete.MultiAutoCompleteTestSuite", | ||
$extends : "aria.jsunit.TestSuite", | ||
$constructor : function () { | ||
this.$TestSuite.constructor.call(this); | ||
|
||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test1.MultiAutoAdd"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test2.MultiAutoRemove"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test3.MultiAutoDataCheck"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test4.MultiAutoPrefill"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test5.MultiAutoEdit"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange1"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange2"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test7.MultiAutoError"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test8.MultiAutoMaxOptions"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test9.MultiAutoBackSpace"); | ||
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.duplicateValuesAfterError.DuplicateValuesAfterError"); | ||
} | ||
}); |
66 changes: 66 additions & 0 deletions
66
...orm/autocomplete/multiautocomplete/duplicateValuesAfterError/DuplicateValuesAfterError.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2013 Amadeus s.a.s. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
Aria.classDefinition({ | ||
$classpath : "test.aria.widgets.form.autocomplete.multiautocomplete.duplicateValuesAfterError.DuplicateValuesAfterError", | ||
$extends : "test.aria.widgets.form.autocomplete.multiautocomplete.BaseMultiAutoCompleteTestCase", | ||
$constructor : function () { | ||
|
||
this.data = { | ||
ac_airline_values : [{ | ||
label : 'Air France', | ||
code : 'AF' | ||
|
||
}, { | ||
label : 'Air Canada', | ||
code : 'AC' | ||
}], | ||
freeText : false | ||
}; | ||
this.$BaseMultiAutoCompleteTestCase.constructor.call(this); | ||
|
||
}, | ||
$prototype : { | ||
|
||
runTemplateTest : function () { | ||
this.checkSelectedItems(2, ["Air France", "Air Canada"]); | ||
|
||
this.clickAndType("o", { | ||
fn : this._afterWrongType, | ||
scope : this | ||
}, 100); | ||
}, | ||
|
||
_afterWrongType : function () { | ||
this.focusOut({ | ||
fn : this._afterFocusOut, | ||
scope : this | ||
}); | ||
}, | ||
|
||
_afterFocusOut : function () { | ||
this.clickAndType(["[right][backspace]P1", "[enter]"], { | ||
fn : this._afterSelectionWithEnter, | ||
scope : this | ||
}, 200); | ||
}, | ||
|
||
_afterSelectionWithEnter : function () { | ||
this.checkSelectedItems(3, ["Air France", "Air Canada", "P1.some"]); | ||
this.end(); | ||
} | ||
|
||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.