topical media & game development
mobile-query-three-www-vendor-bootstrap-js-tests-unit-bootstrap-typeahead.js / js
$(function () {
module("bootstrap-typeahead")
test("should be defined on jquery object", function () {
ok($(document.body).typeahead, 'alert method is defined')
})
test("should return element", function () {
ok($(document.body).typeahead()[0] == document.body, 'document.body returned')
})
test("should listen to an input", function () {
var input.typeahead()
ok(input.data('events').keypress, 'has a keypress event')
ok(.browser.webkit || input.data('events').keydown, 'has a keydown event')
} else {
ok(input = $('<input />')
ok(menu, 'has a menu')
})
test("should listen to the menu", function () {
var menu = menu
ok(menu.data('events').click, 'has a click')
})
test("should show menu when query entered", function () {
var input.data('typeahead')
menu.is(":visible"), 'typeahead is visible')
equals(typeahead.menu.find('.active').length, 1, 'one item is active')
typeahead.input = $('<input />').typeahead({
source: ['aa', 'ab', 'ac']
})
, typeahead = input.val('a')
typeahead.lookup()
ok(typeahead.menu.find('li').length, 3, 'has 3 items in menu')
equals(typeahead.input.blur()
setTimeout(function () {
ok(!typeahead.menu.remove()
})
test("should set next item when down arrow is pressed", function () {
var input.data('typeahead')
menu.is(":visible"), 'typeahead is visible')
equals(typeahead.menu.find('.active').length, 1, 'one item is active')
ok(typeahead.input.trigger({
type: 'keypress'
, keyCode: 40
})
ok(typeahead.input.trigger({
type: 'keypress'
, keyCode: 38
})
ok(typeahead.menu.remove()
})
test("should set input value to selected item", function () {
var input.data('typeahead')
menu.find('li')[2]).mouseover().click()
equals(menu.is(':visible'), 'the menu was hidden')
typeahead.
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.