diff options
| author | Phil Crosby | 2012-06-03 00:27:46 -0700 |
|---|---|---|
| committer | Phil Crosby | 2012-06-03 16:52:32 -0700 |
| commit | 51f197952208701542eef60b353f248e5b9c6054 (patch) | |
| tree | 34109317322b81129a93ec8cbf8b019fad0c2877 /tests | |
| parent | 2cbb4961ce60d75c1535ad65ede5ca74db254cb3 (diff) | |
| download | vimium-51f197952208701542eef60b353f248e5b9c6054.tar.bz2 | |
Implement ranking, and use recency when ranking history entries
One major change between this and the previous implementation is
that all scores are between [0, 1] and "1" means most relevant.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/completion_test.coffee | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee index b79eae98..ed56d0e9 100644 --- a/tests/completion_test.coffee +++ b/tests/completion_test.coffee @@ -24,8 +24,9 @@ context "bookmark completer", context "history completer", setup -> - @history1 = { title: "history1", url: "history1.com" } - @history2 = { title: "history2", url: "history2.com" } + # history2 is more recent than history1. + @history1 = { title: "history1", url: "history1.com", lastVisitTime: hours(1) } + @history2 = { title: "history2", url: "history2.com", lastVisitTime: hours(5) } global.chrome.history = search: (options, callback) => callback([@history1, @history2]) @@ -37,6 +38,13 @@ context "history completer", @completer.filter(["story1"], (@results) =>) assert.arrayEqual [@history1.url], @results.map (entry) -> entry.url + should "rank recent results higher than nonrecent results", -> + stub(Date, "now", returns(hours(24))) + @completer.filter(["hist"], (@results) =>) + @results.forEach (result) -> result.computeRelevancy() + @results.sort (a, b) -> b.relevancy - a.relevancy + assert.arrayEqual [@history2.url, @history1.url], @results.map (result) -> result.url + context "suggestions", should "escape html in page titles", -> suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>") @@ -50,4 +58,6 @@ context "suggestions", suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords") assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com") +hours = (n) -> 1000 * 60 * 60 * n + Tests.run()
\ No newline at end of file |
