-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into qr-scanner
- Loading branch information
Showing
12 changed files
with
149 additions
and
87 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/quo/components/tags/collectible_tag/component_spec.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns quo.components.tags.collectible-tag.component-spec | ||
(:require | ||
[quo.components.tags.collectible-tag.view :as collectible-tag] | ||
[test-helpers.component :as h])) | ||
|
||
(def collectible-name "Collectible") | ||
(def collectible-id "#123") | ||
|
||
(defn get-test-data | ||
[{:keys [options blur? size]}] | ||
{:collectible-name collectible-name | ||
:collectible-id collectible-id | ||
:collectible-img-src {:uri "https://example.com/image.jpg"} | ||
:options options | ||
:blur? (or blur? false) | ||
:size (or size :size-24)}) | ||
|
||
(h/describe "Collectible_tag tests" | ||
(h/test "Renders Default option" | ||
(let [data (get-test-data {})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders Add option" | ||
(let [data (get-test-data {:options :add})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders Hold option" | ||
(let [data (get-test-data {:options :hold})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders with Blur" | ||
(let [data (get-test-data {:blur? true})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders without Blur" | ||
(let [data (get-test-data {:blur? false})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders with Size 24" | ||
(let [data (get-test-data {:size :size-24})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name)))) | ||
|
||
(h/test "Renders with Size 32" | ||
(let [data (get-test-data {:size :size-32})] | ||
(h/render-with-theme-provider [collectible-tag/view data]) | ||
(h/is-truthy (h/get-by-text collectible-name))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns quo.components.tags.collectible-tag.schema) | ||
|
||
(def ?schema | ||
[:=> | ||
[:catn | ||
[:props | ||
[:map | ||
[:options {:optional true} [:maybe [:enum :add :hold]]] | ||
[:size {:optional true} [:maybe [:enum :size-24 :size-32]]] | ||
[:blur? {:optional true} [:maybe :boolean]] | ||
[:theme :schema.common/theme] | ||
[:collectible-img-src :schema.common/image-source] | ||
[:collectible-name :string] | ||
[:collectible-id :string]]]] | ||
:any]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,59 @@ | ||
(ns quo.components.tags.collectible-tag.view | ||
(:require | ||
[oops.core :as oops] | ||
[quo.components.icon :as icons] | ||
[quo.components.markdown.text :as text] | ||
[quo.components.tags.collectible-tag.schema :as component-schema] | ||
[quo.components.tags.collectible-tag.style :as style] | ||
[quo.theme] | ||
[react-native.core :as rn] | ||
[react-native.hole-view :as hole-view] | ||
[reagent.core :as reagent] | ||
[schema.core :as schema])) | ||
|
||
(def ?schema | ||
[:=> | ||
[:catn | ||
[:props | ||
[:map {:closed true} | ||
[:options {:optional true} [:maybe [:enum false :add :hold]]] | ||
[:size {:optional true} [:enum :size-24 :size-32]] | ||
[:blur? {:optional true} :boolean] | ||
[:theme :schema.common/theme] | ||
[:collectible-img-src [:or :int :string]] | ||
[:collectible-name :string] | ||
[:collectible-id :string] | ||
[:container-width :number] | ||
[:on-layout {:optional true} [:maybe fn?]]]]] | ||
:any]) | ||
|
||
(defn- view-internal | ||
[] | ||
(fn [{:keys [options size blur? theme collectible-img-src collectible-name collectible-id | ||
container-width on-layout] | ||
:or {size :size-24}}] | ||
[rn/view | ||
{:on-layout on-layout} | ||
[hole-view/hole-view | ||
{:holes (if options | ||
[{:x (- container-width | ||
(case size | ||
:size-24 10 | ||
:size-32 12 | ||
nil)) | ||
:y (case size | ||
:size-24 -6 | ||
:size-32 -4 | ||
nil) | ||
:width 16 | ||
:height 16 | ||
:borderRadius 8}] | ||
[])} | ||
[rn/view {:style (style/container size options blur? theme)} | ||
[rn/image {:style (style/collectible-img size) :source collectible-img-src}] | ||
[text/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:style (style/label theme)} | ||
collectible-name] | ||
[text/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:margin-left 5 | ||
:style (style/label theme)} | ||
collectible-id]]] | ||
(when options | ||
[rn/view {:style (style/options-icon size)} | ||
[icons/icon (if (= options :hold) :i/hold :i/add-token) | ||
{:size 20 | ||
:no-color true}]])])) | ||
(let [container-width (reagent/atom 0) | ||
on-layout #(->> (oops/oget % :nativeEvent :layout :width) | ||
(reset! container-width))] | ||
(fn [{:keys [options blur? theme collectible-img-src collectible-name collectible-id] :as props}] | ||
(let [size (or (:size props) :size-24)] | ||
[rn/view | ||
{:on-layout on-layout} | ||
[hole-view/hole-view | ||
{:holes (if options | ||
[{:x (- @container-width | ||
(case size | ||
:size-24 10 | ||
:size-32 12 | ||
nil)) | ||
:y (case size | ||
:size-24 -6 | ||
:size-32 -4 | ||
nil) | ||
:width 16 | ||
:height 16 | ||
:borderRadius 8}] | ||
[])} | ||
[rn/view {:style (style/container size options blur? theme)} | ||
[rn/image {:style (style/collectible-img size) :source collectible-img-src}] | ||
[text/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:style (style/label theme)} | ||
collectible-name] | ||
[text/text | ||
{:size :paragraph-2 | ||
:weight :medium | ||
:margin-left 5 | ||
:style (style/label theme)} | ||
collectible-id]]] | ||
(when options | ||
[rn/view {:style (style/options-icon size)} | ||
[icons/icon (if (= options :hold) :i/hold :i/add-token) | ||
{:size 20 | ||
:no-color true}]])])))) | ||
|
||
(def view | ||
(quo.theme/with-theme | ||
(schema/instrument #'view-internal ?schema))) | ||
(schema/instrument #'view-internal component-schema/?schema))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.