aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMark Dalgleish2013-03-21 18:07:49 +1100
committerPete Bacon Darwin2013-04-17 21:50:07 +0100
commit3ebc2c2442755aa93a908b0ee9e372c8e6e4a924 (patch)
tree92617220371a5586ad23b02025d0c6de5191ba54 /test
parent631d86f723a27c079784c62d2807650183729cb3 (diff)
downloadangular.js-3ebc2c2442755aa93a908b0ee9e372c8e6e4a924.tar.bz2
fix(ngModel): use paste/cut events in IE to support context menu
In IE the model is not updated when the input value is modified using the context menu, e.g. pasting from the clipboard, or cutting all or part of the current value. To capture these changes, we bind to the proprietary 'paste' and 'cut' events. Closes #1462
Diffstat (limited to 'test')
-rw-r--r--test/ng/directive/inputSpec.js34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js
index 3b511011..3ed03c12 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -297,7 +297,7 @@ describe('ngModel', function() {
describe('input', function() {
- var formElm, inputElm, scope, $compile, changeInputValueTo;
+ var formElm, inputElm, scope, $compile, $sniffer, $browser, changeInputValueTo;
function compileInput(inputHtml) {
inputElm = jqLite(inputHtml);
@@ -306,7 +306,9 @@ describe('input', function() {
$compile(formElm)(scope);
}
- beforeEach(inject(function($injector, $sniffer) {
+ beforeEach(inject(function($injector, _$sniffer_, _$browser_) {
+ $sniffer = _$sniffer_;
+ $browser = _$browser_;
$compile = $injector.get('$compile');
scope = $injector.get('$rootScope');
@@ -373,6 +375,34 @@ describe('input', function() {
expect(scope.name).toEqual('adam');
});
+ describe('"paste" and "cut" events', function() {
+ beforeEach(function() {
+ // Force browser to report a lack of an 'input' event
+ $sniffer.hasEvent = function(eventName) {
+ return eventName !== 'input';
+ };
+ });
+
+ it('should update the model on "paste" event', function() {
+ compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
+
+ inputElm.val('mark');
+ browserTrigger(inputElm, 'paste');
+ $browser.defer.flush();
+ expect(scope.name).toEqual('mark');
+ });
+
+ it('should update the model on "cut" event', function() {
+ compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
+
+ inputElm.val('john');
+ browserTrigger(inputElm, 'cut');
+ $browser.defer.flush();
+ expect(scope.name).toEqual('john');
+ });
+
+ });
+
it('should update the model and trim the value', function() {
compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');