diff options
| author | Phil Crosby | 2012-06-02 20:08:35 -0700 |
|---|---|---|
| committer | Phil Crosby | 2012-06-03 16:52:32 -0700 |
| commit | e7f75e2c6add8048beb1f4dd2703766f016497bd (patch) | |
| tree | 3ac47a4a7084b5349c4aabbd4a49cfb3acef3036 /tests | |
| parent | d5e64794577e64ef92412e2f0a5794120a85d77b (diff) | |
| download | vimium-e7f75e2c6add8048beb1f4dd2703766f016497bd.tar.bz2 | |
A WIP rewrite of completion in the vomnibar.
The purpose of this refactor is to simplify the contract so it's easier
to modify, and to make some substantial usability improvements.
One of the key differences is that matching is no longer fuzzy. If you
want to search more than one term, separate them by spaces. This matches
the behavior in Firefox.
While fuzzy matching is a nice experience for a limited set of known
items (like files in the current project), it doesn't work well for
a huge messy collection, like URLs in your history. The query "hello"
will match random stuff from your google search results for instance,
and it's hard to prune that noise using ranking intelligence.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/completion_test.coffee | 53 | ||||
| -rw-r--r-- | tests/test_helper.coffee | 5 |
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee new file mode 100644 index 00000000..eb833ecf --- /dev/null +++ b/tests/completion_test.coffee @@ -0,0 +1,53 @@ +require "./test_helper.js" +extend(global, require "../lib/utils.js") +extend(global, require "../background_scripts/completion.js") + +global.chrome = {} + +context "bookmark completer", + setup -> + @bookmark2 = { title: "bookmark2", url: "bookmark2.com" } + @bookmark1 = { title: "bookmark1", url: "bookmark1.com", children: [@bookmark2] } + global.chrome.bookmarks = + getTree: (callback) => callback([@bookmark1]) + + @completer = new BookmarkCompleter() + + should "flatten a list of bookmarks", -> + result = @completer.traverseBookmarks([@bookmark1]) + assert.arrayEqual [@bookmark1, @bookmark2], @completer.traverseBookmarks([@bookmark1]) + + should "return matching bookmarks when searching", -> + @completer.refresh() + @completer.filter(["mark2"], (@results) =>) + assert.arrayEqual [@bookmark2.url], @results.map (suggestion) -> suggestion.url + +context "history completer", + setup -> + @history1 = { title: "history1", url: "history1.com" } + @history2 = { title: "history2", url: "history2.com" } + + global.chrome.history = + search: (options, callback) => callback([@history1, @history2]) + onVisited: { addListener: -> } + + @completer = new HistoryCompleter() + + should "return matching history entries when searching", -> + @completer.filter(["story1"], (@results) =>) + assert.arrayEqual [@history1.url], @results.map (entry) -> entry.url + +context "suggestions", + should "escape html in page titles", -> + suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>", "action") + assert.isTrue suggestion.generateHtml().indexOf("title <span>") >= 0 + + should "highlight query words", -> + suggestion = new Suggestion(["ninja"], "tab", "url", "ninjawords", "action") + assert.isTrue suggestion.generateHtml().indexOf("<span class='match'>ninja</span>words") >= 0 + + should "shorten urls", -> + suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords", "action") + assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com") + +Tests.run()
\ No newline at end of file diff --git a/tests/test_helper.coffee b/tests/test_helper.coffee new file mode 100644 index 00000000..237f8e24 --- /dev/null +++ b/tests/test_helper.coffee @@ -0,0 +1,5 @@ +require("./shoulda.js/shoulda.js") +global.extend = (hash1, hash2) -> + for key of hash2 + hash1[key] = hash2[key] + hash1
\ No newline at end of file |
