1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-06 18:33:38 +02:00

Merge feature/search

Squashed commit of the following:

commit 8a19df91f8daa1b791d40cc910947c94355a8d0d
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Aug 28 16:06:35 2018 +0200

    Implement search UI (closes #19)

commit bf661dd25ec9f1d5569df88a8a87f94c1bc1b317
Author: Arne Schlüter <arne@schlueter.is>
Date:   Tue Aug 28 11:09:46 2018 +0200

    Re-add subscription for single endpoint and move helpers to a different location
This commit is contained in:
Arne Schlüter 2018-08-28 16:07:45 +02:00
commit 7653af5dd1
22 changed files with 236 additions and 49 deletions

View file

@ -1,7 +1,7 @@
(ns airsonic-ui.api.helpers-test
(:require [cljs.test :refer [deftest testing is]]
[clojure.string :as str]
[airsonic-ui.fixtures :refer [responses]]
[airsonic-ui.fixtures :as fixtures :refer [responses]]
[airsonic-ui.api.helpers :as api]))
(defn- url
@ -20,6 +20,12 @@
(is (string? (re-find #"f=json" (fixtures :default-url))))
(is (string? (re-find #"v=1\.15\.0" (fixtures :default-url))))))
(deftest parameter-encoding
(testing "Should escape url parameters"
(let [query "äöüß"
encoded-str (js/encodeURIComponent query)]
(is (str/includes? (api/url "http://localhost" "search3" {:query query}) encoded-str)))))
(deftest song-urls
(testing "Should construct the url based on a song's id"
(let [song {:id 1234}]
@ -46,7 +52,7 @@
(try
(api/unwrap-response error-response)
(catch ExceptionInfo e
(= (:error error-response) (ex-data e)))))))
(is (= (get-in error-response [:subsonic-response :error]) (ex-data e))))))))
(deftest error-recognition
(testing "Should detect error responses"
@ -55,3 +61,13 @@
(testing "Should pass on good responses"
(is (false? (api/is-error? (:ok responses))))
(is (false? (api/is-error? (:auth-success responses))))))
(deftest content-type
(testing "Should detect whether the data we look at represents a song"
(is (= :content-type/song (api/content-type fixtures/song))))
(testing "Should detect whether the data we look at represents an artist"
(is (= :content-type/artist (api/content-type fixtures/artist)))
(is (= :content-type/artist (api/content-type (dissoc fixtures/artist :coverArt)))))
(testing "Should detect whether the data we look at represents an album"
(is (= :content-type/album (api/content-type fixtures/album)))
(is (= :content-type/album (api/content-type (dissoc fixtures/album :coverArt))))))

View file

@ -4,6 +4,12 @@
(enable-console-print!)
(deftest single-response
(testing "Should return the response for a specified endpoint"
(let [db {:api/responses {["search2" {:query "query term"}] :result}}]
(is (= :result (sub/response-for db [:api/response-for "search2" {:query "query term"}])))
(is (nil? (sub/response-for db [:api/response-for "search2" {:query "another query term"}]))))))
(deftest endpoint-keywordification
(testing "Should strip prefixes"
(is (= :artist-info (sub/endpoint->kw "getArtistInfo")))

View file

@ -1,7 +1,7 @@
(ns airsonic-ui.audio.playlist-test
(:require [cljs.test :refer [deftest testing is]]
[airsonic-ui.audio.playlist :as playlist]
[airsonic-ui.utils.helpers :refer [find-where]]
[airsonic-ui.helpers :refer [find-where]]
[airsonic-ui.fixtures :as fixtures]
[airsonic-ui.test-helpers :as helpers]
[debux.cs.core :refer-macros [dbg]]))

View file

@ -21,6 +21,20 @@
:error {:code 40
:message "Wrong username or password."}}}})
(def artist
{:id "499", :name "Tomemitsu", :coverArt "ar-497", :albumCount 1})
(def album
{:artistId "258",
:name "Tocotronic",
:songCount 26,
:created "2017-12-31T08:18:45.000Z",
:duration 7383,
:artist "Tocotronic",
:year 2015,
:id "439",
:coverArt "al-439"})
(def song
{:artistId 42,
:path "DJ Koze/DJ Koze - Reincarnations Part 2, The Remix Chapter 2009-2014/14. Apparat - Black Water (DJ Koze Remix).mp3",

View file

@ -1,6 +1,6 @@
(ns airsonic-ui.utils.helpers-test
(ns airsonic-ui.helpers-test
(:require [cljs.test :refer [deftest testing is]]
[airsonic-ui.utils.helpers :as helpers]))
[airsonic-ui.helpers :as helpers]))
(deftest find-where
(testing "Finds the correct item and index"
@ -12,3 +12,12 @@
:bar false})))))
(testing "Returns nil when nothing is found"
(is (nil? (helpers/find-where (partial = 2) (range 2))))))
(deftest add-classes
(testing "Should add classes to a simple hiccup keyword"
(is (= :div.foo (helpers/add-classes :div :foo)))
(is (= :div.bar.bar (helpers/add-classes :div.bar :bar)))
(is (= :div.foo.bar (helpers/add-classes :div.foo :bar))))
(testing "Should add classes to the innermost child of a nested hiccup element"
(is (= :p>input.input (helpers/add-classes :p>input :input)))
(is (= :div.field>p>input.input.has-background-red (helpers/add-classes :div.field>p>input.input :has-background-red)))))