Fork me on GitHub
#fulcro
<
2018-11-01
>
tony.kay01:11:04

Load the ns?

levitanong06:11:56

@tony.kay I’ve tried requiring the namespace defining the fulcro mutations, no dice. It’s a pathom remote error though, so it seems more like the pc/defmutations aren’t found.

levitanong10:11:34

Figured it out! silly me, forgot to add all the resolvers into the registry!

pvillegas1213:11:59

How can I get something like (dom/span nil "&nbsp;&nbsp;&nbsp;&nbsp;") to work correctly?

pvillegas1213:11:20

This displays &nbsp;&nbsp;&nbsp;&nbsp; in the html instead of properly showing blank characters

exit213:11:23

try \xA0?

exit213:11:38

also I’ve seen similar in hiccup:

exit213:11:42

(defn my-blank-component []
  [:div {:dangerouslySetInnerHTML {:__html "&nbsp;"}}])

souenzzo14:11:42

How to swap states in defcard-fulcro ??

(defcard-fulcro Root-card
                ui/OpenCloseComponent
                {:open?                  false
                 :on-click  #(swap! ????)}
                {:inspect-data true})

tony.kay14:11:07

@pvillegas12 there is an entity namespace in Fulcro that defines these…like ent/nbsp

👍 4
tony.kay14:11:29

It’s called html-entities…There’s also an events namespace that has a lot of helpers for key codes

tony.kay14:11:02

happy to expand either of those…the events one is kind of light…I’m sure there are others that would be helpful

tony.kay14:11:10

@souenzzo you’re aware that those cards use component initial-state if you leave the card map empty?

tony.kay14:11:26

that isn’t an event handler…just leave that map empty

tony.kay14:11:44

the defcard macro takes a PREDEFINED component class name:

tony.kay14:11:03

(defcard-fulcro my-card
  OpenCloseComponent)

tony.kay14:11:26

the next arg is initial state normalized APP DATABASE IF you want to override the one your component declares

tony.kay14:11:34

The :onClick goes in the code of the component

tony.kay14:11:46

never put lambdas in app state

souenzzo14:11:41

I can use the 3º comp to pass lambdas, right?

tony.kay14:11:14

really…never…you can put mutation symbols in app state, but things will break if you put non-serializable things in app state

tony.kay14:11:16

that card type builds a complete fulcro app, uses the component you declare “as root”, gets the initial data from it, normalizes it into the database etc

tony.kay14:11:35

There’s a make-root function in the cards ns to build a wrapper root for using one-off components like this

tony.kay14:11:47

but they still need initial state to be generally functional

souenzzo14:11:41
replied to a thread:never put lambdas in app state

I can use the 3º comp to pass lambdas, right?

tony.kay14:11:11

if you want to do that you’ll need to write a small wrapper root class for your card by hand

souenzzo14:11:33

So I should not create "context-free" components, I should always put the "final" mutation? How? I can't have a generic button and use it in many places?

tony.kay14:11:42

um….let’s see…could you cheat

tony.kay14:11:06

context free components are fine…but if they are query-free and stateless, that;s the wrong card type 🙂

tony.kay14:11:51

show me the component

souenzzo14:11:16

So I need to use the regular defcard to test this query/state-free components? Can I use dc/om-root or something like?

tony.kay14:11:33

no I test components in those kinds of cards all the time

tony.kay14:11:47

I need more info about your component. If you show me the code, I’ll tell you the card

tony.kay14:11:53

if it has no query, for example, then you don’t need an app…you just use a normal devcard…a component like that is just a pure simple React component…and you can pass callbacks via props.

tony.kay14:11:03

The computed stuff is about components with queries

tony.kay14:11:24

because components with queries can refresh the props separate from the parent, which would lose the computed stuff if it wasn’t marked

tony.kay14:11:36

(because the parent makes those up, and targeted refresh need not go through the parent)

tony.kay15:11:40

defcard-fulcro is like defcard with om-root, but it has better hot code reload behavior

souenzzo15:11:09

(defsc my-comp
  [this {:keys [open? on-click]}]
  (dom/button {:onClick on-click}
              (if open? "+" "-")))

(defcard my-card
  my-comp
  {:open? false :on-click #(.log js/console "???")}
  {:inspect-data true})

souenzzo15:11:11

When I try to use dc/om-root I get Use of undeclared Var om.core/root

souenzzo15:11:31

add it to reqyure then

(defsc my-comp
  [this {:keys [open? on-click]}]
  (dom/button {:onClick on-click}
              (if open? "+" "-")))

(def ui-my-comp (prim/factory my-comp))

(defcard my-card
  (fn [state owner]
    (let [st @state]
      (ui-my-comp (assoc st
                    :on-click #(swap! state update :open? not)))))
  {:open?    true
   :on-click #(.log js/console "???")}
  {:inspect-data true})
Now working! thks

souenzzo15:11:21

Now working! thks See thread for solution 😄

tony.kay15:11:40

you the fn form for normal react

tony.kay15:11:43

not Om OR Fulcro

tony.kay15:11:58

(defcard my-card
  (fn [atom _] ...))

tony.kay15:11:30

then pass the on-click as a prop to the component as code

tony.kay15:11:35

not as something stored in the atom

souenzzo15:11:21

Now working! thks See thread for solution 😄

pvillegas1219:11:21

What is a good way to go about testing components in fulcro?

pvillegas1219:11:04

Example test cases: - Interaction: Click on a button and expect something to happen - Given different states what should the component display?

pvillegas1219:11:06

Testing mutations and functions is straight forward but I’m not sure how to tackle testing components themselves

pvillegas1219:11:27

The only similar section of the book I’ve found on this is http://book.fulcrologic.com/#VisualRegression

pvillegas1221:11:37

@tony.kay any thoughts on this?

wilkerlucio21:11:35

@pvillegas12 this should be no much different from testing pure React, the friction is probably in align the tools, AFAIK there is nothing done, so you have to write the wrappers yourself

pvillegas1221:11:17

@wilkerlucio what do you use to test fulcro components?

wilkerlucio21:11:47

currently I do mostly two types of tests, one is for rendering, another for mutations

wilkerlucio21:11:13

the mutations should be strait forward, you create some initial state, trigger the mutation and look at the atom after that, so you check if the data is changing as expected

wilkerlucio21:11:48

for the views, I'm doing generative testing, given in fulcro all the data uses namespaced keywords, its quite easy to generate random data to render a widget

wilkerlucio21:11:06

so I render a lot of random data (and include some bad information, like possible parser errors and nils everywhere)

wilkerlucio21:11:14

than I render and check if no exception was thrown

wilkerlucio21:11:04

this for example takes a component and returns a test.check generator that will get you random props for it

pvillegas1221:11:31

do you test interactions within the component?

wilkerlucio21:11:54

I assume that all that transactions can do is change state

wilkerlucio21:11:13

the state changes are covered by mutation specs, and any type of render can end up in one of the cases of the generative thing

pvillegas1222:11:52

yeah, I guess we end up going back to philosophically what we should be testing in components 🙂

wilkerlucio22:11:44

yup, I had put some time thinking about it, and tried a couple of approaches, I still think we have a lot to explore in this space, but I'm happy with this current setup, it gets a good sanity overall check, prevents people from simple mistakes (like trying to render a keyword by accident) @pvillegas12

wilkerlucio22:11:22

and it's easy to maintain, this is the code for testing a component:

pvillegas1222:11:51

I really like the snapshot testing too to combine with the above

wilkerlucio22:11:04

(ws/deftest test-macro-content-component
  (ts/check-component {::ts/component ui.spotlight/MacroContent
                       ::ts/gen-env   gen-env}))

wilkerlucio22:11:57

yeah, the snapshot is interesting, it just takes some time to run, depending on the number of components you have it can be a burden

pvillegas1222:11:27

What does that do, the generative testing approach?

pvillegas1222:11:49

The magic goes in what ts is 🙂