Commit Graph

46 Commits

Author SHA1 Message Date
Icaro Motta 7a4b12acf4
Make component test helpers usable from the REPL (#15468)
This commit makes the test-helpers.component namespace loadable in the REPL,
plus other changes that allow for a reasonably enjoyable RDD (REPL-Driven
Development) workflow.

Why? I want to be able to get instant feedback when I render a component with
the RN Testing Library (RNTL), and only once I'm satisfied with my findings is
when I proceed to write/update the tests. This nearly instant feedback loop is
only feasible using the ClojureScript REPL, and I'd rather not endure long
recompilation cycles.

Note that by REPL I mean connecting to the CLJS REPL of the Shadow-CLJS :mobile
target.

Essentially, this is what this commit does:

- [x] Allow the test-helpers.component namespace to be evaluated in the REPL.
      This is now possible because I changed all functions that assumed js/jest
      existed with a guard clause using the CLJS macro exists?. Without the
      guard clauses, evaluating the namespace explodes due to stuff like
      js/jest.useFakeTimers that fail in compile time (it's a syntax sugar
      macro).
- [x] Change the family of functions to get the translation by text to either
      translate using i18n/label or translate with the dummy prefix tx:,
      depending if the code is running inside the Jest runtime or not.
- [x] Wrap remaining RNTL query functions, except for the find-* ones, since
      they don't work at all outside the Jest runtime.
- [x] All wrapped functions support the original arguments supported by RNTL.
      Arguments are always converted with clj->js.
- [x] All wrapped functions can optionally take a node (ReactTestInstance) as
      their first argument, otherwise the global screen object will be used.
      This is very important! See the explanation on section Doesn't RNTL
      recommend using the screen object?
- [x] Update Shadow-CLJS preloads, so that (in development) you can fire off the
      REPL and always be ready to call component test helpers. This is critical!

What else would be possible? Just an idea, but now that we can easily render
components using the same machinery provided by RNTL in the tests, we can
roughly implement Storybook's Play function
https://storybook.js.org/docs/react/writing-stories/play-function

Lesson learned: In the REPL, you may need to call
(re-frame.core/clear-subscription-cache!), otherwise you will experience
subscriptions returning the same value if their arguments are the same. For
example, I faced this while playing with the namespace
status-im2.contexts.communities.menus.community-options.component-spec. There
are better ways to solve this particular problem in the context of tests if we
use the tooling provided by day8.re-frame.test.

Doesn't RNTL recommend using the screen object? Indeed, it is recommended to use
the screen object instead of destructuring the results of RNTL render. It's just
easier and less error prone, but this only works reliably within the Jest
runtime, since it automatically cleans up rendered state after each test. When
using the REPL this is no longer the case, and I faced some errors, like Unable
to find node on an unmounted component, where RNTL would refuse to re-render
components, even if I explicitly unmounted them or called cleanup.

The only reliable solution I found was to store the result of render (a node)
and pass it to every subsequent call. This is not a workaround, it's officially
supported, but it's a tad less convenient. You can also not pass the node
reference and it should work most of the time.

Practical examples

Workflow suggestion: write your local experiments in the same namespace as the
component spec and within the comment macro. This way, you can have the Jest
watcher running and a REPL connected to :mobile, and they won't step on each
other. For the test watcher, I usually change quo2-core-spec or
status-im2.core-spec to only require what I'm interested, otherwise Jest
consumes way too many resources.

```clojure
;; Namespace quo2.components.colors.color-picker.component-spec
(h/test "color picker color changed"
  (let [selected (reagent/atom nil)]
    (h/render [color-picker/view {:on-change #(reset! selected %)}])
    (h/fire-event :press (get (h/get-all-by-label-text :color-picker-item) 0))
    (-> (h/expect @selected)
        (.toStrictEqual :blue))))

(comment
  (def selected (atom nil))
  (def c (h/render [color-picker/view {:on-change #(reset! selected %)}]))

  (h/fire-event :press (get (h/get-all-by-label-text c :color-picker-item) 0))

  ;; Options are passed down converted to JS types.
  (h/debug c {:message "Rendering header"})

  @selected ; => :blue
)
```

```clojure
;; Namespace quo2.components.tags.--tests--.status-tags-component-spec
(h/test "renders status tag with pending type"
  (render-status-tag {:status {:type :pending}
                      :label  "Pending"
                      :size   :small})
  (-> (h/expect (h/get-all-by-label-text :status-tag-pending))
      (.toBeTruthy))
  (-> (h/expect (h/get-by-text "Pending"))
      (.toBeTruthy)))

(comment
  (def c (render-status-tag {:status {:type :pending}
                             :label  "Pending"
                             :size   :small}))

  (h/get-all-by-label-text c :status-tag-pending))
```

```clojure
;; Namespace status-im2.contexts.communities.menus.community-options.component-spec
(h/test "joined and muted community"
  (setup-subs {:communities/my-pending-request-to-join nil
               :communities/community                  {:joined       true
                                                        :muted        true
                                                        :token-gated? true}})
  (h/render [options/community-options-bottom-sheet {:id "test"}])
  (-> (h/expect (h/get-by-translation-text :unmute-community))
      (.toBeTruthy)))

(comment
  (setup-subs {:communities/my-pending-request-to-join nil
               :communities/community                  {:joined       true
                                                        :muted        true
                                                        :token-gated? true}})
  (def c (h/render [options/community-options-bottom-sheet {:id "test"}]))
  (some? (h/get-by-translation-text c :invite-people-from-contacts)) ; => true
)
```
2023-03-27 11:54:56 -03:00
Jakub Sokołowski 0f8ad69319
Nix/upgrade zprint 1.2.5 (#15113)
* nix: upgrade zprint from 1.2.4 to 1.2.5

To address issue described in:
https://github.com/kkinnear/zprint/issues/273

Signed-off-by: Jakub Sokołowski <jakub@status.im>

* chore: use zprint :multi-lhs-hang

* refactor: re-format clojure using zprint 1.2.5

---------

Signed-off-by: Jakub Sokołowski <jakub@status.im>
Co-authored-by: yqrashawn <namy.19@gmail.com>
2023-02-17 20:10:00 +08:00
Omar Basem 95380175a6
fix: image actions (#14996)
* fix: image actions and reactions
2023-02-09 07:18:49 +04:00
flexsurfer e8e8547879
cleanup setup (#14827) 2023-01-19 12:15:28 +01:00
Alexander 27c8c5547c
[#14689] Link previews in chat (#14771)
* Initial

* Link fetching

* Post-merge fix
2023-01-18 22:43:26 +01:00
flexsurfer d2e35fe928
move constants/config to status-im2 root and remove old constants/config (#14821) 2023-01-18 15:43:58 +01:00
flexsurfer ed348e0871
cleaning (#14808)
cleaning, introduce react-native.red-black-tree and move messages list events
2023-01-18 12:16:33 +01:00
Jamie Caprani 73c4be8dee
Communities Join Screens - Implement all permutations of Context Drawer options (#14700) 2023-01-13 09:35:41 +00:00
Omar Basem 951fd43d10
Images Album (#14635)
* feat: images album
2023-01-05 16:31:32 +04:00
Icaro Motta 915b8ebd9a
New component Selector > Filter (#14650) 2022-12-28 12:21:15 -03:00
yqrashawn 39e29cfb5a
feat: replace clj-fmt with zprint (#14520) 2022-12-20 21:57:49 +08:00
Omar Basem ba41d4b271
Photo Selector 2 (#14487)
* Photo Selector (2)
2022-12-20 07:36:06 +04:00
Jamie Caprani c6e8aad745
feat: add component tests using react-testing-library and jest (#14331) 2022-11-23 05:59:18 -08:00
flexsurfer c7d5e90882
introduce new project structure (first step) (#14356)
* introduce new project structure
2022-11-14 19:16:55 +01:00
Jakub Sokołowski 93f5b2e32c
nix: fix shadow-cljs on M1 by upgrading to 2.11.16
On M1 calling `shadow-cljs` fails with:
```
Execution error (UnsatisfiedLinkError) at java.lang.ClassLoader$NativeLibrary/load (ClassLoader.java:-2).
/private/var/folders/__/x311ykg17rqgq2wyl4kn1pdr0001yh/T/jna8753030888504535661.tmp:
    dlopen(/private/var/folders/__/x311ykg17rqgq2wyl4kn1pdr0001yh/T/jna8753030888504535661.tmp, 0x0001):
        tried: '/private/var/folders/__/x311ykg17rqgq2wyl4kn1pdr0001yh/T/jna8753030888504535661.tmp'
            (fat file, but missing compatible architecture (have (unknown,i386,x86_64), need (arm64e)))
```
This is due to an outdeted dependency on JNA 3.2.2, which is pulled in
by `hawk` package which up until release `2.11.16` was a `shadow-clj`
dependency which was removed because it was:

>Only used to be used on macOS since it was slightly faster than the default
>JVM implementation. However in Big Sur it seems to cause issues and break
>completely or just be a lot slower.

https://github.com/thheller/shadow-cljs/commit/f3b89b5a

Dropped the explicit dependency on `org.clojure/core.async` to avoid:
```
WARNING: The org.clojure/core.async dependency in shadow-cljs.edn was ignored.
Default version is used and override is not allowed to ensure compatibility.
```

Resolves: https://github.com/status-im/status-mobile/issues/14196

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2022-10-20 17:54:02 +02:00
Roman Volosovskyi c017c01c53
[#11335] Use Pokt network as an infura replacement 2022-10-19 17:00:17 +02:00
Icaro Motta 8502834500
Improve activity log component
Also makes hot reload optional with environment variable
SHADOW_AUTOBUILD_ENABLED.
2022-09-09 00:39:32 -03:00
yqrashawn ccd26dcfd0
refactor: go through clj-kondo warnings (#13929) 2022-09-05 18:52:39 +08:00
Jakub Sokołowski 8ec2f23203
nix: pass OPENSEA_API_KEY via saveAccountAndLogin
Here the injection of OpenSea API key was done at compile time:
https://github.com/status-im/status-mobile/commit/aa72ac57

But this makes `status-go` builds impure, and also prevents them from
being extracted from `status-mobile` into `status-go` repo.

Instead we pass the `OPENSEA_API_KEY` env variable to JS bundle at build
time, which is then passed to `status-go` via the
`Statusgo.saveAccountAndLogin` call in `saveAccountAndLogin`:
https://github.com/status-im/status-mobile/blob/51174f84/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java#L323-L327

Which sends `NodeConfig` that also contains `WalletConfig` which can
include `OpenseaAPIKey`:
```go
type WalletConfig struct {
    Enabled       bool
    OpenseaAPIKey string `json:"OpenseaAPIKey"`
}
```
https://github.com/status-im/status-go/blob/0135cc15/params/config.go#L510-L514

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2022-08-05 14:23:33 +02:00
yqrashawn a08c7ff22e
feat: add repl support for cljs test (#13754) 2022-08-03 16:14:20 +02:00
flexsurfer 8a01d02135
re-frisk 1.6.0 (#13380) 2022-05-20 12:31:54 +02:00
andrey f39b688e89
google free and metrics free
Signed-off-by: andrey <motor4ik@gmail.com>
2022-05-19 07:22:23 +02:00
Parvesh Monu 36c7d8e4ca
Implementation of remote android notifications (#13028) 2022-02-14 17:27:33 +05:30
andrey 05ed28b9a2
re-frisk 1.5.0 2021-04-19 11:45:43 +02:00
andrey 87f86d3b7b
bump re-frisk 1.4.0 2021-04-12 08:36:54 +02:00
andrey 76b1e2a007
bump re-frisk
Signed-off-by: andrey <motor4ik@gmail.com>
2021-03-12 13:01:59 +01:00
Jakub Sokołowski 293fd5fae1
nix: add missing cljfmt dependencies to nix/deps/clojure
It seems like this worked before purely because the `cljfmt` library was
already in the `~/.m2` cache folder. This issue was noticed when I
cleaned up the `~/.m2` folder on one Jenkins slave host and the Lint stage
started randomly failing.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
Signed-off-by: andrey <motor4ik@gmail.com>
2021-03-01 16:42:38 +01:00
andrey 9648f741b4
cleaning 3
Signed-off-by: andrey <motor4ik@gmail.com>
2021-02-17 16:16:54 +01:00
andrey 0087a66df8
bump re-frisk 2021-01-21 15:25:54 +01:00
andrey af2b053fa9
disable fast refresh on ios and bump re-frisk
Signed-off-by: andrey <motor4ik@gmail.com>
2021-01-20 11:44:24 +01:00
Andrea Maria Piana 85991d2272
Set infura token and update snx/synth contract
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2020-10-07 10:01:39 +02:00
Andrea Maria Piana 966f6de31a
Fix infura token
Setting a top-level closure-defines does not have any effect,
it needs to be for some reason inside each environment.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2020-10-05 16:22:14 +02:00
andrey 9cd1e08aaa
upgrade shadow
Signed-off-by: andrey <motor4ik@gmail.com>
2020-10-01 08:53:10 +02:00
Александар Симић b2a79b3e89
Update nREPL to the latest stable
With the update of Emacs CIDER 0.26.1, it expects to have the latest
cider-nrepl dependency to be at 0.25.3 otherwise it throws an error
when connecting to the project's REPL.

Signed-off-by: andrey <motor4ik@gmail.com>
2020-09-02 11:27:52 +02:00
Gheorghe Pinzaru 793579885a
Add universal QR scanner via common router
Rename events

Add router to handle all links

Use router in add new chat

Unify universal link and universal qr with router

Add icon for universal scanner

Update tests

Now routing is tested in routing PR

lint

Cleanup

QA fixes

Scan own profile

Handle more EIP

Fix wallet scanner

Fix stack for view profile in UL

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
2020-08-11 10:24:15 +03:00
yenda 67ce4b03aa
Revert "upgrade shadow"
This reverts commit 08cbc76111.

Signed-off-by: yenda <eric@status.im>
2020-07-14 13:02:24 +02:00
andrey eef6815616
[#10880] Expanded view with public chat categories 2020-07-10 14:54:39 +02:00
andrey 08cbc76111
upgrade shadow
Signed-off-by: andrey <motor4ik@gmail.com>
2020-07-10 12:41:15 +02:00
Andrea Maria Piana 1714970e4e
Use Infura token pulled from environment
This way we can use different token for e2e, release, and devel builds.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2020-06-19 19:26:40 +02:00
Andrey Shovkoplyas f659cbf242
camera roll 2020-06-01 11:34:13 +02:00
Jakub Sokołowski 2f9593a7d2
unify multiple Makefile targets
Changes:
- Drop a bunch of `watch-{android,ios}-*` tagets
- Replace them with one `run-clojure`
- Drop a bunch of `react-native-*` targets
- Replace them with one `run-metro`
- Replace `run-{android,ios}` with `run-{android,ios}`
- Drop `startdev-{android,ios,desktop}*` targets
- Drop `prod-build-{android,ios}` as deprecated
- Drop `src/status_im/android/core.cljs`
- Drop `src/status_im/ios/core.cljs`
- Move `lsof` tool to `default` shell
- Replace them with one `init` `src/status_im/core.cljs`
- Use `init` in one `shadow-cljs.edn` target `mobile`
- Use `mobile` target in `nix/mobile/android/jsbundle`
- Update instructions in `STARTING_GUIDE.md`
- Use `gradle` shell for `android-clean` target

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-05-15 18:29:31 +02:00
Gheorghe Pinzaru d133f57678
Remove source-map android debug
Update flipper version android

Disable source maps ios

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
2020-05-14 15:43:06 +03:00
Andrey Shovkoplyas 41bde61212
[#10414] Implement support for latest version of eip-1193 2020-05-06 17:35:40 +02:00
Andrey Shovkoplyas d3860508ca
hot reload and re-frisk 1.3.1
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
2020-05-04 11:22:19 +02:00
yenda bf706e8fd2
move tests alongside their cljs counterpart
Signed-off-by: yenda <eric@status.im>
2020-04-30 18:07:17 +02:00
yenda d5ef218584
use shadow-cljs
Signed-off-by: Jakub Sokołowski <jakub@status.im>
Signed-off-by: yenda <eric@status.im>
2020-04-30 15:43:46 +02:00