Functional tests are used to mimic user events.
new MVC.Test.Functional(name, tests) -> Test
Creates a new functional test case. A test case is a collection of test functions and helpers.
new MVC.Test.Functional('TestCaseName',{
test_some_clicks : function(){
this.Click('#button')
}
})
Action(event_type, selector_or_element, eventoptions_or_number)
Creates a syntetic event on a HTMLElement.
this.Action('click','.todo',3) //calls a click on the third element with class '.todo'
Change(selector_or_element, options_or_number)
Calls Action using 'change' as the first parameter.
Click(selector_or_element, options_or_number)
Calls Action using 'click' as the first parameter.
Contextmenu(selector_or_element, options_or_number)
Calls Action using 'contextmenu' as the first parameter.
Dblclick(selector_or_element, options_or_number)
Calls Action using 'dblclick' as the first parameter.
Drag(selector_or_element, options)
Creates events that simulate a drag motion across the browser. The drag events are comprised of a mousedown from the from location, equal spaced mousemoves to the to location, and a mouseup at the to location. Drag is by default syncronous, but can be made asyncronous by providing a duration option.
test_drag_to_trash : function(){
this.Drag('#/drag_handle',
{
from: '/drag_handle',
to: '/trash',
duration: 2,
callback: this.next_callback()
})
},
make_sure_drag_worked : function(){
this.assertNull(document.getElementById('/drag_handle'));
}
| Option | Default | Description |
|---|---|---|
| callback | null | A callback that gets called when the drag motion has completed. This is only necessary with asyncronous drags. Typically, the callback can be provided by next_callback(); |
| duration | null | The length of time in seconds the drag takes place. By setting this option, the events are dispatched in intervals, letting the browser update the screen. Typically, you want to provide a callback to test the results of the drag after completion. |
| from | null | The starting coordinates of the drag. This can be specified in three ways: first, as an object like {x: 123, y: 321}; second, as a HTMLElement; third, as the string ID of a HTMLElement. Providing an element or the id of an element, Drag will use the center of the element as is starting position. |
| steps | 100 | The number of mousemoves called to represent the drag. This parameter is void if duration is provided. |
| to | null | The ending coordinates of the drag. Use the to option the same way as the from option. |
Keyup(selector_or_element, options_or_number)
Calls Action using 'keyup' as the first parameter.
Keydown(selector_or_element, options_or_number)
Calls Action using 'keydown' as the first parameter.
Keypress(selector_or_element, character, options_or_number)
Calls Action using 'keypress' as the first parameter. In browsers other that Firefox, keypress support built into the browser doesn't actually write text into the input element. To make up for this shortcoming, this method manually inserts text into the input element's value attribute.
| Option | Default | Description |
|---|---|---|
| character | false | True to simulate pressing the alt key. |
| ctrlKey | false | True to simulate pressing the control key. |
| altKey | false | True to simulate pressing the alt key. |
| shiftKey | false | True to simulate pressing the shift key. |
| metaKey | false | True to simulate pressing the meta key. |
| keyCode | 0 | Used to simulate pressing other keys, this reference shows a list of keyCodes you can use. |
Mousedown(selector_or_element, options_or_number)
Calls Action using 'mousedown' as the first parameter.
Mousemove(selector_or_element, options_or_number)
Calls Action using 'mousemove' as the first parameter.
Mouseout(selector_or_element, options_or_number)
Calls Action using 'mouseout' as the first parameter.
Mouseover(selector_or_element, options_or_number)
Calls Action using 'mouseover' as the first parameter.
Mouseup(selector_or_element, options_or_number)
Calls Action using 'mouseup' as the first parameter.
Select(selector_or_element, options_or_number)
Calls Action using 'select' as the first parameter.
Submit(selector_or_element, options_or_number)
Calls Action using 'submit' as the first parameter.
Write(selector_or_element, options_or_string)
Creates events that simulate writing into an input element. If a callback option is used in the second parameter, the event is asynchronous. Otherwise, it is synchronous.
// syntax 1: synchronous version
this.Write(input_params.element, 'Brian');
// syntax 2: asynchronous version
this.Write(input_params.element, {text: 'Brian', callback: this.next_callback()});
If a string is passed, it is the text written in the passed input element.
| Option | Default | Description |
|---|---|---|
| callback | null | A callback that gets called when the write has completed. This is only necessary with asyncronous writes. Typically, the callback can be provided by next_callback(); |
| duration | null | The length of time in seconds the write takes place. By setting this option, the events are dispatched in intervals, letting the browser update the screen. Typically, you want to provide a callback to test the results of the drag after completion. |
| text | null |
The text to be written into the given input element.
'\b' - the backspace character is used to delete one character of text '\n' - the newline character is used to simulate pressing enter |