/hipper

Hiccup zipper conversion and searching

Primary LanguageClojureEclipse Public License 1.0EPL-1.0

hipper

A Clojurescript library to help test hiccup style (hiccup, sablono, crate, etc...) forms. Unlike some other libraries this is done directly on the hiccup forms without turning them into a dom. This is accomplished by first turning the form into a zipper. The search namespace then takes expressions which will walk and match a hiccup zipper.

Usage

;; Check that my component has: 
;;     a child div, 
;;     with a child ul with an id of my-list, 
;;     followed by some number of li with a class of special
(deftest render-widget
  (testing "My widget has the correct number of entries"
     (is (= 5 (count (s/search (render-widget data) [:div :ul#my-list :li.special]))))))
; the above form is shorthand for:
[child(:div) child(:ul#my-list) child(:li.special)]

;; Directly check that some where in the result are 5 li elements
;; with a class of special
(deftest render-widget
  (testing "My widget has the correct number of entries"
     (is (= 5 (count (s/search (render-widget data) [descendent(:li.special)]))))))

;; Same as above but use an attribute map instead of a hiccup form
(deftest render-widget
  (testing "My widget has the correct number of entries"
     (is (= 5 (count (s/search (render-widget data) [descendent({:tag "li" :classes ["special"]})]))))))

The forms passed to the search function have two parts: a predicate & an axis.

An axis takes the current set of nodes and determines which nodes to search. Examples include self, child, & descendents. The default axis if none are specified is child.

A predicate takes the node list generated by the axis and filters it down to matching nodes. A predicate can be a map of attributes or a hiccup style keyword which will be expanded and matched.

Forms passed to search are reduced, where the set of nodes matched from the first node is passed as the input to the next forms axis & predicate.

Check out the hipper.search namespace for more search options.

License

Copyright © 2015 119 Labs LLC

Distributed under the Eclipse Public License either version 1.0 or any later version.