gelgey
21 Apr 2009, 6:30 PM
I want to simulate entering a character into a text field for my unit tests.
I'd like to create a ComponentEvent and call TextField.onComponentEvent(), but the problem I have is that ComponentEvent.getKeyCode() calls DOM.eventGetKeyCode(), and I can't get DOM.eventGetKeyCode() to return a specific key code.
Simply overriding ComponentEvent.getKeyCode() to return the value I specify is not sufficient, since Field.onComponentEvent() will create a FieldEvent that wraps the original ComponentEvent. When FieldEvent.getKeyCode() is called, it will then call DOM.eventGetKeyCode() and not the getKeyCode() method of the wrapped component event.
I can create a FieldEvent and call Field.fireEvent(), but that bypasses some logic that is executed when onComponentEvent() is called.
So ... is there any way to programmatically create a ComponentEvent that will return a specific key code when that event object is passed to DOM.eventGetKeyCode()?
Or is there some other way to simulate typing characters (including control keys) into a TextField?
Or is firing a FieldEvent and bypassing onComponentEvent() the best I can hope for?
I'd like to create a ComponentEvent and call TextField.onComponentEvent(), but the problem I have is that ComponentEvent.getKeyCode() calls DOM.eventGetKeyCode(), and I can't get DOM.eventGetKeyCode() to return a specific key code.
Simply overriding ComponentEvent.getKeyCode() to return the value I specify is not sufficient, since Field.onComponentEvent() will create a FieldEvent that wraps the original ComponentEvent. When FieldEvent.getKeyCode() is called, it will then call DOM.eventGetKeyCode() and not the getKeyCode() method of the wrapped component event.
I can create a FieldEvent and call Field.fireEvent(), but that bypasses some logic that is executed when onComponentEvent() is called.
So ... is there any way to programmatically create a ComponentEvent that will return a specific key code when that event object is passed to DOM.eventGetKeyCode()?
Or is there some other way to simulate typing characters (including control keys) into a TextField?
Or is firing a FieldEvent and bypassing onComponentEvent() the best I can hope for?