Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
280 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="js/integration.js"></script> | ||
<script>rid3.integration.main();</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(ns rid3.integration | ||
(:require | ||
[cljs.spec :as spec] | ||
[reagent.core :as reagent] | ||
[re-frisk.core :as rf] | ||
[rid3.core :as rid3])) | ||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Vars | ||
|
||
(defonce app-state (reagent/atom {})) | ||
|
||
|
||
(def height 100) | ||
(def width 100) | ||
|
||
(def margin {:top 16 | ||
:right 16 | ||
:bottom 16 | ||
:left 16}) | ||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Page | ||
|
||
(defn page [app-state] | ||
[:div | ||
[rid3/viz | ||
{:id "test1" | ||
:ratom app-state | ||
:svg {:did-mount (fn [node _] | ||
(-> node | ||
(.attr "height" (+ height | ||
(:top margin) | ||
(:bottom margin))) | ||
(.attr "width" (+ width | ||
(:left margin) | ||
(:right margin)))))} | ||
:main-container {:did-mount (fn [node _] | ||
(-> node | ||
(.attr "transform" | ||
(str "translate(" | ||
(:left margin) | ||
"," | ||
(:top margin) | ||
")"))))} | ||
:pieces [{:kind :elem | ||
:tag "rect" | ||
:class "my-elem" | ||
:did-mount (fn [node _] | ||
(-> node | ||
(.attr "width" width) | ||
(.attr "height" height) | ||
(.attr "fill" "grey")))} | ||
|
||
{:kind :elem-with-data | ||
:tag "rect" | ||
:class "my-elem-with-data" | ||
:prepare-dataset (fn [ratom] | ||
(clj->js ["A" "B" "C"])) | ||
:did-mount (fn [node _] | ||
(let [x-scale (-> js/d3 | ||
.scaleBand | ||
(.rangeRound #js [0 width]) | ||
(.domain (clj->js ["A" "B" "C"])))] | ||
(-> node | ||
(.attr "x" (fn [d] | ||
(+ (x-scale d) | ||
(/ (.bandwidth x-scale) 4)))) | ||
(.attr "width" (/ (.bandwidth x-scale) | ||
2)) | ||
(.attr "y" 0) | ||
(.attr "height" (fn [d i] | ||
(/ height (inc i)))) | ||
(.attr "fill" "green"))))}] | ||
}]]) | ||
|
||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Initialize App | ||
|
||
(defn dev-setup [] | ||
(when ^boolean js/goog.DEBUG | ||
(enable-console-print!) | ||
(println "dev mode") | ||
(rf/enable-frisk!) | ||
(rf/add-data :app-state app-state) | ||
(spec/check-asserts true))) | ||
|
||
(defn reload [] | ||
(reagent/render [page app-state] | ||
(.getElementById js/document "app"))) | ||
|
||
(defn ^:export main [] | ||
(dev-setup) | ||
(reload)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
(ns rid3.integration-test | ||
(:require | ||
[clojure.string :as string] | ||
[clojure.test :refer :all] | ||
[etaoin.api :refer :all])) | ||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Setup | ||
|
||
(def ^:dynamic | ||
*driver*) | ||
|
||
(defn fixture-driver | ||
"Executes a test running a driver. Bounds a driver | ||
with the global *driver* variable." | ||
[f] | ||
(with-chrome {:headless true} driver | ||
(binding [*driver* driver] | ||
(f)))) | ||
|
||
|
||
(use-fixtures | ||
:each ;; start and stop driver for each test | ||
fixture-driver) | ||
|
||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Vars | ||
|
||
(def url "http://localhost:3449/integration.html") | ||
|
||
(def screenshot-success-path "screenshots/success") | ||
(def screenshot-failure-path "screenshots/failure") | ||
|
||
(def desktop-env | ||
{:label "desktop" | ||
:width 1920 | ||
:height 1080}) | ||
|
||
(def mobile-env | ||
{:label "mobile" | ||
:width 337 | ||
:height 667}) | ||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Util | ||
|
||
(defn ->screenshot [driver env name] | ||
(screenshot driver | ||
(str screenshot-success-path | ||
"/" | ||
(get env :label) | ||
"_" | ||
name | ||
".png"))) | ||
|
||
|
||
(defn px [int] | ||
(when int | ||
(str int "px"))) | ||
|
||
|
||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Test | ||
|
||
(defn ->test1 [env] | ||
(testing "basic skeleton of a rid3 component" | ||
(with-postmortem *driver* {:dir screenshot-failure-path} | ||
(doto *driver* | ||
(set-window-size (get env :width) | ||
(get env :height)) | ||
(go url) | ||
(wait-visible {:id "test1"}) | ||
(->screenshot env "test1")) | ||
|
||
;; NOTE: | ||
;; a rid3 component has the following structure: | ||
|
||
;; div#id | ||
;; svg | ||
;; g.rid3-main-container | ||
;; [<pieces>] | ||
|
||
|
||
;; div#id | ||
(testing "should have div with id" | ||
(is (exists? *driver* {:css "div#test1"}))) | ||
|
||
;; svg | ||
(testing "should have svg as child of div with id" | ||
(is (exists? *driver* {:css "#test1 svg"}))) | ||
|
||
(testing "svg should have set dimensions" | ||
(is (= {:width 132 | ||
:height 132} (get-element-size *driver* {:css "#test1 svg"})))) | ||
|
||
;; g.rid3-main-container | ||
(testing "there should be a g tag with class rid3-main-container" | ||
(is (exists? *driver* {:css "#test1 svg g.rid3-main-container"}))) | ||
|
||
(testing "a rect piece should be inside the main-container" | ||
(is (exists? *driver* {:css (string/join " " | ||
["#test1" | ||
"svg" | ||
"g.rid3-main-container" | ||
"g.my-elem" | ||
"rect"])}))) | ||
|
||
;; [<pieces>] | ||
|
||
;; :elem | ||
(testing "a rect (:elem piece) should have set dimensions" | ||
(is (= {:width 100 | ||
:height 100} (get-element-size *driver* | ||
{:css (string/join " " | ||
["#test1" | ||
"svg" | ||
"g.rid3-main-container" | ||
"g.my-elem" | ||
"rect"])})))) | ||
|
||
;; elem-with-data | ||
(testing ":elem-with-data piece should create multiple rects inside its parent g" | ||
(let [rects (query-all *driver* | ||
{:css (string/join " " | ||
["#test1" | ||
"svg" | ||
"g.rid3-main-container" | ||
"g.my-elem-with-data" | ||
"rect"])})] | ||
(is (= 3 (count rects))) | ||
(doseq [rect rects] | ||
(is (= "rect" | ||
(get-element-tag-el *driver* rect)))))) | ||
|
||
|
||
))) | ||
|
||
|
||
(deftest ^:integration | ||
desktop-1920x1080 | ||
(->test1 desktop-env)) |