Improved error handling.

This commit is contained in:
Martin Edenhofer 2014-12-03 13:45:59 +01:00
parent 776e60f3a2
commit 72e2a73f63
2 changed files with 58 additions and 7 deletions

View file

@ -95,6 +95,7 @@
} }
}, this )) }, this ))
// reduce buffer, in case close it
this.$element.on('keydown', $.proxy(function (e) { this.$element.on('keydown', $.proxy(function (e) {
// backspace // backspace
@ -109,8 +110,8 @@
} }
}, this )) }, this ))
// build buffer
this.$element.on('keypress', $.proxy(function (e) { this.$element.on('keypress', $.proxy(function (e) {
var value = this.$element.text()
console.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which) ) console.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which) )
a = $.proxy(function() { a = $.proxy(function() {
@ -119,6 +120,16 @@
return return
} }
// enter
if ( e.keyCode === 13 ) {
return
}
// arrow keys
if ( e.keyCode === 37 || e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 40 ) {
return
}
// enter : // enter :
if ( String.fromCharCode(e.which) === ':' ) { if ( String.fromCharCode(e.which) === ':' ) {
this.buffer = this.buffer + ':' this.buffer = this.buffer + ':'
@ -234,7 +245,13 @@
} }
var range = sel.getRangeAt(0) var range = sel.getRangeAt(0)
var clone = range.cloneRange() var clone = range.cloneRange()
clone.setStart(range.startContainer, range.startOffset - this.buffer.length)
// improve error handling
start = range.startOffset - this.buffer.length
if (start < 0) {
start = 0
}
clone.setStart(range.startContainer, start)
clone.setEnd(range.startContainer, range.startOffset) clone.setEnd(range.startContainer, range.startOffset)
clone.deleteContents() clone.deleteContents()
this.buffer = '' this.buffer = ''

View file

@ -121,8 +121,9 @@ class AgentTicketActionLevel5Test < TestCase
:css => 'a[href="#ticket/create"]', :css => 'a[href="#ticket/create"]',
}, },
{ {
:execute => 'wait', :execute => 'watch_for',
:value => 2, :area => '.active [data-name="body"]',
:value => '',
}, },
{ {
:execute => 'set', :execute => 'set',
@ -138,6 +139,10 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:execute => 'wait',
:value => 1,
},
{ {
:execute => 'click', :execute => 'click',
:css => '.active .shortcut > ul> li > a', :css => '.active .shortcut > ul> li > a',
@ -301,6 +306,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 3,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',
@ -337,6 +347,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',
@ -363,6 +378,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 10,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',
@ -447,6 +467,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',
@ -503,6 +528,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',
@ -519,9 +549,8 @@ class AgentTicketActionLevel5Test < TestCase
:css => '.modal-content .js-submit', :css => '.modal-content .js-submit',
}, },
{ {
:where => :instance2, :execute => 'watch_for_disappear',
:execute => 'wait', :area => '.modal',
:value => 4,
}, },
{ {
:where => :instance2, :where => :instance2,
@ -545,6 +574,11 @@ class AgentTicketActionLevel5Test < TestCase
:execute => 'sendkey', :execute => 'sendkey',
:value => [:arrow_down] :value => [:arrow_down]
}, },
{
:where => :instance2,
:execute => 'wait',
:value => 1,
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'click', :execute => 'click',