From 27f46a24f93bc4d4f3e5d4e32eae60ba930bfebf Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Wed, 26 Jul 2023 16:41:35 +0200 Subject: [PATCH] Fullfill tests for grid --- src/layout/grid.lisp | 10 ++++++---- tests/layout/grid.lisp | 22 +++++++++++++--------- tests/utility.lisp | 7 ++++++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/layout/grid.lisp b/src/layout/grid.lisp index 3633007..fb463b8 100644 --- a/src/layout/grid.lisp +++ b/src/layout/grid.lisp @@ -110,7 +110,7 @@ Examples: ""))) (concatenate 'string size-string offset-string))) -(defun breakpoint-class (&key (kind :con) (xs nil) (sm nil) (md nil) (lg nil) (xl nil) (xxl nil)) +(defun breakpoint-class (&key (kind "con") (xs nil) (sm nil) (md nil) (lg nil) (xl nil) (xxl nil)) "Generates Bootstrap class string for different kinds of elements across breakpoints. The KIND argument specifies the type of element for which the classes are generated. @@ -140,6 +140,8 @@ Examples: (breakpoint-class :kind :con :xs t :sm t :md t :lg t :xl t :xxl t) ; will generate a string for a fluid container that spans all breakpoints." + (assert (and kind + (or xs sm md lg xl xxl))) (let ((breakpoint-values (list xs sm md lg xl xxl))) (string-clean (apply #'concatenate 'string @@ -148,9 +150,9 @@ Examples: for breakpoint-value = (nth i breakpoint-values) collect (cond - ((eq kind :con) (make-con-class breakpoint-name breakpoint-value)) - ((eq kind :row) (make-row-class breakpoint-name breakpoint-value)) - ((eq kind :col) (make-col-class breakpoint-name breakpoint-value)))))))) + ((equal kind "con") (make-con-class breakpoint-name breakpoint-value)) + ((equal kind "row") (make-row-class breakpoint-name breakpoint-value)) + ((equal kind "col") (make-col-class breakpoint-name breakpoint-value)))))))) (defmacro con ((&key (fluid nil) (breakpoint nil) (text nil) (spacing nil)) &body body) "Generates a Bootstrap container. diff --git a/tests/layout/grid.lisp b/tests/layout/grid.lisp index a19ff2a..1b0823c 100644 --- a/tests/layout/grid.lisp +++ b/tests/layout/grid.lisp @@ -77,23 +77,27 @@ (deftest test-breakpoint-class-con (testing "Generates correct class for container" - (ok (string= (breakpoint-class :kind :con :md t) "container-md")))) + (ok (string= (breakpoint-class :kind "con" :md t) "container-md")))) (deftest test-breakpoint-class-row (testing "Generates correct class for row" - (ok (string= (breakpoint-class :kind :row :sm 2 :md 3) "row-cols-sm-2 row-cols-md-3")))) + (ok (string= (breakpoint-class :kind "row" :sm 2 :md 3) "row-cols-sm-2 row-cols-md-3")))) (deftest test-breakpoint-class-col (testing "Generates correct class for column" - (ok (string= (breakpoint-class :kind :col :lg '(4 1)) "col-lg-4 offset-lg-1")))) + (ok (string= (breakpoint-class :kind "col" :lg '(4 1)) "col-lg-4 offset-lg-1")))) (deftest test-breakpoint-class-con-fluid (testing "Generates correct class for fluid container" - (ok (string= (breakpoint-class :kind :con :xs t :sm t :md t :lg t :xl t :xxl t) "container-xs container-sm container-md container-lg container-xl container-xxl")))) + (ok (string= (breakpoint-class :kind "con" :xs t :sm t :md t :lg t :xl t :xxl t) "container-xs container-sm container-md container-lg container-xl container-xxl")))) (deftest test-breakpoint-class-col-no-offset (testing "Generates correct class for column with no offset" - (ok (string= (breakpoint-class :kind :col :md '(3)) "col-md-3")))) + (ok (string= (breakpoint-class :kind "col" :md '(3)) "col-md-3")))) + +(deftest test-breakpoint-class-no-arguments + (testing "Asserts error is signaled for no arguments" + (ok (signals (breakpoint-class))))) (deftest test-con-fluid (let ((result (spinneret:with-html-string (con (:fluid t))))) @@ -101,7 +105,7 @@ (ok (string= result "
"))))) (deftest test-con-breakpoint - (let ((result (spinneret:with-html-string (con (:breakpoint (:kind :con :md t)))))) + (let ((result (spinneret:with-html-string (con (:breakpoint (:kind "con" :md t)))))) (testing "Generates correct HTML for container with breakpoint" (ok (string= result "
"))))) @@ -111,7 +115,7 @@ (ok (string= result "
"))))) (deftest test-con-fluid-breakpoint-text - (let ((result (spinneret:with-html-string (con (:fluid t :breakpoint (:kind :con :sm t) :text (:weight "bold")))))) + (let ((result (spinneret:with-html-string (con (:fluid t :breakpoint (:kind "con" :sm t) :text (:weight "bold")))))) (testing "Generates correct HTML for fluid container with breakpoint and text utilities" (ok (string= result "
"))))) @@ -126,7 +130,7 @@ (ok (string= result "
"))))) (deftest test-row-breakpoint - (let ((result (spinneret:with-html-string (cl-sbt/grid:row (:breakpoint (:kind :row :sm 2)))))) + (let ((result (spinneret:with-html-string (cl-sbt/grid:row (:breakpoint (:kind "row" :sm 2)))))) (testing "Generates correct HTML when breakpoint is provided" (ok (string= result "
"))))) @@ -156,7 +160,7 @@ (ok (string= result "
"))))) (deftest test-col-breakpoint - (let ((result (spinneret:with-html-string (col (:breakpoint (:kind :col :md (8 2))))))) + (let ((result (spinneret:with-html-string (col (:breakpoint (:kind "col" :md (8 2))))))) (testing "Generates correct HTML for column with breakpoint" (ok (string= result "
"))))) diff --git a/tests/utility.lisp b/tests/utility.lisp index 73ca3c6..bf4b34e 100644 --- a/tests/utility.lisp +++ b/tests/utility.lisp @@ -181,7 +181,12 @@ (deftest test-text-all-arguments (testing "Generates correct text utility class with all arguments" - (ok (string= (text :alignment "center" :transform "uppercase" :weight "bolder" :wrap "nowrap" :monospace t) + (ok (string= (text + :alignment "center" + :transform "uppercase" + :weight "bolder" + :wrap "nowrap" + :monospace t) "text-center text-uppercase fw-bolder text-nowrap font-monospace")))) (deftest test-text-some-arguments