mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
✔️ Allow for tests of data module at frontend
This commit is contained in:
parent
87cf91a044
commit
bde62473a4
5 changed files with 110 additions and 4 deletions
|
@ -31,7 +31,8 @@ goog.scope(function() {
|
|||
} else if (typeof require === "function") {
|
||||
const crypto = require("crypto");
|
||||
return (buf) => {
|
||||
crypto.getRandomValues(buf);
|
||||
const bytes = crypto.randomBytes(buf.length);
|
||||
buf.set(bytes)
|
||||
return buf;
|
||||
};
|
||||
} else {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
[app.common.data :as d]
|
||||
[app.common.spec :as us]
|
||||
[app.common.version :as v]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.object :as obj]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.avatars :as avatars]
|
||||
|
@ -73,7 +74,7 @@
|
|||
(def login-with-ldap (obj/get global "appLoginWithLDAP" false))
|
||||
(def worker-uri (obj/get global "appWorkerURI" "/js/worker.js"))
|
||||
(def public-uri (or (obj/get global "appPublicURI")
|
||||
(.-origin ^js js/location)))
|
||||
(.-origin ^js globals/location)))
|
||||
(def media-uri (str public-uri "/assets"))
|
||||
(def version (delay (parse-version global)))
|
||||
(def target (delay (parse-target global)))
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[beicon.core :as rx]
|
||||
[app.main.store :as st]
|
||||
[app.main.refs :as refs]
|
||||
[app.common.geom.point :as gpt]))
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.util.globals :as globals]))
|
||||
|
||||
;; --- User Events
|
||||
|
||||
|
@ -103,7 +104,7 @@
|
|||
|
||||
|
||||
(defonce window-blur
|
||||
(->> (rx/from-event js/window "blur")
|
||||
(->> (rx/from-event globals/window "blur")
|
||||
(rx/share)))
|
||||
|
||||
(defonce keyboard-alt
|
||||
|
|
42
frontend/src/app/util/globals.js
Normal file
42
frontend/src/app/util/globals.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*
|
||||
* Copyright (c) 2020 UXBOX Labs SL
|
||||
*/
|
||||
|
||||
/*
|
||||
* Provide instances of some javascript global objects, by looking for
|
||||
* them in the browser, the current worker or creating a dummy for test
|
||||
* environment.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
goog.provide("app.util.globals");
|
||||
|
||||
goog.scope(function() {
|
||||
var win;
|
||||
if (typeof goog.global.window !== "undefined") {
|
||||
win = goog.global.window;
|
||||
} else {
|
||||
win = {};
|
||||
}
|
||||
|
||||
app.util.globals.window = win;
|
||||
|
||||
var loc;
|
||||
if (typeof goog.global.location !== "undefined") {
|
||||
loc = goog.global.location;
|
||||
} else {
|
||||
loc = {};
|
||||
}
|
||||
|
||||
app.util.globals.location = loc;
|
||||
});
|
||||
|
61
frontend/tests/app/test_library_sync.cljs
Normal file
61
frontend/tests/app/test_library_sync.cljs
Normal file
|
@ -0,0 +1,61 @@
|
|||
(ns app.test-library-sync
|
||||
(:require [cljs.test :as t :include-macros true]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[app.main.data.workspace.libraries :as dwl]))
|
||||
|
||||
;; ---- Helpers
|
||||
|
||||
(defn do-update
|
||||
[state event cb]
|
||||
(let [new-state (ptk/update event state)]
|
||||
(cb new-state)))
|
||||
|
||||
(defn do-watch
|
||||
[state event cb]
|
||||
(->> (ptk/watch event state nil)
|
||||
(rx/reduce conj [])
|
||||
(rx/subs cb)))
|
||||
|
||||
(defn do-watch-update
|
||||
[state event & cbs]
|
||||
(do-watch state event
|
||||
(fn [events]
|
||||
(t/is (= (count events) (count cbs)))
|
||||
(reduce
|
||||
(fn [new-state [event cb]]
|
||||
(do-update new-state event cb))
|
||||
state
|
||||
(map list events cbs)))))
|
||||
|
||||
;; ---- Tests
|
||||
|
||||
(t/deftest synctest
|
||||
(t/testing "synctest"
|
||||
(let [state {:workspace-local {:color-for-rename "something"}}]
|
||||
(do-update
|
||||
state
|
||||
dwl/clear-color-for-rename
|
||||
(fn [new-state]
|
||||
(t/is (= (get-in new-state [:workspace-local :color-for-rename])
|
||||
nil)))))))
|
||||
|
||||
(t/deftest asynctest
|
||||
(t/testing "asynctest"
|
||||
(t/async done
|
||||
(let [state {}
|
||||
color {:color "#ffffff"}]
|
||||
(do-watch-update
|
||||
state
|
||||
(dwl/add-recent-color color)
|
||||
(fn [new-state]
|
||||
(t/is (= (get-in new-state [:workspace-file
|
||||
:data
|
||||
:recent-colors])
|
||||
[color]))
|
||||
(t/is (= (get-in new-state [:workspace-data
|
||||
:recent-colors])
|
||||
[color]))
|
||||
(done)))))))
|
||||
|
Loading…
Reference in a new issue