Init forms
This commit is contained in:
parent
9949912e41
commit
19ab90bc98
3 changed files with 59 additions and 2 deletions
|
@ -23,7 +23,8 @@
|
|||
(:file "nav-tab")
|
||||
(:file "pagination")
|
||||
(:file "table")
|
||||
(:file "spinner")))
|
||||
(:file "spinner")
|
||||
(:file "form")))
|
||||
(:module "examples"
|
||||
:components
|
||||
((:file "album"))))
|
||||
|
@ -52,6 +53,7 @@
|
|||
(:file "dropdown")
|
||||
(:file "list-group")
|
||||
(:file "navbar")
|
||||
(:file "nav-tab"))))
|
||||
(:file "nav-tab")
|
||||
(:file "form"))))
|
||||
:description "Test system for cl-sbt"
|
||||
:perform (test-op (op c) (symbol-call :rove :run c)))
|
||||
|
|
15
src/component/form.lisp
Normal file
15
src/component/form.lisp
Normal file
|
@ -0,0 +1,15 @@
|
|||
(defpackage cl-sbt/form
|
||||
(:use
|
||||
:cl)
|
||||
(:export
|
||||
:form-ctrl))
|
||||
|
||||
(in-package :cl-sbt/form)
|
||||
|
||||
(defmacro form-ctrl (&rest rest)
|
||||
`(spinneret:with-html
|
||||
,@(loop for item in rest
|
||||
collect (destructuring-bind (&key id label type placeholder) item
|
||||
`(progn
|
||||
(:label :for ,id :class "form-label" ,label)
|
||||
(:input :type ,type :class "form-control" :id ,id :placeholder ,placeholder))))))
|
40
tests/component/form.lisp
Normal file
40
tests/component/form.lisp
Normal file
|
@ -0,0 +1,40 @@
|
|||
(defpackage cl-sbt/tests/form
|
||||
(:use
|
||||
:cl
|
||||
:cl-sbt
|
||||
:rove)
|
||||
(:import-from
|
||||
:cl-sbt/form
|
||||
:form-ctrl))
|
||||
|
||||
(in-package :cl-sbt/tests/form)
|
||||
|
||||
(deftest test-simple-form-control
|
||||
(let ((result (spinneret:with-html-string (form-ctrl (:id "exampleFormControlInput1" :label "Email address" :type "email" :placeholder "name@example.com")))))
|
||||
(testing "Generates correct HTML for a simple form"
|
||||
(ok (search "for=exampleFormControlInput1" result))
|
||||
(ok (search "class=form-label" result))
|
||||
(ok (search "type=email" result))
|
||||
(ok (search "class=form-control" result))
|
||||
(ok (search "id=exampleFormControlInput1" result))
|
||||
(ok (search "placeholder=name@example.com" result)))))
|
||||
|
||||
(deftest test-simple-form-control-2
|
||||
(let ((result (spinneret:with-html-string (form-ctrl
|
||||
(:id "exampleFormControlInput1"
|
||||
:label "Email address"
|
||||
:type "email"
|
||||
:placeholder "name@example.com")
|
||||
(:id "form1"
|
||||
:label "Another Form"
|
||||
:type "email"
|
||||
:placeholder "name@example.com")))))
|
||||
(testing "Generates correct HTML for a simple form with more than one entries"
|
||||
(ok (search "for=exampleFormControlInput1" result))
|
||||
(ok (search "class=form-label" result))
|
||||
(ok (search "type=email" result))
|
||||
(ok (search "class=form-control" result))
|
||||
(ok (search "id=exampleFormControlInput1" result))
|
||||
(ok (search "placeholder=name@example.com" result))
|
||||
(ok (search "for=form1" result))
|
||||
(ok (search "Another Form" result)))))
|
Loading…
Add table
Reference in a new issue