2013-08-18 08:22:08 +00:00
|
|
|
(ns grub.integration-test
|
2013-08-18 11:36:16 +00:00
|
|
|
(:require [grub.db :as db]
|
|
|
|
[clj-webdriver.taxi :as taxi]
|
2013-08-18 08:22:08 +00:00
|
|
|
[clj-webdriver.core :as webdriver]
|
|
|
|
[clojure.test :as test]))
|
|
|
|
|
2013-08-18 11:11:05 +00:00
|
|
|
(def site-url "http://localhost:3000")
|
|
|
|
|
2013-08-18 08:22:08 +00:00
|
|
|
(defn add-grub [driver grub-text]
|
|
|
|
(taxi/input-text driver "#add-grub-input" grub-text)
|
|
|
|
(taxi/click driver {:text "Add"}))
|
|
|
|
|
2013-08-18 11:11:05 +00:00
|
|
|
(defn get-driver [url]
|
|
|
|
(webdriver/start {:browser :chrome} url))
|
2013-08-18 08:22:08 +00:00
|
|
|
|
|
|
|
(defn get-rand-grub []
|
|
|
|
(str "testgrub" (rand-int 10000)))
|
|
|
|
|
2013-08-18 11:11:05 +00:00
|
|
|
(defn test-adding-grubs [url driver1 driver2]
|
|
|
|
(taxi/to driver1 url)
|
|
|
|
(taxi/to driver2 url)
|
2013-08-18 08:22:08 +00:00
|
|
|
(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})
|
2013-08-18 11:36:16 +00:00
|
|
|
"Added grubs should appear in other browser")))
|
|
|
|
(db/clear-grubs))
|
2013-08-18 08:22:08 +00:00
|
|
|
|
2013-08-18 11:11:05 +00:00
|
|
|
(defn test-grubs-are-stored-on-server [url driver]
|
|
|
|
(taxi/to driver url)
|
|
|
|
(let [grubs (repeatedly 4 get-rand-grub)]
|
|
|
|
(doseq [grub grubs]
|
|
|
|
(add-grub driver grub))
|
2013-08-18 11:36:16 +00:00
|
|
|
(Thread/sleep 200)
|
2013-08-18 11:11:05 +00:00
|
|
|
(taxi/refresh driver)
|
2013-08-18 11:36:16 +00:00
|
|
|
(Thread/sleep 200)
|
2013-08-18 11:11:05 +00:00
|
|
|
(doseq [grub grubs]
|
|
|
|
(test/is (taxi/find-element driver {:text grub})
|
2013-08-18 11:36:16 +00:00
|
|
|
"Previously added grubs should be loaded on refresh")))
|
|
|
|
(db/clear-grubs))
|
2013-08-18 11:11:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defn run [port]
|
2013-08-18 11:36:16 +00:00
|
|
|
(db/connect-and-handle-events "grub-integration-test")
|
2013-08-18 11:11:05 +00:00
|
|
|
(let [site-url (str "http://localhost:" port)]
|
|
|
|
(println "Starting integration test")
|
|
|
|
(let [driver1 (get-driver site-url)
|
|
|
|
driver2 (get-driver site-url)]
|
|
|
|
(test-adding-grubs site-url driver1 driver2)
|
|
|
|
(test-grubs-are-stored-on-server site-url driver1)
|
|
|
|
(taxi/quit driver1)
|
2013-08-18 11:36:16 +00:00
|
|
|
(taxi/quit driver2)))
|
|
|
|
(db/clear-grubs))
|