autocomplete-test.js revision cc70141342b8690e43bef6d8cef0c38fcfba8227
var ArrayAssert = Y.ArrayAssert,
YArray = Y.Array,
// Simple, bare AutoCompleteBase implementation for testing.
initializer: function () {
this._bindUIACBase();
this._syncUIACBase();
},
destructor: function () {
this._destructorACBase();
}
});
// -- Global Suite -------------------------------------------------------------
// -- Base Suite ---------------------------------------------------------------
// -- Base: Lifecycle ----------------------------------------------------------
name: 'Lifecycle',
_should: {
error: {
'Initializer should require an inputNode': 'No inputNode specified.'
}
},
setUp: function () {
},
tearDown: function () {
delete this.inputNode;
},
'Initializer should accept an inputNode': function () {
},
'Initializer should require an inputNode': function () {
// Should fail.
}
}));
// -- Base: Attributes ---------------------------------------------------------
name: 'Attributes',
setUp: function () {
},
tearDown: function () {
delete this.ac;
delete this.inputNode;
},
'_parseResponse should preserve duplicates in text when using resultTextLocator': function () {
var response = {
results: [
{"City":"La Habra","State":"CA","County":"Orange","Zip":"90631"},
{"City":"La Habra Heights","State":"CA","County":"Orange","Zip":"90631"},
{"City":"La Habra Hgts","State":"CA","County":"Orange","Zip":"90631"}
]
};
"The raw result values should be different.");
"The raw result values should be different.");
});
},
'Browser autocomplete should be off by default': function () {
},
'Browser autocomplete should be turned on when enabled': function () {
allowBrowserAutocomplete: true
});
},
'Browser autocomplete should be settable after init': function () {
},
'inputNode should be writable only on init': function () {
},
// 'maxResults should enforce a maximum number of results': function () {
//
// },
//
// 'maxResults should do nothing if <= 0': function () {
//
// },
'requestTemplate should accept a custom template function': function () {
return 'query: ' + query;
};
},
'requestTemplate should generate a template function when set to a string': function () {
},
'requestTemplate function should replace {query} with the URI-encoded query': function () {
var rt;
},
'resultFilters should accept a filter, array of filters, string, array of strings, or null': function () {
var filter = function () {};
ArrayAssert.itemsAreSame([Y.AutoCompleteFilters.phraseMatch, Y.AutoCompleteFilters.charMatch], this.ac.get('resultFilters'));
},
// -- Generic setters and validators ---------------------------------------
'_functionValidator() should accept a function or null': function () {
},
'_setSource() should accept a DataSource': function () {
},
'_setSource() should accept an array': function () {
},
'_setSource() should accept an object': function () {
},
'_setSource() should accept a URL string': function () {
},
'_setSource() should accept a YQL string': function () {
},
'_setSource() should accept a Y.JSONPRequest instance': function () {
},
// -- Miscellaneous protected methods that aren't testable otherwise -------
'_jsonpFormatter should correctly format URLs both with and without a requestTemplate set': function () {
Assert.areSame('foo?q=bar%20baz&cb=callback', this.ac._jsonpFormatter('foo?q={query}&cb={callback}', 'callback', 'bar baz'));
Assert.areSame('foo?q=bar%20baz&cb=callback', this.ac._jsonpFormatter('foo', 'callback', 'bar baz'));
}
}));
// -- Filters Suite ------------------------------------------------------------
function arrayToResults(array) {
return {
};
});
}
if (!key) {
key = 'text';
}
});
}
// -- Filters: API -------------------------------------------------------------
name: 'API',
// -- charMatch() ----------------------------------------------------------
'charMatch() should match all characters in the query, in any order': function () {
);
['cab', 'taxi cab'],
);
},
'charMatch() should be case-insensitive': function () {
['Foo', 'foo'],
);
},
'charMatchCase() should be case-sensitive': function () {
['foo'],
);
},
'charMatchFold() should match accent-folded characters': function () {
['fóó', 'föö', 'foo'],
);
// Accent-folded matches are always case-insensitive.
['FÓÓ', 'FÖÖ', 'FOO'],
);
},
// -- phraseMatch() --------------------------------------------------------
'phraseMatch() should match the complete query as a phrase': function () {
);
['foo bar'],
);
['xxfoo barxx'],
);
['foo barxx'],
);
['xxfoo bar'],
);
},
'phraseMatch() should be case-insensitive': function () {
['Foo', 'foo'],
);
},
'phraseMatchCase() should be case-sensitive': function () {
['foo'],
);
},
'phraseMatchFold() should match accent-folded characters': function () {
['fóó', 'föö', 'foo'],
);
// Accent-folded matches are always case-insensitive.
['FÓÓ', 'FÖÖ', 'FOO'],
);
},
// -- startsWith() ---------------------------------------------------------
'startsWith() should match the complete query at the start of a result': function () {
);
['foo', 'foo bar'],
);
},
'startsWith() should be case-insensitive': function () {
['Foo', 'foo'],
);
},
'startsWithCase() should be case-sensitive': function () {
['foo'],
);
},
'startsWithFold() should match accent-folded characters': function () {
['fóó', 'föö', 'foo'],
);
// Accent-folded matches are always case-insensitive.
['FÓÓ', 'FÖÖ', 'FOO'],
);
},
// -- wordMatch() ----------------------------------------------------------
'wordMatch() should match results that contain all words in the query in any order': function () {
);
['foo bar baz'],
resultsToArray(Filters.wordMatch('baz foo bar', arrayToResults(['foo', 'bar', 'foo bar baz', 'foobar baz'])))
);
['foo', 'foo bar baz'],
resultsToArray(Filters.wordMatch('foo', arrayToResults(['foo', 'bar', 'foo bar baz', 'foobar baz'])))
);
},
'wordMatch() should be case-insensitive': function () {
['Foo', 'foo'],
);
},
'wordMatchCase() should be case-sensitive': function () {
['foo'],
);
},
'wordMatchFold() should match accent-folded characters': function () {
['fóó', 'föö', 'foo'],
);
// Accent-folded matches are always case-insensitive.
['FÓÓ', 'FÖÖ', 'FOO'],
);
}
}));
// -- Highlighters Suite -------------------------------------------------------
// -- Highlighters: API --------------------------------------------------------
name: 'API',
// -- charMatch() ----------------------------------------------------------
'charMatch() should highlight all characters in the query, in any order': function () {
['foo', '<b class="yui3-highlight">b</b><b class="yui3-highlight">a</b>r', '<b class="yui3-highlight">b</b><b class="yui3-highlight">a</b>z'],
);
},
'charMatch() should be case-insensitive': function () {
['<b class="yui3-highlight">F</b>oo', '<b class="yui3-highlight">f</b>oo'],
);
},
// -- charMatchCase() ------------------------------------------------------
'charMatchCase() should be case-sensitive': function () {
['Foo', '<b class="yui3-highlight">f</b>oo'],
);
},
// -- charMatchFold() ------------------------------------------------------
'charMatchFold() should highlight accent-folded characters': function () {
['f<b class="yui3-highlight">ó</b><b class="yui3-highlight">ó</b>', 'f<b class="yui3-highlight">o</b><b class="yui3-highlight">o</b>', 'bar'],
);
['f<b class="yui3-highlight">o</b><b class="yui3-highlight">o</b>', 'f<b class="yui3-highlight">o</b><b class="yui3-highlight">o</b>', 'bar'],
);
},
// -- phraseMatch() --------------------------------------------------------
'phraseMatch() should highlight the complete query as a phrase': function () {
['foo', 'bar', 'foo bar'],
);
['foo', 'bar', '<b class="yui3-highlight">foo bar</b>'],
);
['<b class="yui3-highlight">foo</b>', 'bar', '<b class="yui3-highlight">foo</b> bar'],
);
['foo', 'bar', 'xx<b class="yui3-highlight">foo bar</b>'],
);
},
'phraseMatch() should be case-insensitive': function () {
['<b class="yui3-highlight">Foo</b>', '<b class="yui3-highlight">foo</b>'],
);
},
// -- phraseMatchCase() ----------------------------------------------------
'phraseMatchCase() should be case-sensitive': function () {
['Foo', '<b class="yui3-highlight">foo</b>'],
);
},
// -- phraseMatchFold() ----------------------------------------------------
'phraseMatchFold() should match accent-folded characters': function () {
['<b class="yui3-highlight">fóó</b>bar', 'bar<b class="yui3-highlight">foo</b>', 'bar'],
);
['<b class="yui3-highlight">foo</b>bar', 'bar<b class="yui3-highlight">foo</b>', 'bar'],
);
},
// -- startsWith() ---------------------------------------------------------
'startsWith() should highlight the complete query at the start of a result': function () {
['xx foo', 'bar', 'xx foo bar'],
);
['<b class="yui3-highlight">foo</b>', 'bar foo', '<b class="yui3-highlight">foo</b> bar'],
);
},
'startsWith() should be case-insensitive': function () {
['<b class="yui3-highlight">Foo</b>', '<b class="yui3-highlight">foo</b>'],
);
},
// -- startsWithCase() -----------------------------------------------------
'startsWithCase() should be case-sensitive': function () {
['Foo', '<b class="yui3-highlight">foo</b>'],
);
},
// -- startsWithFold() -----------------------------------------------------
'startsWithFold() should match accent-folded characters': function () {
['<b class="yui3-highlight">fóó</b>', 'barfoo', 'bar'],
);
['<b class="yui3-highlight">foo</b>', 'barfoo', 'bar'],
);
},
// -- wordMatch() ----------------------------------------------------------
'wordMatch() should highlight complete words in the query': function () {
['foobar', 'barbaz'],
);
['<b class="yui3-highlight">foo</b>', '<b class="yui3-highlight">bar</b>', '<b class="yui3-highlight">foo</b> <b class="yui3-highlight">bar</b> <b class="yui3-highlight">baz</b>', 'foobar <b class="yui3-highlight">baz</b>'],
);
},
'wordMatch() should be case-insensitive': function () {
['<b class="yui3-highlight">Foo</b>', '<b class="yui3-highlight">foo</b>'],
);
},
// -- wordMatchCase() ------------------------------------------------------
'wordMatchCase() should be case-sensitive': function () {
['Foo', '<b class="yui3-highlight">foo</b>'],
);
},
'wordMatchFold() should match accent-folded characters': function () {
['<b class="yui3-highlight">fóó</b>', '<b class="yui3-highlight">foo</b>', 'barfoo'],
);
['<b class="yui3-highlight">foo</b>', '<b class="yui3-highlight">fóó</b>', 'barfoo'],
);
}
}));
}, '@VERSION@', {
requires: [
'autocomplete-base', 'autocomplete-filters',
'autocomplete-filters-accentfold', 'autocomplete-highlighters',
'autocomplete-highlighters-accentfold', 'autocomplete-test-data',
'datasource-local', 'node', 'jsonp', 'test', 'yql'
]
});