| 1 | (in-package :lol-test) |
| 2 | |
| 3 | (defclass lol-test-server (ucw-core:standard-server) |
| 4 | ()) |
| 5 | |
| 6 | (defclass lol-test-application (ucw:standard-application) |
| 7 | () |
| 8 | (:default-initargs |
| 9 | :url-prefix "/lisp-on-lines.test/" |
| 10 | ; :www-roots (list (cons "static/" (project-relative-pathname #P"wwwroot/"))) |
| 11 | )) |
| 12 | |
| 13 | (defparameter *lol-test-ucw-application* (make-instance 'lol-test-application)) |
| 14 | |
| 15 | (defun make-backend () |
| 16 | (ucw::make-backend |
| 17 | :httpd |
| 18 | :host "localhost" |
| 19 | :port 9090)) |
| 20 | |
| 21 | (defun make-server () |
| 22 | (make-instance |
| 23 | 'lol-test-server |
| 24 | :backend (make-backend))) |
| 25 | |
| 26 | (defparameter *lol-test-ucw-server* (make-server)) |
| 27 | |
| 28 | (ucw-core:register-application *lol-test-ucw-server* *lol-test-ucw-application*) |
| 29 | |
| 30 | (ucw-core:defentry-point "index.ucw" (:application *lol-test-ucw-application*) () |
| 31 | (call 'lol-test-window)) |
| 32 | |
| 33 | (defun startup-lol-ucw-test () |
| 34 | (ucw-core:startup-server *lol-test-ucw-server*)) |
| 35 | |
| 36 | (defun shutdown-lol-ucw-test () |
| 37 | (ucw-core:shutdown-server *lol-test-ucw-server*)) |
| 38 | |
| 39 | (ucw-core:defcomponent lol-test-window (standard-window-component) |
| 40 | () |
| 41 | (:default-initargs |
| 42 | :body (make-instance 'lol-test-suite-component))) |
| 43 | |
| 44 | (define-symbol-macro $window (ucw-core:context.window-component *context*)) |
| 45 | |
| 46 | (define-symbol-macro $body (window-body $window)) |
| 47 | |
| 48 | (ucw-core:defcomponent lol-test-suite-component () |
| 49 | ((test :component lol-test-simple-action :accessor test) |
| 50 | (component :component lol-test-render :accessor component))) |
| 51 | |
| 52 | (define-symbol-macro $test (test $body)) |
| 53 | |
| 54 | (define-symbol-macro $component (component $body)) |
| 55 | |
| 56 | (defmethod ucw-core:render ((self lol-test-suite-component)) |
| 57 | (<:H1 "Lisp On Lines Web test suite") |
| 58 | (render (slot-value self 'test)) |
| 59 | (<:div |
| 60 | :style "border:1px solid black;" |
| 61 | (render (slot-value self 'component)))) |
| 62 | |
| 63 | (ucw-core:defcomponent lol-test-render () |
| 64 | ((message :initform "test" :accessor message :initarg :message))) |
| 65 | |
| 66 | (defmethod ucw-core:render ((self lol-test-render)) |
| 67 | (<:h3 :id "test-render" |
| 68 | (<:as-html (format nil "Hello ~A." (message self))))) |
| 69 | |
| 70 | (ucw-core:defcomponent lol-test-simple-action () |
| 71 | ()) |
| 72 | |
| 73 | (defmethod ucw-core:render ((self lol-test-simple-action)) |
| 74 | (<:ul |
| 75 | (<:li (<ucw:a |
| 76 | :function |
| 77 | (lambda () |
| 78 | (setf (message $component) |
| 79 | (format nil "~A : ~A" (message $component) "FUNCTION"))) |
| 80 | "Test <:A :FUNCTION type actions")) |
| 81 | (<:li |
| 82 | (<ucw:a |
| 83 | :action (setf (message $component) |
| 84 | (format nil "~A : ~A" (message $component) "ACTION")) |
| 85 | "Test <:A :ACTION type actions")) |
| 86 | (<:li |
| 87 | (<ucw:a |
| 88 | :action* (make-action |
| 89 | (lambda () |
| 90 | (setf (message $component) |
| 91 | (format nil "~A : ~A" (message $component) "ACTION*")))) |
| 92 | "Test <:A :ACTION* type actions")) |
| 93 | (<:li |
| 94 | (<ucw:a |
| 95 | :action (call-component $component (make-instance 'lol-test-answer)) |
| 96 | "Test CALL-COMPONENT/ANSWER-COMPONENT")) |
| 97 | (<:li |
| 98 | (<ucw:a |
| 99 | :action (call-component $component (make-instance 'lol-test-call-magic)) |
| 100 | "Test CALL/ANSWER MAGIC")) |
| 101 | (<:li |
| 102 | (<ucw:a |
| 103 | :action (call-component $component (make-instance 'lol-test-call-answer-action-magic)) |
| 104 | "Test CALL/ANSWER ACTION MAGIC")) |
| 105 | (<:li |
| 106 | (<ucw:a |
| 107 | :action (call-component $component (make-instance 'lol-test-simple-form)) |
| 108 | "Test Simple Form")) |
| 109 | (<:li |
| 110 | (<ucw:a |
| 111 | :action (call-component $component (make-instance 'lol-test-multi-submit-form)) |
| 112 | "Test Multi Form")) |
| 113 | (<:li |
| 114 | (<ucw:a |
| 115 | :action (call-component $component (make-instance 'lol-test-input)) |
| 116 | "Test Form input")) |
| 117 | )) |
| 118 | |
| 119 | (ucw-core:defcomponent lol-test-answer (lol-test-render) () |
| 120 | (:default-initargs :message "CALL was ok. Go Back will answer")) |
| 121 | |
| 122 | (defmethod ucw-core:render :wrapping ((self lol-test-answer)) |
| 123 | (call-next-method) |
| 124 | (<ucw:a :action (answer-component self nil) "Go Back.")) |
| 125 | |
| 126 | (ucw-core:defcomponent lol-test-simple-form (lol-test-render) () |
| 127 | (:default-initargs :message "Testing Simple Form:")) |
| 128 | |
| 129 | (defmethod ucw-core:render :wrapping ((self lol-test-simple-form)) |
| 130 | (call-next-method) |
| 131 | (<ucw:form |
| 132 | :action (setf (message self) "Form Submitted") |
| 133 | (<:submit)) |
| 134 | (<ucw:a :action (answer-component self nil) "Go Back.")) |
| 135 | |
| 136 | (ucw-core:defcomponent lol-test-multi-submit-form (lol-test-render) () |
| 137 | (:default-initargs :message "Testing Simple Form:")) |
| 138 | |
| 139 | (defmethod ucw-core:render :wrapping ((self lol-test-multi-submit-form)) |
| 140 | (call-next-method) |
| 141 | (<ucw:form |
| 142 | :action (setf (message self) "Form Submitted") |
| 143 | (<:submit) |
| 144 | (<ucw:submit :action (setf (message self) "Submit 2" ) |
| 145 | :value "2") |
| 146 | (<ucw:submit :action (setf (message self) "Submit 3") |
| 147 | 3)) |
| 148 | (<ucw:a :action (answer-component self nil) "Go Back.")) |
| 149 | |
| 150 | (ucw-core:defcomponent lol-test-input (lol-test-render) |
| 151 | () |
| 152 | (:default-initargs :message "Testing INPUTS")) |
| 153 | |
| 154 | (defmethod ucw-core:render :wrapping ((self lol-test-input)) |
| 155 | (call-next-method) |
| 156 | (<ucw:form |
| 157 | :function (constantly t) |
| 158 | (<ucw:input :type "text" :accessor (message self)) |
| 159 | |
| 160 | (<:submit) |
| 161 | ) |
| 162 | (<ucw:a :action (answer-component self nil) "Go Back.")) |
| 163 | |
| 164 | |
| 165 | |
| 166 | (ucw-core:defcomponent lol-test-call-magic (lol-test-render) |
| 167 | () |
| 168 | (:default-initargs :message "Testing CALL magic.")) |
| 169 | |
| 170 | (defmethod ucw-core:render :wrapping ((self lol-test-call-magic)) |
| 171 | (call-next-method) |
| 172 | (<ucw:a :action (setf (message self) (call 'lol-test-answer-magic)) "Test CALL") |
| 173 | (<:br) |
| 174 | (<ucw:a :action (answer-component self nil) "Go Back.")) |
| 175 | |
| 176 | |
| 177 | |
| 178 | (ucw-core:defcomponent lol-test-answer-magic (lol-test-render) |
| 179 | () |
| 180 | (:default-initargs :message "Hit it to answer")) |
| 181 | |
| 182 | (defmethod ucw-core:render :wrapping ((self lol-test-answer-magic)) |
| 183 | (call-next-method) |
| 184 | |
| 185 | (<ucw:a :action (answer "Ja, dat is vut ve answer" ) "IT! (hit here)")) |
| 186 | |
| 187 | (ucw-core:defcomponent lol-test-call-answer-action-magic (lol-test-render) |
| 188 | () |
| 189 | (:default-initargs :message "Hit it to answer")) |
| 190 | |
| 191 | (ucw:defaction test-call-component () |
| 192 | (call 'lol-test-call-answer-action-magic :message "We made it")) |
| 193 | |
| 194 | (ucw:defaction test-answer-component () |
| 195 | (answer "We Made IT BACK!!!")) |
| 196 | |
| 197 | (defmethod ucw-core:render :wrapping ((self lol-test-call-answer-action-magic)) |
| 198 | (call-next-method) |
| 199 | (<ucw:a :action (test-call-component) "Test CALL from ACTION") |
| 200 | (<:br) |
| 201 | (<ucw:a :action (test-answer-component) "Test ANSWER from ACTION")) |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |