source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/tests/unit/autocomplete/autocomplete_options.js@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 4.2 KB
Line 
1/*
2 * autocomplete_options.js
3 */
4(function($) {
5
6module("autocomplete: options");
7
8
9/* disabled until autocomplete actually has built-in support for caching
10// returns at most 4 items
11function source(request) {
12 ok(true, "handling a request");
13 switch(request.term) {
14 case "cha":
15 return ["Common Pochard", "Common Chiffchaff", "Common Chaffinch", "Iberian Chiffchaff"]
16 case "chaf":
17 case "chaff":
18 return ["Common Chiffchaff", "Common Chaffinch", "Iberian Chiffchaff"]
19 case "chaffi":
20 return ["Common Chaffinch"]
21 case "schi":
22 return ["schifpre"]
23 }
24}
25
26function search(input) {
27 var autocomplete = input.data("autocomplete");
28 autocomplete.search("cha");
29 autocomplete.close();
30 autocomplete.search("chaf");
31 autocomplete.close();
32 autocomplete.search("chaff");
33 autocomplete.close();
34 autocomplete.search("chaffi");
35 autocomplete.close();
36 autocomplete.search("schi");
37}
38
39test("cache: default", function() {
40 expect(2);
41 search($("#autocomplete").autocomplete({
42 source: source
43 }));
44});
45
46test("cache: {limit:4}", function() {
47 expect(3);
48 search($("#autocomplete").autocomplete({
49 cache: {
50 limit: 4
51 },
52 source: source
53 }));
54});
55
56test("cache: false", function() {
57 expect(5);
58 search($("#autocomplete").autocomplete({
59 cache: false,
60 source: source
61 }));
62});
63*/
64
65var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"];
66
67test("delay", function() {
68 var ac = $("#autocomplete").autocomplete({
69 source: data,
70 delay: 50
71 });
72 ac.val("ja").keydown();
73
74 same( $(".ui-menu").length, 0 );
75
76 // wait half a second for the default delay to open the menu
77 stop();
78 setTimeout(function() {
79 same( $(".ui-menu").length, 1 );
80 ac.autocomplete("destroy");
81 start();
82 }, 100);
83});
84
85test("minLength", function() {
86 var ac = $("#autocomplete").autocomplete({
87 source: data
88 });
89 ac.autocomplete("search", "");
90 same( $(".ui-menu").length, 0, "blank not enough for minLength: 1" );
91
92 ac.autocomplete("option", "minLength", 0);
93 ac.autocomplete("search", "");
94 same( $(".ui-menu").length, 1, "blank enough for minLength: 0" );
95 ac.autocomplete("destroy");
96});
97
98test("source, local string array", function() {
99 var ac = $("#autocomplete").autocomplete({
100 source: data
101 });
102 ac.val("ja").autocomplete("search");
103 same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
104 ac.autocomplete("destroy");
105});
106
107function source_test(source, async) {
108 var ac = $("#autocomplete").autocomplete({
109 source: source
110 });
111 ac.val("ja").autocomplete("search");
112 function result(){
113 same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
114 ac.autocomplete("destroy");
115 async && start();
116 }
117 if (async) {
118 stop();
119 setTimeout(result, 100);
120 } else {
121 result();
122 }
123}
124
125test("source, local object array, only label property", function() {
126 source_test([
127 {label:"java"},
128 {label:"php"},
129 {label:"coldfusion"},
130 {label:"javascript"}
131 ]);
132});
133
134test("source, local object array, only value property", function() {
135 source_test([
136 {value:"java"},
137 {value:"php"},
138 {value:"coldfusion"},
139 {value:"javascript"}
140 ]);
141});
142
143test("source, url string with remote json string array", function() {
144 source_test("remote_string_array.txt", true);
145});
146
147test("source, url string with remote json object array, only value properties", function() {
148 source_test("remote_object_array_values.txt", true);
149});
150
151test("source, url string with remote json object array, only label properties", function() {
152 source_test("remote_object_array_labels.txt", true);
153});
154
155test("source, custom", function() {
156 source_test(function(request, response) {
157 same( request.term, "ja" );
158 response(["java", "javascript"]);
159 });
160});
161
162test("source, update after init", function() {
163 var ac = $("#autocomplete").autocomplete({
164 source: ["java", "javascript", "haskell"]
165 });
166 ac.val("ja").autocomplete("search");
167 same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
168 ac.autocomplete("option", "source", ["php", "asp"]);
169 ac.val("ph").autocomplete("search");
170 same( $(".ui-menu .ui-menu-item").text(), "php" );
171 ac.autocomplete("destroy");
172});
173
174})(jQuery);
Note: See TracBrowser for help on using the repository browser.