Commit cf9fb8e6 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Confirming that the port is disregarded when looking at the site time

Also expanded comments on url-key, since there is a reason why it uses
host instead of hostname.
parent 16855131
Pipeline #4517025 passed with stage
in 1 minute and 45 seconds
......@@ -78,6 +78,10 @@
[url]
(if (not-empty url)
(let [element (dommy/set-attr! (dommy/create-element :a) :href url)
;; For the url-key we _want_ to use the full host, not just the hostname
;; since it will be used to indicate how much time we have spent on the
;; specific URL. http://localhost/index.html will likely be different from
;; http://localhost:8080/index.html
shortened (str (.toLowerCase (.-host element)) (.-pathname element) (.-search element))]
(hash-string shortened))
0))
......
......@@ -439,14 +439,51 @@
:ts 1446051494575
:title "New York spot price Gold..."}}
acc (data/accumulate-site-times data)]
; There should be no empty hostnames
; We check (get acc 0) because the result is indexed by the host-key,
; which returns 0 on nil or empty.
;; There should be no empty hostnames
;; We check (get acc 0) because the result is indexed by the host-key,
;; which returns 0 on nil or empty.
(is (nil? (get acc 0)))
;; Let's verify we got the right data
(is (= {971841386 {:time 39, :icon nil, :host "numergent.com"},
-915908674 {:time 4, :icon nil, :host "www.kitco.com"}}
acc)))))
acc))))
(testing "Accumulate site times disregards the port for the URL when accumulating"
(let [data {2080624698
{:url "/tags/khroma/"
:time 117
:ts 1445964037798
:title "Khroma articles"}
-526558523
{:url "http://numergent.com/opensource/"
:time 27
:ts 1445964037798
:title "Open source projects"}
-380467869
{:url "http://google.com"
:time 12
:ts 1445964037798
:title "Google - default port"}
-849773167
{:url "http://google.com:8080"
:time 25
:ts 1445964037798
:title "Google - non-standard port"}
1917381154
{:url "http://www.kitco.com/market/"
:time 4
:ts 1446051494575
:title "New York spot price Gold..."}}
acc (data/accumulate-site-times data)]
;; There should be no empty hostnames
;; We check (get acc 0) because the result is indexed by the host-key,
;; which returns 0 on nil or empty.
(is (nil? (get acc 0)))
;; Let's verify we got the right data
(is (= {971841386 {:time 27 :icon nil :host "numergent.com"}
-915908674 {:time 4 :icon nil :host "www.kitco.com"}
-1536293812 {:time 37 :icon nil :host "google.com"}}
acc))))
)
(deftest test-accumulate-after-clean-up
......
......@@ -5,61 +5,82 @@
(deftest test-time-score
; A score for an unknown URL with no tab index is zero
;; A score for an unknown URL with no tab index is zero
(is (= 0 (order/time-score {:url "http://google.com"}
{}
{}
{})))
; A score for an unknown URL with no tab index is the complement of its index
;; A score for an unknown URL with no tab index is the complement of its index
(is (= -20 (order/time-score {:url "http://google.com"
:index 20}
{}
{}
{})))
; A score for a known URL equals its time value
;; A score for a known URL equals its time value
(is (= 291 (order/time-score {:url "http://google.com"}
{(utils/url-key "http://google.com")
{:time 291}}
{}
{})))
; A score for a known URL gets added the time for its site
;; A score for a known URL equals its time value, even if it includes a port
(is (= 291 (order/time-score {:url "http://google.com:80"}
{(utils/url-key "http://google.com")
{:time 291}}
{}
{})))
;; A score for a known URL gets added the time for its site
(is (= 468 (order/time-score {:url "http://google.com/somepage"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A score for a known URL is not affected by the score of other URLs for the same site
;; A score for a known URL gets added the time for its host, even if it's using
;; a non-standard port
(is (= 123 (order/time-score {:url "http://google.com:9090/somepage"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
(is (= 448 (order/time-score {:url "http://google.com:9090/somepage"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}
(utils/url-key "http://google.com:9090/somepage") {:time 325}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
;; A score for a known URL is not affected by the score of other URLs for the same site
(is (= 414 (order/time-score {:url "http://google.com/"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A page inherits its site's score even if the page is unknown
;; A page inherits its site's score even if the page is unknown
(is (= 987 (order/time-score {:url "http://apple.com/mac"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A page inherits its site's score even if the page is unknown, but
; substracts the index so that they are placed at the end.
;; A page inherits its site's score even if the page is unknown, but
;; substracts the index so that they are placed at the end.
(is (= 975 (order/time-score {:url "http://apple.com/mac" :index 12}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A page that has sound gets no extra score if the :sound-to-left? key isn't on settings
;; A page that has sound gets no extra score if the :sound-to-left? key isn't on settings
(is (= 291 (order/time-score {:url "http://google.com"
:audible true}
{(utils/url-key "http://google.com")
{:time 291}}
{}
{})))
; An audible page gets an extra score if the :sound-to-left? key is set to true on the settings,
; but based on the index, not the time spent
;; An audible page gets an extra score if the :sound-to-left? key is set to true on the settings,
;; but based on the index, not the time spent
(is (= (+ 5 123 order/sound-extra-score)
(order/time-score {:url "http://google.com/translate"
:index 5
......@@ -69,8 +90,8 @@
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{:sound-to-left? true})))
; Non-http pages are penalized, but get a minimum score of 1 (they will
; likely have a time of 0 to begin with since they aren't tracked)
;; Non-http URLs are penalized, but get a minimum score of 1 (they will
;; likely have a time of 0 to begin with since they aren't tracked)
(is (= (* 124 order/non-http-penalty)
(order/time-score {:url "chrome://google.com/translate"
:index 5}
......@@ -87,8 +108,8 @@
(utils/url-key "http://apple.com/") {:time 2120}}
site-times {(utils/host-key "google.com") {:time 4295} ; Includes time from tabs which we have deleted
(utils/host-key "apple.com") {:time 12221}}]
; We have spent the longest at Apple, so it gets prioritized
; The extension tab ends up at the end because it's not http
;; We have spent the longest at Apple, so it gets prioritized
;; The extension tab ends up at the end because it's not http
(is (= [{:index 0 :id 23} {:index 1 :id 9} {:index 2 :id 1}]
(order/score-tabs [{:url "http://google.com"
:id 9
......@@ -102,7 +123,7 @@
url-times
site-times
{})))
; An unknown page ends up at the end
;; An unknown page ends up at the end
(is (= [{:index 0 :id 23} {:index 1 :id 9} {:index 2 :id 1} {:index 3 :id 2}]
(order/score-tabs [{:url "http://google.com"
:id 9
......@@ -119,7 +140,7 @@
url-times
site-times
{})))
; Two unknown pages get sorted by their index order
;; Two unknown pages get sorted by their index order
(is (= [{:index 0 :id 23} {:index 1 :id 9} {:index 2 :id 1} {:index 3 :id 123} {:index 4 :id 2}]
(order/score-tabs [{:url "http://google.com"
:id 9
......@@ -139,7 +160,7 @@
url-times
site-times
{})))
; An unknown page that is playing sound gets prioritized according to the settings
;; An unknown page that is playing sound gets prioritized according to the settings
(is (= [{:index 0 :id 2} {:index 1 :id 23} {:index 2 :id 9} {:index 3 :id 1}]
(order/score-tabs [{:url "http://google.com"
:id 9
......@@ -157,7 +178,7 @@
url-times
site-times
{:sound-to-left? true})))
; If for any reason the Apple URL is not http, it gets de-prioritized
;; If for any reason the Apple URL is not http, it gets de-prioritized
(is (= [{:index 0 :id 9} {:index 1 :id 1} {:index 2 :id 23}]
(order/score-tabs [{:url "http://google.com"
:id 9
......
......@@ -38,6 +38,12 @@
-526558523 "http://numergent.com/opensource/"
93819220 "about:blank"
-847465478 "file:///Users/ricardo/Sources/user.html"
;; URL keys are port-sensitive
-380467869 "http://google.com:80"
-849773167 "http://google.com:8080"
;; Port 80 is treated the same as if it wasn't specified
2045915370 "http://google.com/index.html"
2045915370 "http://google.com:80/index.html"
))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment