/ test-parenscript.lisp
test-parenscript.lisp
1 ;;;; test-parenscript.lisp - Test ParenScript compilation 2 3 (ql:quickload :parenscript) 4 5 (defun test-auth-ui-compilation () 6 "Test compiling the auth-ui ParenScript to JavaScript" 7 (let ((js-code 8 (ps:ps 9 ;; Check if user is logged in by calling the API 10 (defun check-auth-status () 11 (ps:chain 12 (fetch "/api/asteroid/auth-status") 13 (then (lambda (response) 14 (ps:chain response (json)))) 15 (then (lambda (result) 16 ;; api-output wraps response in {status, message, data} 17 (let ((data (or (ps:@ result data) result))) 18 data))) 19 (catch (lambda (error) 20 (ps:chain console (error "Error checking auth status:" error)) 21 (ps:create :logged-in false 22 :is-admin false))))) 23 24 ;; Update UI based on authentication status 25 (defun update-auth-ui (auth-status) 26 ;; Show/hide elements based on login status 27 (ps:chain document 28 (query-selector-all "[data-show-if-logged-in]") 29 (for-each (lambda (el) 30 (setf (ps:@ el style display) 31 (if (ps:@ auth-status logged-in) 32 "inline-block" 33 "none"))))) 34 35 (ps:chain document 36 (query-selector-all "[data-show-if-logged-out]") 37 (for-each (lambda (el) 38 (setf (ps:@ el style display) 39 (if (ps:@ auth-status logged-in) 40 "none" 41 "inline-block"))))) 42 43 (ps:chain document 44 (query-selector-all "[data-show-if-admin]") 45 (for-each (lambda (el) 46 (setf (ps:@ el style display) 47 (if (ps:@ auth-status is-admin) 48 "inline-block" 49 "none")))))) 50 51 ;; Initialize auth UI on page load 52 (ps:chain document 53 (add-event-listener 54 "DOMContentLoaded" 55 (async lambda () 56 (ps:chain console (log "Auth UI initializing...")) 57 (let ((auth-status (await (check-auth-status)))) 58 (ps:chain console (log "Auth status:" auth-status)) 59 (update-auth-ui auth-status) 60 (ps:chain console (log "Auth UI updated"))))))))) 61 62 (format t "~%Generated JavaScript:~%~%") 63 (format t "~a~%" js-code) 64 (format t "~%~%") 65 66 ;; Write to file for comparison 67 (with-open-file (out "/home/glenn/Projects/Code/asteroid/static/js/auth-ui-generated.js" 68 :direction :output 69 :if-exists :supersede) 70 (write-string js-code out)) 71 72 (format t "Wrote generated JavaScript to: static/js/auth-ui-generated.js~%"))) 73 74 ;; Run the test 75 (test-auth-ui-compilation)