Last active
June 30, 2024 13:52
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
(ns horizon.controls.widgets.views-selector-tests.views-selector-test | |
(:require | |
[cljs.test :refer-macros [deftest testing is use-fixtures async]] | |
[sablono.core :as sab :include-macros true] | |
[cljs-react-test.utils :as tu] | |
[cljs-react-test.simulate :as sim] | |
[cljs.core.async :as core.async] | |
[om.core :as om :include-macros true] | |
[horizon.controls.widgets.comboboxes.views-selector :as views-selector] | |
[horizon.common.messaging.core :as m] | |
[horizon.test-helpers.async-test-tools :as async-test-tools] | |
[horizon.test-doubles.core :as td :include-macros true] | |
[horizon.common.logging :as log] | |
[horizon.test-helpers.dom-selection :as dom-selection])) | |
(def ^:private ^:dynamic c) | |
(use-fixtures :each | |
{:before #(async done | |
(set! c (tu/new-container!)) | |
(done)) | |
:after #(do | |
(td/with-doubles | |
:ignoring [m/unsubscribe] | |
(tu/unmount! c)))}) | |
(def ^:private possible-views-options | |
[{:Id :view1 :Name "Custom View 1"} | |
{:Id :view2 :Name "Custom View 2"}]) | |
(defn- mount-component-on-root | |
[root-container combo-id-num app-state ui-events-channel commands-channel] | |
(td/with-doubles | |
:ignoring [log/debug] | |
(om/root | |
(fn [data owner] | |
(reify | |
om/IRenderState | |
(render-state [_ _] | |
(sab/html | |
[:div | |
(om/build | |
views-selector/views-combobox | |
data | |
{:opts {:channels {:ui-events-channel ui-events-channel | |
:commands-channel commands-channel} | |
:generate-id-fn (constantly combo-id-num)} | |
:init-state {:expanded true | |
:value {:selected (:selected @app-state)}}})])))) | |
app-state | |
{:target root-container}))) | |
(deftest selecting-save-current-view-action | |
(let [ui-events-channel (core.async/chan) | |
commands-channel (core.async/chan) | |
app-state (atom {:pre-label "Select view:" | |
:views-options possible-views-options | |
:selected -1})] | |
(mount-component-on-root | |
c 100 app-state ui-events-channel commands-channel) | |
(async | |
done | |
(async-test-tools/expect-async-message | |
commands-channel | |
:done-fn done | |
:expected-message {:type :command | |
:payload {:command :show-custom-view | |
:Id :view1}}) | |
(sim/click (dom-selection/nth-li c 2) {})))) | |
(deftest selecting-showing-first-custom-view-action | |
(let [ui-events-channel (core.async/chan) | |
commands-channel (core.async/chan) | |
app-state (atom {:pre-label "Select view:" | |
:views-options possible-views-options | |
:selected -1})] | |
(mount-component-on-root | |
c 100 app-state ui-events-channel commands-channel) | |
(async | |
done | |
(async-test-tools/expect-async-message | |
commands-channel | |
:done-fn done | |
:expected-message {:type :command | |
:payload {:command :save-current-view}}) | |
(sim/click (dom-selection/nth-li c 4) {})))) | |
(deftest deleting-view-action | |
(let [ui-events-channel (core.async/chan) | |
commands-channel (core.async/chan) | |
app-state (atom {:pre-label "Select view:" | |
:views-options possible-views-options | |
:selected -1})] | |
(mount-component-on-root | |
c 100 app-state ui-events-channel commands-channel) | |
(async | |
done | |
(async-test-tools/expect-async-message | |
commands-channel | |
:done-fn done | |
:expected-message {:type :command | |
:payload {:command :delete-custom-view | |
:Id :view2}}) | |
(sim/click (second (dom-selection/elements-of-class c "delete")) {})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment