Test adding recipes
This commit is contained in:
parent
a58832da22
commit
7998b205d6
2 changed files with 57 additions and 29 deletions
|
@ -9,28 +9,17 @@
|
|||
(defn set-chromedriver-path! []
|
||||
(System/setProperty "webdriver.chrome.driver" "bin/chromedriver"))
|
||||
|
||||
(defn add-grub [driver grub-text]
|
||||
(taxi/input-text driver "#add-grub-input" grub-text)
|
||||
(taxi/click driver {:text "Add"}))
|
||||
|
||||
(defn get-driver [url]
|
||||
(webdriver/start {:browser :chrome} url))
|
||||
|
||||
(defn get-rand-grub []
|
||||
(str "testgrub" (rand-int 10000)))
|
||||
|
||||
(defn test-adding-synced-grubs [url driver1 driver2]
|
||||
(taxi/to driver1 url)
|
||||
(taxi/to driver2 url)
|
||||
(let [grubs (repeatedly 4 get-rand-grub)]
|
||||
(doseq [grub grubs]
|
||||
(add-grub driver1 grub))
|
||||
(doseq [grub grubs]
|
||||
(test/is (taxi/find-element driver2 {:text grub})
|
||||
"Added grubs should appear in other browser")))
|
||||
(db/clear-grubs))
|
||||
(defn add-grub [driver grub-text]
|
||||
(taxi/input-text driver "#add-grub-input" grub-text)
|
||||
(taxi/click driver {:text "Add"}))
|
||||
|
||||
(defn test-grubs-are-stored-on-server [url driver]
|
||||
(defn test-grubs-saved-to-server [url driver]
|
||||
(taxi/to driver url)
|
||||
(let [grubs (repeatedly 4 get-rand-grub)]
|
||||
(doseq [grub grubs]
|
||||
|
@ -42,7 +31,41 @@
|
|||
(test/is (taxi/find-element driver {:text grub})
|
||||
"Previously added grubs should be loaded on refresh")))
|
||||
(db/clear-grubs))
|
||||
|
||||
|
||||
(defn test-added-grubs-sync [url driver1 driver2]
|
||||
(taxi/to driver1 url)
|
||||
(taxi/to driver2 url)
|
||||
(let [grubs (repeatedly 4 get-rand-grub)]
|
||||
(doseq [grub grubs]
|
||||
(add-grub driver1 grub))
|
||||
(doseq [grub grubs]
|
||||
(test/is (taxi/find-element driver2 {:text grub})
|
||||
"Added grubs should appear in other browser"))))
|
||||
|
||||
(defn get-rand-recipe []
|
||||
{:name (str "recipe" (rand-int 10000))
|
||||
:grubs "grubs\nstuff\nmorestuff"})
|
||||
|
||||
(defn add-recipe [driver {:keys [name grubs]}]
|
||||
(taxi/click driver "#new-recipe-name")
|
||||
(taxi/input-text driver "#new-recipe-name" name)
|
||||
(taxi/input-text driver "#new-recipe-grubs" grubs)
|
||||
(taxi/click driver {:text "Done"}))
|
||||
|
||||
(defn test-added-recipes-sync [url driver1 driver2]
|
||||
(taxi/to driver1 url)
|
||||
(taxi/to driver2 url)
|
||||
(let [recipes (repeatedly 4 get-rand-recipe )]
|
||||
(doseq [recipe recipes]
|
||||
(add-recipe driver2 recipe))
|
||||
(doseq [{:keys [name]} recipes]
|
||||
(test/is (taxi/find-element driver2 {:text name})
|
||||
"Added recipes should appear in other browser"))))
|
||||
|
||||
(defn run-tests [site-url driver1 driver2]
|
||||
(test-grubs-saved-to-server site-url driver1)
|
||||
(test-added-grubs-sync site-url driver1 driver2)
|
||||
(test-added-recipes-sync site-url driver1 driver2))
|
||||
|
||||
(defn run [port]
|
||||
(set-chromedriver-path!)
|
||||
|
@ -52,8 +75,7 @@
|
|||
(ws/pass-received-events-to-clients-and-db db-chan)
|
||||
(let [driver1 (get-driver site-url)
|
||||
driver2 (get-driver site-url)]
|
||||
(test-grubs-are-stored-on-server site-url driver1)
|
||||
(test-adding-synced-grubs site-url driver1 driver2)
|
||||
(run-tests site-url driver1 driver2)
|
||||
(taxi/quit driver1)
|
||||
(taxi/quit driver2)))
|
||||
(db/clear-grubs))
|
||||
|
|
|
@ -43,9 +43,7 @@
|
|||
:key id}
|
||||
[:div.panel-heading.recipe-header
|
||||
[:input.form-control.recipe-header-input
|
||||
{:id "recipe-name"
|
||||
:type "text"
|
||||
:placeholder "Grub pie"
|
||||
{:type "text"
|
||||
:value name}]
|
||||
[:button.btn.btn-primary.btn-sm.recipe-add-grubs-btn
|
||||
{:type "button"
|
||||
|
@ -53,9 +51,7 @@
|
|||
"Add Grubs"]]
|
||||
[:div.panel-body.recipe-grubs.hidden
|
||||
[:textarea.form-control.recipe-grubs-input
|
||||
{:id "recipe-grubs"
|
||||
:rows 3
|
||||
:placeholder "2 grubs"
|
||||
{:rows 3
|
||||
:value grubs}]
|
||||
[:button.btn.btn-primary.hidden.pull-right.recipe-btn.recipe-done-btn
|
||||
{:type "button"} "Save"]]])))))
|
||||
|
@ -155,27 +151,30 @@
|
|||
{:on-click #(put! >local-events :click)}
|
||||
[:div.panel-heading.recipe-header
|
||||
[:input.form-control.recipe-header-input
|
||||
{:type "text"
|
||||
{:id "new-recipe-name"
|
||||
:type "text"
|
||||
:placeholder "New recipe"
|
||||
:value new-recipe-name
|
||||
:on-change #(om/set-state! owner :new-recipe-name (dom/event-val %))}]]
|
||||
[:div.panel-body.recipe-grubs
|
||||
{:class (when (not editing) "hidden")}
|
||||
[:textarea.form-control.recipe-grubs-input
|
||||
{:id "recipe-grubs"
|
||||
{:id "new-recipe-grubs"
|
||||
:rows 3
|
||||
:placeholder "Recipe ingredients"
|
||||
:value new-recipe-grubs
|
||||
:on-change #(om/set-state! owner :new-recipe-grubs (dom/event-val %))}]
|
||||
[:button.btn.btn-primary.pull-right.recipe-btn.recipe-done-btn
|
||||
{:type "button"
|
||||
:on-click #(add-recipe add new-recipe-name new-recipe-grubs owner)}
|
||||
:on-click #(put! >local-events :done)}
|
||||
"Done"]]])))
|
||||
|
||||
om/IWillMount
|
||||
(will-mount [_]
|
||||
(let [<local-events (om/get-state owner :<local-events)
|
||||
<events (om/get-shared owner :<events)]
|
||||
<events (om/get-shared owner :<events)
|
||||
add (om/get-shared owner :recipe-add)
|
||||
]
|
||||
(go-loop []
|
||||
(let [subscriber (chan)]
|
||||
(a/sub <local-events :click subscriber)
|
||||
|
@ -185,12 +184,19 @@
|
|||
(om/set-state! owner :editing true)
|
||||
(let [subscriber (chan)]
|
||||
(a/sub <events :body-mousedown subscriber)
|
||||
(a/sub <local-events :done subscriber)
|
||||
(loop []
|
||||
(let [event (<! subscriber)]
|
||||
(when (and (= (:type event) :body-mousedown)
|
||||
(if-not (and (= (:type event) :body-mousedown)
|
||||
(dom/click-on-self? (:event event) (om/get-node owner)))
|
||||
(when (= event :done)
|
||||
(add-recipe add
|
||||
(om/get-state owner :new-recipe-name)
|
||||
(om/get-state owner :new-recipe-grubs)
|
||||
owner))
|
||||
(recur))))
|
||||
(a/unsub <events :body-mousedown subscriber)
|
||||
(a/unsub <local-events :done subscriber)
|
||||
(a/close! subscriber))
|
||||
(om/set-state! owner :editing false)
|
||||
(recur))))))
|
||||
|
|
Loading…
Reference in a new issue