From 02afd8a32edb13ea7fc2266ac80092ea15c0930c Mon Sep 17 00:00:00 2001 From: Alvin Li Date: Wed, 9 Oct 2013 15:52:53 +0800 Subject: * treat 'apps/utils' as regular django app; which used to store general tools for used in other apps * moved 'templatetags' from 'apps/indicator' to 'apps/utils' * '.gitignore' to ignore 'fixtures_bak' * moved js plugins from 'apps/indicator/static/plugins' to 'staticfiles/plugins' apps/recommend: * updated 'recommend.models'; o commented 'recommend.models.ResearchCombination' (not used) * implemented views 'add_edit_blog_info' and 'ajax_add_edit_configs'; * added pages 'templates/recommend/add_edit_blog_info.html', 'add_edit_blog_info_error.html'; o related css and javascripts files * added 'tools.py'; * added 'utils/tools.py' for placing generic functions; * deleted 'initial_data.json' (mv 'fixtures' to 'fixtures_bak'); * small fixes to 'indicator.models', 'sciblog.models' and 'sfaccount.views' * fixed automatically show 'proper_nouns' annotation in blog: recovered the line 'import signals' in 'sciblog.models' * added 'is_ok()' method for 'recommend.models.ResearchConfig'; --- .../jquery-ui/tests/unit/autocomplete/all.html | 30 +++ .../tests/unit/autocomplete/autocomplete.html | 49 ++++ .../tests/unit/autocomplete/autocomplete_common.js | 29 +++ .../tests/unit/autocomplete/autocomplete_core.js | 242 +++++++++++++++++++ .../tests/unit/autocomplete/autocomplete_events.js | 182 ++++++++++++++ .../unit/autocomplete/autocomplete_methods.js | 45 ++++ .../unit/autocomplete/autocomplete_options.js | 264 +++++++++++++++++++++ .../autocomplete/remote_object_array_labels.txt | 1 + .../autocomplete/remote_object_array_values.txt | 1 + .../unit/autocomplete/remote_string_array.txt | 1 + 10 files changed, 844 insertions(+) create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/all.html create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete.html create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_common.js create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_core.js create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_events.js create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_methods.js create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_options.js create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_labels.txt create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_values.txt create mode 100644 97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_string_array.txt (limited to '97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete') diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/all.html b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/all.html new file mode 100644 index 0000000..3049902 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/all.html @@ -0,0 +1,30 @@ + + + + + jQuery UI Autocomplete Test Suite + + + + + + + + + + + + + +

jQuery UI Autocomplete Test Suite

+

+
+

+
    +
    + +
    + + diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete.html b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete.html new file mode 100644 index 0000000..571c620 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete.html @@ -0,0 +1,49 @@ + + + + + jQuery UI Autocomplete Test Suite + + + + + + + + + + + + + + + + + + +

    jQuery UI Autocomplete Test Suite

    +

    +
    +

    +
      +
      + +
      +
      +
      + + +
      + + diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_common.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_common.js new file mode 100644 index 0000000..63b24d3 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_common.js @@ -0,0 +1,29 @@ +TestHelpers.commonWidgetTests( "autocomplete", { + defaults: { + appendTo: null, + autoFocus: false, + delay: 300, + disabled: false, + messages: { + noResults: "No search results.", + results: $.ui.autocomplete.prototype.options.messages.results + }, + minLength: 1, + position: { + my: "left top", + at: "left bottom", + collision: "none" + }, + source: null, + + // callbacks + change: null, + close: null, + create: null, + focus: null, + open: null, + response: null, + search: null, + select: null + } +}); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_core.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_core.js new file mode 100644 index 0000000..7b9deb2 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_core.js @@ -0,0 +1,242 @@ +(function( $ ) { + +module( "autocomplete: core" ); + +test( "prevent form submit on enter when menu is active", function() { + expect( 2 ); + var event, + element = $( "#autocomplete" ) + .autocomplete({ + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ), + menu = element.autocomplete( "widget" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.DOWN; + element.trigger( event ); + deepEqual( menu.find( ".ui-menu-item:has(.ui-state-focus)" ).length, 1, "menu item is active" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.ENTER; + element.trigger( event ); + ok( event.isDefaultPrevented(), "default action is prevented" ); +}); + +test( "allow form submit on enter when menu is not active", function() { + expect( 1 ); + var event, + element = $( "#autocomplete" ) + .autocomplete({ + autoFocus: false, + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.ENTER; + element.trigger( event ); + ok( !event.isDefaultPrevented(), "default action is prevented" ); +}); + +(function() { + test( "up arrow invokes search - input", function() { + arrowsInvokeSearch( "#autocomplete", true, true ); + }); + + test( "down arrow invokes search - input", function() { + arrowsInvokeSearch( "#autocomplete", false, true ); + }); + + test( "up arrow invokes search - textarea", function() { + arrowsInvokeSearch( "#autocomplete-textarea", true, false ); + }); + + test( "down arrow invokes search - textarea", function() { + arrowsInvokeSearch( "#autocomplete-textarea", false, false ); + }); + + test( "up arrow invokes search - contenteditable", function() { + arrowsInvokeSearch( "#autocomplete-contenteditable", true, false ); + }); + + test( "down arrow invokes search - contenteditable", function() { + arrowsInvokeSearch( "#autocomplete-contenteditable", false, false ); + }); + + test( "up arrow moves focus - input", function() { + arrowsMoveFocus( "#autocomplete", true ); + }); + + test( "down arrow moves focus - input", function() { + arrowsMoveFocus( "#autocomplete", false ); + }); + + test( "up arrow moves focus - textarea", function() { + arrowsMoveFocus( "#autocomplete-textarea", true ); + }); + + test( "down arrow moves focus - textarea", function() { + arrowsMoveFocus( "#autocomplete-textarea", false ); + }); + + test( "up arrow moves focus - contenteditable", function() { + arrowsMoveFocus( "#autocomplete-contenteditable", true ); + }); + + test( "down arrow moves focus - contenteditable", function() { + arrowsMoveFocus( "#autocomplete-contenteditable", false ); + }); + + test( "up arrow moves cursor - input", function() { + arrowsNavigateElement( "#autocomplete", true, false ); + }); + + test( "down arrow moves cursor - input", function() { + arrowsNavigateElement( "#autocomplete", false, false ); + }); + + test( "up arrow moves cursor - textarea", function() { + arrowsNavigateElement( "#autocomplete-textarea", true, true ); + }); + + test( "down arrow moves cursor - textarea", function() { + arrowsNavigateElement( "#autocomplete-textarea", false, true ); + }); + + test( "up arrow moves cursor - contenteditable", function() { + arrowsNavigateElement( "#autocomplete-contenteditable", true, true ); + }); + + test( "down arrow moves cursor - contenteditable", function() { + arrowsNavigateElement( "#autocomplete-contenteditable", false, true ); + }); + + function arrowsInvokeSearch( id, isKeyUp, shouldMove ) { + expect( 1 ); + + var didMove = false, + element = $( id ).autocomplete({ + source: [ "a" ], + delay: 0, + minLength: 0 + }); + element.data( "ui-autocomplete" )._move = function() { + didMove = true; + }; + element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); + equal( didMove, shouldMove, "respond to arrow" ); + } + + function arrowsMoveFocus( id, isKeyUp ) { + expect( 1 ); + + var element = $( id ).autocomplete({ + source: [ "a" ], + delay: 0, + minLength: 0 + }); + element.data( "ui-autocomplete" )._move = function() { + ok( true, "repsond to arrow" ); + }; + element.autocomplete( "search" ); + element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); + } + + function arrowsNavigateElement( id, isKeyUp, shouldMove ) { + expect( 1 ); + + var didMove = false, + element = $( id ).autocomplete({ + source: [ "a" ], + delay: 0, + minLength: 0 + }); + element.on( "keypress", function( e ) { + didMove = !e.isDefaultPrevented(); + }); + element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); + element.simulate( "keypress" ); + equal( didMove, shouldMove, "respond to arrow" ); + } +})(); + +asyncTest( "handle race condition", function() { + expect( 3 ); + var count = 0, + element = $( "#autocomplete" ).autocomplete({ + source: function( request, response ) { + count++; + if ( request.term.length === 1 ) { + equal( count, 1, "request with 1 character is first" ); + setTimeout(function() { + response([ "one" ]); + setTimeout( checkResults, 1 ); + }, 1 ); + return; + } + equal( count, 2, "request with 2 characters is second" ); + response([ "two" ]); + } + }); + + element.autocomplete( "search", "a" ); + element.autocomplete( "search", "ab" ); + + function checkResults() { + equal( element.autocomplete( "widget" ).find( ".ui-menu-item" ).text(), "two", + "correct results displayed" ); + start(); + } +}); + +test( "ARIA", function() { + expect( 7 ); + var element = $( "#autocomplete" ).autocomplete({ + source: [ "java", "javascript" ] + }), + liveRegion = element.data( "ui-autocomplete" ).liveRegion; + + equal( liveRegion.text(), "", "Empty live region on create" ); + + element.autocomplete( "search", "j" ); + equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", + "Live region for multiple values" ); + + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", + "Live region not changed on focus" ); + + element.one( "autocompletefocus", function( event ) { + event.preventDefault(); + }); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equal( liveRegion.text(), "javascript", + "Live region updated when default focus is prevented" ); + + element.autocomplete( "search", "javas" ); + equal( liveRegion.text(), "1 result is available, use up and down arrow keys to navigate.", + "Live region for one value" ); + + element.autocomplete( "search", "z" ); + equal( liveRegion.text(), "No search results.", + "Live region for no values" ); + + element.autocomplete( "search", "j" ); + equal( liveRegion.text(), "2 results are available, use up and down arrow keys to navigate.", + "Live region for multiple values" ); +}); + +test( ".replaceWith() (#9172)", function() { + expect( 1 ); + + var element = $( "#autocomplete" ).autocomplete(), + replacement = "
      test
      ", + parent = element.parent(); + element.replaceWith( replacement ); + equal( parent.html().toLowerCase(), replacement ); +}); + +}( jQuery ) ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_events.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_events.js new file mode 100644 index 0000000..fb1cf73 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_events.js @@ -0,0 +1,182 @@ +(function( $ ) { + +module( "autocomplete: events" ); + +var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ]; + +$.each([ + { + type: "input", + selector: "#autocomplete", + valueMethod: "val" + }, + { + type: "textarea", + selector: "#autocomplete-textarea", + valueMethod: "val" + }, + { + type: "contenteditable", + selector: "#autocomplete-contenteditable", + valueMethod: "text" + } +], function( i, settings ) { + asyncTest( "all events - " + settings.type, function() { + expect( 13 ); + var element = $( settings.selector ) + .autocomplete({ + autoFocus: false, + delay: 0, + source: data, + search: function( event ) { + equal( event.originalEvent.type, "keydown", "search originalEvent" ); + }, + response: function( event, ui ) { + deepEqual( ui.content, [ + { label: "Clojure", value: "Clojure" }, + { label: "Java", value: "Java" }, + { label: "JavaScript", value: "JavaScript" } + ], "response ui.content" ); + ui.content.splice( 0, 1 ); + }, + open: function() { + ok( menu.is( ":visible" ), "menu open on open" ); + }, + focus: function( event, ui ) { + equal( event.originalEvent.type, "menufocus", "focus originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" ); + }, + close: function( event ) { + equal( event.originalEvent.type, "menuselect", "close originalEvent" ); + ok( menu.is( ":hidden" ), "menu closed on close" ); + }, + select: function( event, ui ) { + equal( event.originalEvent.type, "menuselect", "select originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" ); + }, + change: function( event, ui ) { + equal( event.originalEvent.type, "blur", "change originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "change ui.item" ); + ok( menu.is( ":hidden" ), "menu closed on change" ); + start(); + } + }), + menu = element.autocomplete( "widget" ); + + element.simulate( "focus" )[ settings.valueMethod ]( "j" ).keydown(); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is visible after delay" ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + // blur must be async for IE to handle it properly + setTimeout(function() { + element.simulate( "blur" ); + }, 1 ); + }, 50 ); + }); +}); + +asyncTest( "change without selection", function() { + expect( 1 ); + var element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + change: function( event, ui ) { + strictEqual( ui.item, null ); + start(); + } + }); + element.triggerHandler( "focus" ); + element.val( "ja" ).triggerHandler( "blur" ); +}); + +asyncTest( "cancel search", function() { + expect( 6 ); + var first = true, + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + search: function() { + if ( first ) { + equal( element.val(), "ja", "val on first search" ); + first = false; + return false; + } + equal( element.val(), "java", "val on second search" ); + }, + open: function() { + ok( true, "menu opened" ); + } + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + setTimeout(function() { + ok( menu.is( ":hidden" ), "menu is hidden after first search" ); + element.val( "java" ).keydown(); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is visible after second search" ); + equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" ); + start(); + }, 50 ); + }, 50 ); +}); + +asyncTest( "cancel focus", function() { + expect( 1 ); + var customVal = "custom value", + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + focus: function() { + $( this ).val( customVal ); + return false; + } + }); + element.val( "ja" ).keydown(); + setTimeout(function() { + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equal( element.val(), customVal ); + start(); + }, 50 ); +}); + +asyncTest( "cancel select", function() { + expect( 1 ); + var customVal = "custom value", + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + select: function() { + $( this ).val( customVal ); + return false; + } + }); + element.val( "ja" ).keydown(); + setTimeout(function() { + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equal( element.val(), customVal ); + start(); + }, 50 ); +}); + +asyncTest( "blur during remote search", function() { + expect( 1 ); + var ac = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: function( request, response ) { + ok( true, "trigger request" ); + ac.simulate( "blur" ); + setTimeout(function() { + response([ "result" ]); + start(); + }, 100 ); + }, + open: function() { + ok( false, "opened after a blur" ); + } + }); + ac.val( "ro" ).keydown(); +}); + +}( jQuery ) ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_methods.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_methods.js new file mode 100644 index 0000000..1bfa105 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_methods.js @@ -0,0 +1,45 @@ +(function( $ ) { + +module( "autocomplete: methods" ); + +test( "destroy", function() { + expect( 1 ); + domEqual( "#autocomplete", function() { + $( "#autocomplete" ).autocomplete().autocomplete( "destroy" ); + }); +}); + +test( "search, close", function() { + expect( 6 ); + var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ], + element = $( "#autocomplete" ).autocomplete({ + source: data, + minLength: 0 + }), + menu = element.autocomplete( "widget" ); + + ok( menu.is( ":hidden" ), "menu is hidden on init" ); + + element.autocomplete( "search" ); + ok( menu.is( ":visible" ), "menu is visible after search" ); + equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" ); + + element.val( "has" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" ); + + element.autocomplete( "search", "ja" ); + equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" ); + + element.autocomplete( "close" ); + ok( menu.is( ":hidden" ), "menu is hidden after close" ); +}); + +test( "widget", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete(), + widgetElement = element.autocomplete( "widget" ); + equal( widgetElement.length, 1, "one element" ); + ok( widgetElement.is( ".ui-menu" ), "menu element" ); +}); + +}( jQuery ) ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_options.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_options.js new file mode 100644 index 0000000..9f0bd2d --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/autocomplete_options.js @@ -0,0 +1,264 @@ +(function( $ ) { + +module( "autocomplete: options" ); + +var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; + +test( "appendTo", function() { + expect( 8 ); + var detached = $( "
      " ), + element = $( "#autocomplete" ).autocomplete(); + equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: ".ac-wrap" + }); + equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "first found element" ); + equal( $( "#ac-wrap2 .ui-autocomplete" ).length, 0, "only appends to one element" ); + element.autocomplete( "destroy" ); + + $( "#ac-wrap2" ).addClass( "ui-front" ); + element.autocomplete(); + equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap2" )[0], "null, inside .ui-front" ); + element.autocomplete( "destroy" ); + $( "#ac-wrap2" ).removeClass( "ui-front" ); + + element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" ); + equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached jQuery object" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: detached[0] + }); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" ); + element.autocomplete( "destroy" ); + + element.autocomplete().autocomplete( "option", "appendTo", detached ); + equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element via option()" ); + element.autocomplete( "destroy" ); +}); + +function autoFocusTest( afValue, focusedLength ) { + var element = $( "#autocomplete" ).autocomplete({ + autoFocus: afValue, + delay: 0, + source: data, + open: function() { + equal( element.autocomplete( "widget" ).children( ".ui-menu-item:first" ).find( ".ui-state-focus" ).length, + focusedLength, "first item is " + (afValue ? "" : "not") + " auto focused" ); + start(); + } + }); + element.val( "ja" ).keydown(); + stop(); +} + +test( "autoFocus: false", function() { + expect( 1 ); + autoFocusTest( false, 0 ); +}); + +test( "autoFocus: true", function() { + expect( 1 ); + autoFocusTest( true, 1 ); +}); + +asyncTest( "delay", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data, + delay: 50 + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + + ok( menu.is( ":hidden" ), "menu is closed immediately after search" ); + + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is open after delay" ); + start(); + }, 100 ); +}); + +asyncTest( "disabled", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data, + delay: 0, + disabled: true + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + + ok( menu.is( ":hidden" ) ); + + setTimeout(function() { + ok( menu.is( ":hidden" ) ); + start(); + }, 50 ); +}); + +test( "minLength", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data + }), + menu = element.autocomplete( "widget" ); + element.autocomplete( "search", "" ); + ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" ); + + element.autocomplete( "option", "minLength", 0 ); + element.autocomplete( "search", "" ); + ok( menu.is( ":visible" ), "blank enough for minLength: 0" ); +}); + +asyncTest( "minLength, exceed then drop below", function() { + expect( 4 ); + var element = $( "#autocomplete" ).autocomplete({ + minLength: 2, + source: function( req, res ) { + equal( req.term, "12", "correct search term" ); + setTimeout(function() { + res([ "item" ]); + }, 1 ); + } + }), + menu = element.autocomplete( "widget" ); + + ok( menu.is( ":hidden" ), "menu is hidden before first search" ); + element.autocomplete( "search", "12" ); + + ok( menu.is( ":hidden" ), "menu is hidden before second search" ); + element.autocomplete( "search", "1" ); + + setTimeout(function() { + ok( menu.is( ":hidden" ), "menu is hidden after searches" ); + start(); + }, 50 ); +}); + +test( "minLength, exceed then drop below then exceed", function() { + expect( 3 ); + var _res = [], + element = $( "#autocomplete" ).autocomplete({ + minLength: 2, + source: function( req, res ) { + _res.push( res ); + } + }), + menu = element.autocomplete( "widget" ); + + // trigger a valid search + ok( menu.is( ":hidden" ), "menu is hidden before first search" ); + element.autocomplete( "search", "12" ); + + // trigger a search below the minLength, to turn on cancelSearch flag + ok( menu.is( ":hidden" ), "menu is hidden before second search" ); + element.autocomplete( "search", "1" ); + + // trigger a valid search + element.autocomplete( "search", "13" ); + // react as if the first search was cancelled (default ajax behavior) + _res[ 0 ]([]); + // react to second search + _res[ 1 ]([ "13" ]); + + ok( menu.is( ":visible" ), "menu is visible after searches" ); +}); + +test( "source, local string array", function() { + expect( 1 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); +}); + +function sourceTest( source, async ) { + var element = $( "#autocomplete" ).autocomplete({ + source: source + }), + menu = element.autocomplete( "widget" ); + function result() { + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); + element.autocomplete( "destroy" ); + if ( async ) { + start(); + } + } + if ( async ) { + stop(); + $( document ).one( "ajaxStop", result ); + } + element.val( "ja" ).autocomplete( "search" ); + if ( !async ) { + result(); + } +} + +test( "source, local object array, only label property", function() { + expect( 1 ); + sourceTest([ + { label: "java" }, + { label: "php" }, + { label: "coldfusion" }, + { label: "javascript" } + ]); +}); + +test( "source, local object array, only value property", function() { + expect( 1 ); + sourceTest([ + { value: "java" }, + { value: "php" }, + { value: "coldfusion" }, + { value: "javascript" } + ]); +}); + +test( "source, url string with remote json string array", function() { + expect( 1 ); + sourceTest( "remote_string_array.txt", true ); +}); + +test( "source, url string with remote json object array, only value properties", function() { + expect( 1 ); + sourceTest( "remote_object_array_values.txt", true ); +}); + +test( "source, url string with remote json object array, only label properties", function() { + expect( 1 ); + sourceTest( "remote_object_array_labels.txt", true ); +}); + +test( "source, custom", function() { + expect( 2 ); + sourceTest(function( request, response ) { + equal( request.term, "ja" ); + response( ["java", "javascript"] ); + }); +}); + +test( "source, update after init", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: [ "java", "javascript", "haskell" ] + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); + element.autocomplete( "option", "source", [ "php", "asp" ] ); + element.val( "ph" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "php" ); +}); + +}( jQuery ) ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_labels.txt b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_labels.txt new file mode 100644 index 0000000..502496c --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_labels.txt @@ -0,0 +1 @@ +[{"label":"java"},{"label":"javascript"}] \ No newline at end of file diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_values.txt b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_values.txt new file mode 100644 index 0000000..029cbb9 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_object_array_values.txt @@ -0,0 +1 @@ +[{"value":"java"},{"value":"javascript"}] \ No newline at end of file diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_string_array.txt b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_string_array.txt new file mode 100644 index 0000000..3b24c8e --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/autocomplete/remote_string_array.txt @@ -0,0 +1 @@ +["java", "javascript"] \ No newline at end of file -- cgit v1.2.2