mirror of
https://github.com/penpot/penpot.git
synced 2026-09-19 10:26:14 +00:00
Move SPA routing out of the URL fragment into the normal query string. The screen travels in a reserved `screen` key holding the route name (`?screen=workspace&team-id=…`); every other param keeps its name. `rt/nav` and `rt/resolve` keep their signatures. This deletes the fragment-mirroring URL surgery, simplifies link-preview (the server sees everything) and nginx (single path, no SPA fallback rules needed), and migrates OIDC redirects, email links, e2e helpers and plugin test utils to the new format. Legacy `#/…` URLs translate client-side for one Penpot version (`legacy-routes`, marked TODO(next-version)); non-SPA paths are untouched. AI-assisted-by: muse-spark-1.3-contributor
46 lines
2.0 KiB
Clojure
46 lines
2.0 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 INC Sucursal en España SL
|
|
|
|
(ns frontend-tests.router-test
|
|
(:require
|
|
[app.main.router :as rt]
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
(def ^:private test-routes
|
|
#{:auth-login :auth-register :dashboard-recent :workspace})
|
|
|
|
(t/deftest resolve-target-screen-wins-over-forwarded-params
|
|
;; Screens forward the current query params when navigating (e.g.
|
|
;; login passes its params to the register link); the stale screen
|
|
;; they carry must never override the destination.
|
|
(t/is (= "?screen=auth-register&foo=1"
|
|
(rt/resolve test-routes :auth-register {:screen "auth-login"
|
|
:foo "1"}))))
|
|
|
|
(t/deftest resolve-builds-screen-token
|
|
(t/is (= "?screen=dashboard-recent&team-id=team-1"
|
|
(rt/resolve test-routes :dashboard-recent {:team-id "team-1"})))
|
|
(t/is (= "?screen=auth-login"
|
|
(rt/resolve test-routes :auth-login)))
|
|
(t/is (nil? (rt/resolve test-routes :unknown-screen {:team-id "team-1"}))))
|
|
|
|
(t/deftest resolve-uri-builds-absolute-url
|
|
(let [uri (rt/resolve-uri test-routes :workspace {:file-id "file-1"})]
|
|
(t/is (string? uri))
|
|
(t/is (re-find #"\?screen=workspace&file-id=file-1$" uri))))
|
|
|
|
(t/deftest match-resolves-screen-token
|
|
(let [match (rt/match test-routes "?screen=workspace&team-id=team-1&file-id=file-1")]
|
|
(t/is (= :workspace (get-in match [:data :name])))
|
|
(t/is (= "team-1" (get-in match [:params :query :team-id])))
|
|
(t/is (= "file-1" (get-in match [:query-params :file-id])))
|
|
(t/is (= {} (get-in match [:params :path])))))
|
|
|
|
(t/deftest match-rejects-missing-or-unknown-screen
|
|
(t/is (nil? (rt/match test-routes "")))
|
|
(t/is (nil? (rt/match test-routes "?team-id=team-1")))
|
|
(t/is (nil? (rt/match test-routes "?screen=nope&team-id=team-1"))))
|