mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Fix sketchy pagination (#31)
* Fix test watcher and notifications on linux * Improve pagination; no items are repeated, items loaded ahead are kept and many calculations have been moved to subscriptions Closes #28
This commit is contained in:
parent
ea68c92c73
commit
4b9f99ecc2
9 changed files with 3187 additions and 69 deletions
2834
test/cljs/airsonic_ui/components/library/fixtures.cljs
Normal file
2834
test/cljs/airsonic_ui/components/library/fixtures.cljs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,12 +1,33 @@
|
|||
(ns airsonic-ui.components.library.subs-test
|
||||
(:require [cljs.test :refer-macros [deftest testing is]]
|
||||
[airsonic-ui.config :as conf]
|
||||
[airsonic-ui.components.library.fixtures :as fixtures]
|
||||
[airsonic-ui.components.library.subs :as sub]))
|
||||
|
||||
(def responses {["getAlbumList2" {:type "recent" :offset 1}] {:album '(5 6 7 8)}
|
||||
["getAlbumList2" {:type "recent" :offset 0}] {:album '(1 2 3 4)}
|
||||
["getAlbumList2" {:type "newest" :offset 1}] {:album '(9 8 7 6)}})
|
||||
(deftest partition-library
|
||||
(testing "Should give us a map of page -> content"
|
||||
(let [pages (sub/partition-responses "recent" fixtures/responses)]
|
||||
(is (map? pages))
|
||||
(is (every? int? (keys pages)))
|
||||
(is (every? seq? (vals pages)))))
|
||||
(testing "Should map each response correctly to a page"
|
||||
(let [first-response (select-keys fixtures/responses [["getAlbumList2" {:type "recent", :size 100, :offset 0}]])]
|
||||
(is (= (range 5) (keys (sub/partition-responses "recent" first-response)))))
|
||||
(let [first-and-third (select-keys fixtures/responses [["getAlbumList2" {:type "recent", :size 100, :offset 0}]
|
||||
["getAlbumList2" {:type "recent", :size 100, :offset 40}]])]
|
||||
;; there will be overlapping content for pages 2, 3 and 4 (with a zero-based index)
|
||||
(is (= (range 7) (keys (sub/partition-responses "recent" first-and-third)))))))
|
||||
|
||||
(deftest complete-library
|
||||
(testing "Should concatenate all album list responses for a given type of list"
|
||||
(is (= '(1 2 3 4 5 6 7 8)
|
||||
(sub/complete-library responses [:library/complete "recent"])))))
|
||||
(deftest paginated-library
|
||||
(testing "Should humanize page offsets"
|
||||
(let [responses (select-keys fixtures/responses [["getAlbumList2" {:type "recent", :size 100, :offset 0}]])
|
||||
paginated (sub/paginated-library responses [:sub/paginated-library "recent"])]
|
||||
(is (= [1 2 3 4 5] (keys paginated)))))
|
||||
(testing "Should concatenate and deduplicate all album list responses"
|
||||
(let [responses (select-keys fixtures/responses [["getAlbumList2" {:type "recent", :size 100, :offset 0}]
|
||||
["getAlbumList2" {:type "recent", :size 100, :offset 20}]
|
||||
["getAlbumList2" {:type "recent", :size 100, :offset 40}]])
|
||||
paginated (sub/paginated-library responses [:sub/paginated-library "recent"])]
|
||||
(is (= [1 2 3 4 5 6 7] (keys paginated)))
|
||||
(is (= 140 (count (mapcat val paginated))))
|
||||
(is (= 140 (count (set (mapcat val paginated))))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue