diff options
| author | Stephen Blott | 2012-11-11 17:45:24 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2012-11-11 17:45:24 +0000 | 
| commit | cf757fc841c6b97a8341472bd15bdc95c527babc (patch) | |
| tree | 17b503f47858ef4e72b50677b6dce5f72712bb63 | |
| parent | 775122483b5c5dd7631e247bc3bb7c89aac0e9ab (diff) | |
| download | vimium-cf757fc841c6b97a8341472bd15bdc95c527babc.tar.bz2 | |
More domain completer tests.
| -rw-r--r-- | tests/unit_tests/completion_test.coffee | 27 | 
1 files changed, 19 insertions, 8 deletions
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee index 6e6a2efb..e9e60ff9 100644 --- a/tests/unit_tests/completion_test.coffee +++ b/tests/unit_tests/completion_test.coffee @@ -130,8 +130,9 @@ context "domain completer",    setup ->      @history1 = { title: "history1", url: "http://history1.com", lastVisitTime: hours(1) }      @history2 = { title: "history2", url: "http://history2.com", lastVisitTime: hours(1) } +    @history3 = { title: "history2", url: "http://history2.com/something", lastVisitTime: hours(0) } -    stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2])) +    stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2, @history3]))      @onVisitedListener = null      @onVisitRemovedListener = null      global.chrome.history = @@ -142,7 +143,7 @@ context "domain completer",      @completer = new DomainCompleter()    should "return only a single matching domain", -> -    results = filterCompleter(@completer, ["story"]) +    results = filterCompleter(@completer, ["story1"])      assert.arrayEqual ["history1.com"], results.map (result) -> result.url    should "pick domains which are more recent", -> @@ -156,20 +157,30 @@ context "domain completer",    should "remove 1 matching domain entry", ->      # Force installation of `@onVisitRemovedListener` -    @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"]) +    filterCompleter(@completer, ["story"])      @onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] }      assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url -  should "remove 2 (both) matching domain entries", -> -    # Force installation of `@onVisitRemovedListener` -    @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"]) +  should "remove all entries from one domain", -> +    filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`. +    @onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] } +    @onVisitRemovedListener { allHistory: false, urls: [ @history3.url ] } +    assert.equal "history1.com", filterCompleter(@completer, ["story"])[0].url + +  should "remove 3 (all) matching domain entries", -> +    filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.      @onVisitRemovedListener { allHistory: false, urls: [ @history2.url ] }      @onVisitRemovedListener { allHistory: false, urls: [ @history1.url ] } +    @onVisitRemovedListener { allHistory: false, urls: [ @history3.url ] } +    assert.isTrue filterCompleter(@completer, ["story"]).length == 0 + +  should "remove 3 (all) matching domain entries, and do it all at once", -> +    filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`. +    @onVisitRemovedListener { allHistory: false, urls: [ @history2.url, @history1.url, @history3.url ] }      assert.isTrue filterCompleter(@completer, ["story"]).length == 0    should "remove *all* domain entries", -> -    # Force installation of `@onVisitRemovedListener` -    @history2.lastVisitTime = hours(3) and filterCompleter(@completer, ["story"]) +    filterCompleter(@completer, ["story"]) # Force installation of `@onVisitRemovedListener`.      @onVisitRemovedListener { allHistory: true }      assert.isTrue filterCompleter(@completer, ["story"]).length == 0  | 
