-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.clj
More file actions
85 lines (84 loc) · 3.63 KB
/
html.clj
File metadata and controls
85 lines (84 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(ns net.thegeez.snippetlist.html
(:require [clojure.test :refer [deftest is]]
[io.pedestal.log :as log]
[net.cgrand.enlive-html :as html]
[net.thegeez.w3a.test :as w3a-test :refer [follow at?]]
[kerodon.core :as k]
[kerodon.test :as t]
[peridot.core :as p]
[net.thegeez.snippetlist.test-core :as test-core]))
(deftest snippet
(-> (k/session (test-core/ring-handler))
(p/header "Accept" "text/html")
(k/visit "/")
(follow "/snippets")
(k/within [:#content]
(t/has (t/link? "http://testhost:-1/snippets/new"))
(t/has (t/link? "http://testhost:-1/snippets/1"))
(t/has (t/link? "http://testhost:-1/snippets/2")))
(follow "http://testhost:-1/snippets/new")
(k/follow-redirect)
(at? "/login")
(k/within [:div#flash-info]
(t/has (t/text? "You need to be logged in for that action.")))
(k/within [[:form (html/attr= :action "http://testhost:-1/login?next=http%3A%2F%2Ftesthost%3A-1%2Fsnippets%2Fnew")]]
(k/fill-in "Username" "amy")
(k/fill-in "Password" "amy")
(k/press "Login"))
(k/follow-redirect)
(at? "/snippets/new")
(k/within [:ul.breadcrumb]
(k/within [[:li html/first-of-type]]
(t/has (t/link? "Home" "http://testhost:-1/")))
(k/within [[:li (html/nth-of-type 2)]]
(t/has (t/link? "Snippets" "http://testhost:-1/snippets"))))
(k/within [(html/left [:label (html/attr= :for "snippet[owner_username]")])]
(t/has (t/text? "amy")))
(k/press "Create new snippet")
(at? "/snippets")
(k/within [:#flash-error]
(t/has (t/text? "Creating snippet failed")))
(k/within [[:form (html/attr= :action "http://testhost:-1/snippets")]]
(k/within [:span.help-block]
(t/has (t/text? "Code can't be empty"))))
(k/fill-in "Code" "Amy's new snippet")
(k/check "Fast")
(k/check "Good")
(k/check "Cheap")
(k/press "Create new snippet")
(at? "/snippets")
(k/within [(html/lefts [:label (html/attr= :for "snippet[quality]")])
:span.help-block]
(t/has (t/text? "Sorry, you can only select up to 2 qualities")))
(k/uncheck "Good")
(k/press "Create new snippet")
(k/follow-redirect)
(k/within [:#flash-info]
(t/has (t/text? "Snippet inserted")))
(k/within [(html/left [:label (html/has [(html/text-pred #{"Code"})])]) :p]
(t/has (t/text? "Amy's new snippet")))
(k/within [(html/left [:label (html/has [(html/text-pred #{"Quality"})])]) :p]
(t/has (t/text? "#{:fast :cheap}")))
(follow "http://testhost:-1/snippets/102/edit")
(k/fill-in "Code" "Amy's edited snippet")
(k/press "Edit")
(k/follow-redirect)
(at? "/snippets/102")
(k/within [:#flash-info]
(t/has (t/text? "Snippet updated")))
(k/within [(html/left [:label (html/has [(html/text-pred #{"Code"})])]) :p]
(t/has (t/text? "Amy's edited snippet")))
(follow "Snippets")
(at? "/snippets")
(follow "11")
(at? "/snippets?page=11")
(k/within [(html/lefts [:td.id (html/has [(html/text-pred #{"102"})])])
:form]
(k/press "Delete"))
(k/follow-redirect)
(at? "/snippets")
(k/within [:#flash-info]
(t/has (t/text? "Snippet deleted")))
(k/visit "/snippets/102")
(t/has (t/text? "Not found"))
))