mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 13:32:28 +00:00
* ♻️ Reduce the routes, viewer, theme and typography e2e specs The five specs of Task 10 (routes, theme, viewer and roles) go from 14 tests to 6, and the two of Task 11 (missing font and add typography) from 9 to 4. Nine unit tests cover rules that had none: five for the private legacy-match and four for the viewer frame navigation. No skipped test and no fixture removed. The browser keeps the wiring: the known and unknown hash as two steps of one test, the theme applied live without a reload, the viewer role walked in two loads with the context menu counted instead of trusted, and the typography states merged around shared fixtures. The viewer zoom click comes back as a header step; the arrows e2e becomes unit tests, with the Next button still clicked by the child-click test. The missing-font test asserts the renamed, disabled typography button instead of a hidden one it never described. WorkspacePage gains reloadWorkspace, which clears the socket registry, reloads and reopens the mock, and settles on the sitemap page name or on the canvas when the restored sidebar tab hides it. layerRow matches rows by anchored text, because a selected row's action buttons can join its accessible name, and selectLayer accepts click options for the shift-click steps. The font specs use both and no longer import MockWebSocketHelper. The viewer role asserts its two absences by testid: new-project-button already existed and add-custom-font is new in fonts.cljs, the only product change, with the visible side covered by dashboard.spec. routes_test adds the path-params case for legacy-match; viewer_test asserts the first event and the page id of the frame navigation, and watch-events delivers asynchronously and handles the nil a watch can return. Measured at four workers: 23 to 10 tests; Task 10 from 141.3 to 68.5/72.3 worker-seconds and Task 11 from 150.1 to 109.0/109.3. Closes #13058 AI-assisted-by: deepseek-v4.1-flash * 🐛 Let the two reduced e2e steps fail when they should The typography step selected the next layer with Shift, which in the layers panel is a range selection: the range also brought in the text with a typography token, so the button was hidden by the applied token and not by the mixed values. A mod-click adds only that shape, and two new assertions keep the token and the asset texts out of the selection. The logo step clicked 100 px below the logo and asserted the URL, which potok updates after the click returns, so the assertion matched the old URL on its first poll. Probing elementFromPoint under the logo answers the hit-area question directly. AI-assisted-by: deepseek-v4.1-flash
191 lines
7.9 KiB
Clojure
191 lines
7.9 KiB
Clojure
;; 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/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns frontend-tests.ui.routes-test
|
|
(:require
|
|
[app.common.time :as ct]
|
|
[app.common.uuid :as uuid]
|
|
[app.config :as cf]
|
|
[app.main.data.team :as dtm]
|
|
[app.main.repo :as rp]
|
|
[app.main.store :as st]
|
|
[app.main.ui.routes :as routes]
|
|
[app.util.storage :as storage]
|
|
[beicon.v2.core :as rx]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.helpers.mock :as mock]))
|
|
|
|
(defn- workspace-match
|
|
[team-id]
|
|
{:data {:name :workspace}
|
|
:params {:path {}}
|
|
:query-params {:team-id (str team-id)}})
|
|
|
|
(t/deftest sso-check-is-cached-for-five-minutes
|
|
(t/async done
|
|
(let [team-id (uuid/next)
|
|
match (workspace-match team-id)
|
|
now (atom (ct/inst "2026-08-11T10:00:00Z"))
|
|
rpc-calls (atom 0)
|
|
events (atom [])]
|
|
(mock/with-mocks
|
|
{cf/flags (conj cf/flags :admin-console)
|
|
ct/now (mock/stub (fn [] @now))
|
|
rp/cmd! (mock/stub
|
|
(fn [command params]
|
|
(t/is (= :check-nitrate-sso command))
|
|
(t/is (= team-id (:team-id params)))
|
|
(t/is (= "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d"
|
|
(:query-string params)))
|
|
(swap! rpc-calls inc)
|
|
(rx/of {:authorized true})))
|
|
st/emit! (mock/stub
|
|
(fn [& emitted]
|
|
(swap! events into emitted)))}
|
|
(fn [done']
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(reset! now (ct/plus @now #js {:minutes 4 :seconds 59}))
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(t/is (= 1 @rpc-calls))
|
|
(t/is (= 2 (count @events)))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest sso-check-is-refreshed-after-five-minutes
|
|
(t/async done
|
|
(let [team-id (uuid/next)
|
|
match (workspace-match team-id)
|
|
now (atom (ct/inst "2026-08-11T10:00:00Z"))
|
|
rpc-calls (atom 0)]
|
|
(mock/with-mocks
|
|
{cf/flags (conj cf/flags :admin-console)
|
|
ct/now (mock/stub (fn [] @now))
|
|
rp/cmd! (mock/stub
|
|
(fn [_ _]
|
|
(swap! rpc-calls inc)
|
|
(rx/of {:authorized true})))
|
|
st/emit! mock/noop}
|
|
(fn [done']
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(reset! now (ct/plus @now #js {:minutes 5}))
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(t/is (= 2 @rpc-calls))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest sso-redirect-result-is-not-cached
|
|
(t/async done
|
|
(let [team-id (uuid/next)
|
|
match (workspace-match team-id)
|
|
rpc-calls (atom 0)
|
|
events (atom [])]
|
|
(mock/with-mocks
|
|
{cf/flags (conj cf/flags :admin-console)
|
|
rp/cmd! (mock/stub
|
|
(fn [_ _]
|
|
(swap! rpc-calls inc)
|
|
(rx/of {:authorized false
|
|
:redirect-uri "https://idp.example.com/authorize"})))
|
|
st/emit! (mock/stub
|
|
(fn [& emitted]
|
|
(swap! events into emitted)))}
|
|
(fn [done']
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(#'routes/check-sso-and-navigate match true "screen=workspace&team-id=1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d")
|
|
(t/is (= 2 @rpc-calls))
|
|
(t/is (= 2 (count @events)))
|
|
(done'))
|
|
done))))
|
|
|
|
;; Template links (`#?template=<url>`) predate query-string routing: the
|
|
;; params live in a bare `#?…` fragment and there is no `screen` (#12127).
|
|
|
|
(def ^:private template-url
|
|
"https://penpot.github.io/penpot-files/tutorial-for-beginners%20v.2.0.penpot")
|
|
|
|
(def ^:private template-param
|
|
"The query param as the router decodes it."
|
|
"https://penpot.github.io/penpot-files/tutorial-for-beginners v.2.0.penpot")
|
|
|
|
(t/deftest legacy-query-hash-becomes-a-query-token
|
|
(t/is (= (str "?template=" template-url)
|
|
(#'routes/legacy-query-token (str "#?template=" template-url))))
|
|
(t/is (nil? (#'routes/legacy-query-token "#/workspace?team-id=1")))
|
|
(t/is (nil? (#'routes/legacy-query-token ""))))
|
|
|
|
(t/deftest query-without-screen-goes-to-dashboard-with-its-params
|
|
(t/async done
|
|
(let [team-id (uuid/next)
|
|
events (atom [])]
|
|
(mock/with-mocks
|
|
{rp/cmd! (mock/stub
|
|
(fn [command _]
|
|
(case command
|
|
:get-profile (rx/of {:id (uuid/next) :default-team-id team-id})
|
|
:get-teams (rx/of [{:id team-id}]))))
|
|
dtm/get-last-team-id (mock/stub (fn [] nil))
|
|
st/emit! (mock/stub (fn [& emitted] (swap! events into emitted)))}
|
|
(fn [done']
|
|
(#'routes/on-query-navigate #{:dashboard-recent} (str "?template=" template-url) false)
|
|
(let [{:keys [id params]} (some-> (first @events) deref)]
|
|
(t/is (= :dashboard-recent id))
|
|
(t/is (= template-param (:template params)))
|
|
(t/is (= team-id (:team-id params))))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest query-without-screen-keeps-template-for-after-login
|
|
(t/async done
|
|
(let [events (atom [])]
|
|
(mock/with-mocks
|
|
{rp/cmd! (mock/stub
|
|
(fn [command _]
|
|
(case command
|
|
:get-profile (rx/of {:id uuid/zero})
|
|
;; The backend requires a session for get-teams.
|
|
:get-teams (rx/throw (ex-info "authentication required"
|
|
{:type :authentication})))))
|
|
st/emit! (mock/stub (fn [& emitted] (swap! events into emitted)))}
|
|
(fn [done']
|
|
(#'routes/on-query-navigate #{:auth-login} (str "?template=" template-url) false)
|
|
(t/is (= template-param (:template @storage/session)))
|
|
(t/is (= :auth-login (:id (some-> (first @events) deref))))
|
|
(binding [storage/*sync* true]
|
|
(swap! storage/session dissoc :template))
|
|
(done'))
|
|
done))))
|
|
|
|
;; --- Legacy hash table -----------------------------------------------------
|
|
;; The router built from `legacy-routes` is a `defonce`, so its entries are
|
|
;; fixed when the namespace loads. These tests only reach the unconditional
|
|
;; ones; a flag cannot add or remove routes here.
|
|
|
|
(t/deftest legacy-match-resolves-a-top-level-path
|
|
(let [match (#'routes/legacy-match "/auth/login")]
|
|
(t/is (= :auth-login (:name match)))
|
|
(t/is (= {} (:params match)))))
|
|
|
|
(t/deftest legacy-match-resolves-a-nested-path
|
|
(let [match (#'routes/legacy-match "/dashboard/files")]
|
|
(t/is (= :dashboard-files (:name match)))
|
|
(t/is (= {} (:params match)))))
|
|
|
|
(t/deftest legacy-match-keeps-the-query-string-params
|
|
(let [team-id (str (uuid/next))
|
|
match (#'routes/legacy-match (str "/workspace?team-id=" team-id))]
|
|
(t/is (= :workspace (:name match)))
|
|
(t/is (= team-id (:team-id (:params match))))))
|
|
|
|
(t/deftest legacy-match-returns-nil-for-an-unknown-path
|
|
(t/is (nil? (#'routes/legacy-match "/nope"))))
|
|
|
|
(t/deftest legacy-match-keeps-the-path-params
|
|
;; /render-sprite is the only legacy route with a path param.
|
|
(let [file-id (str (uuid/next))
|
|
match (#'routes/legacy-match (str "/render-sprite/" file-id))]
|
|
(t/is (= :render-sprite (:name match)))
|
|
(t/is (= file-id (:file-id (:params match))))))
|