mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
* ✨ Add per-profile review marks to branch comparisons A reviewer goes through the changes of a branch one by one, and the comparison has to remember which ones they have already seen. Add the `file_branch_change_review` table and two RPC methods, `get-branch-change-reviews` and `set-branch-change-review`. A mark belongs to a branch, a profile, a direction and a change, and keeps the fingerprint of the change at the time it was marked, so the client can ask for a new review when the change moves again. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ✨ Compare a branch with main on the canvas The comparison and the conflicts of a branch opened in two modals, away from the design they talk about. Move both to a compare mode on the canvas of the branch itself. The left sidebar lists the changes, in either direction, and the right one shows the change chosen. The canvas marks every change where it is, or only the one chosen, and a bar goes through them one at a time. The conflicts of a merge or an update are resolved in the same mode, with a popover beside the layer in conflict. The file is never touched: the workspace is read-only while the mode lasts, and what the canvas shows that the branch does not hold (the update, the choices made, main itself) is drawn by the WASM render alone. Main is put together from the changes of both directions, and can be seen beside the branch or by holding M. Each direction keeps its own selection of changes, and the changes marked as reviewed are stored per profile. The marks and the bar of the design reviews become shared components. That bar and the bar of the review now center on the canvas the rulers leave, as the bar of the branch does. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ✨ Add end-to-end tests for the compare mode Cover entering and leaving the mode, a merge with a change left out, an update from main and the three kinds of conflict. The tests of the reviews and of the merged branches follow the comparison to the canvas. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 💄 Move the WebGL rendering label to the bottom of the canvas The top right corner of the canvas now holds the name of the branch while it is compared with main, and the label was drawn under it. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ✨ Make the canvas answer for the changes in the compare mode While a branch is compared with main both sidebars talk about changes, not about layers, yet the canvas still selected any layer. Make it answer for the layers with a change or a conflict alone. The pointer on such a layer marks it and shows its row in the list, a click chooses it and a double click zooms to it. A click anywhere else lets the choice go, and the canvas marks every change again. The row under the pointer marks its layer too. No layer is selected, outlined or dragged over; pan and zoom stay as they are, and a commenting tool takes the canvas back while it is in use. The bar that goes through the changes shows with a change chosen only. The canvas no longer draws its projection again on every render, only when what it shows changes. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 💄 Keep the compare navigator grey outside a design review The bar that goes through the changes of a comparison had the blue border of a design review even with no review open. Give it the grey of the bar at the bottom of the canvas, and keep the blue inside a review. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ✨ Line main up with the change chosen in the side by side view Main beside the branch showed the same spot of the page, so a layer the branch moved fell out of the half of main once the canvas went to it. The side by side view now has two modes: linked, as it was, and aligned to the change, where main is moved by how far the layer chosen moved, so both versions sit at the middle of their halves. Zoom and pan stay linked, and main slides to the next change as it is chosen. The mode is picked in a submenu of the view, or with the A key, and the browser keeps the last one for the next comparison. The note on the canvas says how far main is moved. Main put a moved group, path or boolean at the place the branch has: the diff leaves out the box of a layer, and it was only built again for the layers whose box is their position and size. Their mark in main now stands where they are. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 💄 Name the side by side view alone in the view menu The control of the view said "Side by side - aligned" with main lined up with the change chosen, which the note under the toolbar already says. It names the view alone now, in both modes. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 🐛 Fit the whole page in both halves of the side by side view Fitting the whole page, and zooming from the menu or to 100%, took the middle of the canvas as the middle of the page, but beside main that is the divider: both halves showed the page cut on the left, out of its middle. While main is beside the branch these zooms now work in the half of the branch: the page fits in it and stands at its middle, and a zoom with no pointer turns on that middle. Fitting the whole page takes in main too, which can reach further than the branch. Fitting the change chosen goes through the same fit, which every fit of the workspace now shares. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 🐛 Zoom the canvas with the wheel over the marks of the changes The wheel with ctrl or cmd held only zoomed the canvas over the canvas itself or over the comments. Over the tags of the changes, which take the pointer, the browser zoomed the whole page instead. It zooms the canvas over anything drawn on top of it now: marks, tags and bars. The note that says how main stands beside the branch takes the look of the other notes of the canvas, in the primary colour. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 🐛 Fix the layers, bars and badges of the compare and review modes - The comments go over the marks of the changes, so a thread or a task opened from a bubble is no longer covered by them. - How far the review of a comparison is reads at the size of the rest of its bar, in Spanish too. - The way out of a comparison, back from its conflicts and out of a review are icon buttons, with what they do in a tooltip. - Beside the branch, main keeps the frame of the canvas, rounded corners included: its half covered it. - The tab of the other direction counts its changes as soon as the comparison opens: they come with every diff, but only the tab shown was counted. - The read-only badge is a quiet grey one with a lock, in the pages panel and over the changes of a comparison. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 🌐 Translate branching and design reviews into Spanish The Spanish catalog lacked 418 keys, nearly all of them of branching, comparing, conflicts, merges and design reviews, so those buttons, menus, messages and tooltips showed in English. Add them all, with the terms the catalog already uses. Drop 61 keys of both catalogs that nothing reads any more, left over from screens that are gone, and spell "colors" as the rest of the English catalog does. The Spanish word list takes the valid words the glued-word check flagged. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * 🐛 Find the way out of a review by its name in the e2e test The test looked for "Exit review" in the menu of the review bar, but the way out sits on the bar itself, and it is an icon button now, with its name in a tooltip. Click it on the bar, by its name. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ✨ Rework the detail of a change in the compare mode The property changes and the buttons of a change stand on the background the inspect tab gives its blocks, over the whole width of the sidebar and as one block when they follow each other. The buttons go one over the other, as wide as the sidebar. Under a change or a conflict, the comments that wait for an answer and the tasks still open on its layer give its context, inside a design review and outside it. They replace the tab of the comments of the review the detail had inside one. The bar of a design review says "In review", on one line: a long title is cut short, whole on hover. The arrows of the bar that goes through the changes hold the place in the list between them, with no gap. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ♻️ Bring the branching styles in line with the design system Review every stylesheet of branching and design reviews against the design system rules. None of them depends on the deprecated styles; a few details did not follow the rules: - colors that change with a state go through a local custom property (the branch counts, the caption of a preview card, the actions of the branch switcher and the next step of a task); - the alias of the canvas frame border resolves to its DS token; - the panels of the compare mode scroll with overflow-y, as overflow-block is not well supported yet; - unused imports are gone, and a z-index and a variable that are not DS tokens say so in a TODO. The generated CSS stays the same, except the overflow and two backgrounds that render as before. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> * ♻️ Reuse the design system components in the branching UI Where the branching and design review UI built its own control, it uses the one of the design system, keeping what the screens look like: - the multi-line fields use the DS text area, as high as before, and their labels name them; - renaming a branch uses the DS input; - the filter of comments and tasks is a DS menu, as wide as its button; - the read-only badge is a DS tag, and its own component is gone. The design system had nothing for a floating panel that is not a menu, so it gets a popover: it only closes on a click out of it or on Escape and gives the focus back, and the caller draws the panel. The branch switcher and the branches of a dashboard card use it instead of the legacy dropdown, unchanged on screen. The verdicts of a review and its reviewers read as radios and as checkboxes. The preview card of the design system, unused since the old conflicts dialog went away, is deleted. Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com> --------- Signed-off-by: elhombretecla <delacruzgarciajuan@gmail.com>
621 lines
29 KiB
Clojure
621 lines
29 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.data.workspace-branches-test
|
|
(:require
|
|
[app.common.uuid :as uuid]
|
|
[app.config :as cf]
|
|
[app.main.data.common :as dcm]
|
|
[app.main.data.modal :as modal]
|
|
[app.main.data.persistence :as dwp]
|
|
[app.main.data.workspace.branches :as dwb]
|
|
[app.main.data.workspace.pull-requests :as dwpr]
|
|
[app.main.repo :as rp]
|
|
[beicon.v2.core :as rx]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.helpers.async :as async]
|
|
[frontend-tests.helpers.mock :as mock]
|
|
[potok.v2.core :as ptk]))
|
|
|
|
(def ^:private conflict-revn
|
|
"Main's revn in the conflict answer of the faked merge/update command."
|
|
7)
|
|
|
|
(defn- cmd-stub
|
|
"Fake `rp/cmd!` that records every call into `calls`. The branch diff
|
|
fetch never answers, so the diff stays loading. A merge or update without
|
|
resolutions answers with one conflict computed at `conflict-revn`; one
|
|
with resolutions answers nothing."
|
|
[calls conflict-id]
|
|
(mock/stub (fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(cond
|
|
(= cmd :get-branch-diff) (rx/subject)
|
|
(seq (:resolutions params)) (rx/empty)
|
|
:else (rx/of {:status :conflicts
|
|
:conflicts [{:id conflict-id}]
|
|
:main-revn conflict-revn})))))
|
|
|
|
(defn- make-store
|
|
[]
|
|
(ptk/store {:state {}
|
|
:on-error (fn [cause] (t/is false (str cause)))}))
|
|
|
|
(defn- branch-cmd
|
|
[mode]
|
|
(if (= mode :update) :update-branch-from-main :merge-file-branch))
|
|
|
|
(defn- open-conflicts!
|
|
"Ask for a `mode` (`:merge` or `:update`) of `branch` and let the conflict
|
|
answer seed the store, as the compare mode then fetches the diff in the
|
|
direction it resolves (`app.main.data.workspace.compare/start-resolve`)."
|
|
[store mode branch]
|
|
(ptk/emit! store (if (= mode :update)
|
|
(dwb/update-branch-from-main branch)
|
|
(dwb/merge-branch branch)))
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)
|
|
(if (= mode :update) :main->branch :branch->main))))
|
|
|
|
(defn- apply-resolutions!
|
|
"Resolve every conflict to main and apply, as the compare mode does."
|
|
[store mode branch]
|
|
(ptk/emit! store (dwb/set-conflict-resolutions
|
|
(into {}
|
|
(map (fn [conflict] [(:id conflict) :main]))
|
|
(get-in @store [:workspace-branch-conflicts :conflicts]))))
|
|
(let [resolutions (get-in @store [:workspace-branch-diff :resolutions])]
|
|
(ptk/emit! store (if (= mode :update)
|
|
(dwb/update-branch-from-main branch {:resolutions resolutions})
|
|
(dwb/merge-branch branch {:resolutions resolutions})))))
|
|
|
|
(defn- last-params
|
|
"Params of the last merge or update call recorded in `calls`."
|
|
[calls mode]
|
|
(->> @calls
|
|
(filter #(= (branch-cmd mode) (first %)))
|
|
(last)
|
|
(second)))
|
|
|
|
(t/deftest resolutions-applied-before-the-diff-loads-send-the-conflict-revn
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
conflict-id (uuid/next)]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls conflict-id)}
|
|
(fn [done']
|
|
(doseq [mode [:merge :update]]
|
|
(t/testing (name mode)
|
|
(let [branch {:id (uuid/next)}
|
|
store (make-store)]
|
|
(reset! calls [])
|
|
(open-conflicts! store mode branch)
|
|
(t/is (= :loading (get-in @store [:workspace-branch-diff :status]))
|
|
"the diff fetch has not answered")
|
|
(apply-resolutions! store mode branch)
|
|
(let [params (last-params calls mode)]
|
|
(t/is (= {conflict-id :main} (:resolutions params)))
|
|
(t/is (= conflict-revn (:expected-main-revn params))
|
|
"the resolutions carry the revn of the conflict answer"))
|
|
(rx/dispose! store))))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest the-loaded-diff-revn-wins-over-the-conflict-revn
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
conflict-id (uuid/next)]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls conflict-id)}
|
|
(fn [done']
|
|
(doseq [mode [:merge :update]]
|
|
(t/testing (name mode)
|
|
(let [branch {:id (uuid/next)}
|
|
store (make-store)]
|
|
(reset! calls [])
|
|
(open-conflicts! store mode branch)
|
|
;; the diff fetch answers, computed at a newer main
|
|
(ptk/emit! store (dwb/update-branch-diff {:status :loaded
|
|
:diff {:meta {:main-revn 9}}}))
|
|
(apply-resolutions! store mode branch)
|
|
(t/is (= 9 (:expected-main-revn (last-params calls mode))))
|
|
(rx/dispose! store))))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest no-resolutions-without-a-loaded-diff-send-no-revn
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
conflict-id (uuid/next)]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls conflict-id)}
|
|
(fn [done']
|
|
(doseq [mode [:merge :update]]
|
|
(t/testing (name mode)
|
|
(let [branch {:id (uuid/next)}
|
|
store (make-store)]
|
|
(reset! calls [])
|
|
(open-conflicts! store mode branch)
|
|
(t/is (not (contains? (last-params calls mode) :expected-main-revn))
|
|
"the first request has neither resolutions nor a diff")
|
|
;; ask again while the diff is loading, with the conflict
|
|
;; answer's revn already stored
|
|
(ptk/emit! store (if (= mode :update)
|
|
(dwb/update-branch-from-main branch)
|
|
(dwb/merge-branch branch)))
|
|
(let [params (last-params calls mode)]
|
|
(t/is (= 2 (count (filter #(= (branch-cmd mode) (first %)) @calls))))
|
|
(t/is (not (contains? params :resolutions)))
|
|
(t/is (not (contains? params :expected-main-revn))
|
|
"the stored revn only travels with resolutions"))
|
|
(rx/dispose! store))))
|
|
(done'))
|
|
done))))
|
|
|
|
;;; --- Selective merge: the per-change selection ---
|
|
|
|
(defn- excluded
|
|
"The per-change selection of the direction the diff of `store` shows."
|
|
[store]
|
|
(dwb/diff-excluded (:workspace-branch-diff @store)))
|
|
|
|
(t/deftest the-per-change-selection-toggles-and-clears
|
|
(let [store (make-store)
|
|
k1 "color//aaaaaaaa/1"
|
|
k2 "color//aaaaaaaa/2"]
|
|
(t/testing "a row flips on its own"
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1}))
|
|
(t/is (= #{k1} (excluded store)))
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1}))
|
|
(t/is (= #{} (excluded store))))
|
|
|
|
(t/testing "a group sets every key of it to one side"
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1 k2} false))
|
|
(t/is (= #{k1 k2} (excluded store)))
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1} false))
|
|
(t/is (= #{k1 k2} (excluded store)))
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1 k2} true))
|
|
(t/is (= #{} (excluded store))))
|
|
|
|
(t/testing "leaving the comparison drops the selection"
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1}))
|
|
(ptk/emit! store (dwb/clear-diff-excluded))
|
|
(t/is (= #{} (excluded store))))))
|
|
|
|
(t/deftest each-direction-keeps-its-own-selection
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
branch {:id (uuid/next)}
|
|
k1 "color//aaaaaaaa/1"
|
|
k2 "color//aaaaaaaa/2"]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls (uuid/next))}
|
|
(fn [done']
|
|
(let [store (make-store)]
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k1}))
|
|
(t/testing "the same branch and direction refetches over the selection"
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(t/is (= #{k1} (excluded store))))
|
|
(t/testing "the other direction has a selection of its own"
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch) :main->branch))
|
|
(t/is (= #{} (excluded store)))
|
|
(ptk/emit! store (dwb/toggle-diff-excluded #{k2}))
|
|
(t/is (= #{k2} (excluded store))))
|
|
(t/testing "going back finds the first one as it was left"
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(t/is (= #{k1} (excluded store))))
|
|
(t/testing "another branch starts over"
|
|
(ptk/emit! store (dwb/fetch-branch-diff (uuid/next)))
|
|
(t/is (= #{} (excluded store))))
|
|
(rx/dispose! store))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest the-selection-travels-with-the-merge-and-update-calls
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
conflict-id (uuid/next)]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls conflict-id)}
|
|
(fn [done']
|
|
(doseq [mode [:merge :update]]
|
|
(t/testing (name mode)
|
|
(let [branch {:id (uuid/next)}
|
|
store (make-store)
|
|
excluded #{"color//aaaaaaaa/1"}]
|
|
(reset! calls [])
|
|
(ptk/emit! store (if (= mode :update)
|
|
(dwb/update-branch-from-main branch {:excluded excluded})
|
|
(dwb/merge-branch branch {:excluded excluded})))
|
|
(t/is (= excluded (:excluded (last-params calls mode))))
|
|
(t/testing "an empty selection sends no `:excluded` at all"
|
|
(ptk/emit! store (if (= mode :update)
|
|
(dwb/update-branch-from-main branch)
|
|
(dwb/merge-branch branch)))
|
|
(t/is (not (contains? (last-params calls mode) :excluded))))
|
|
(rx/dispose! store))))
|
|
(done'))
|
|
done))))
|
|
|
|
(t/deftest the-comment-travels-with-the-merge-and-its-conflicts
|
|
(t/async done
|
|
(let [calls (atom [])
|
|
conflict-id (uuid/next)]
|
|
(mock/with-mocks
|
|
{rp/cmd! (cmd-stub calls conflict-id)}
|
|
(fn [done']
|
|
(let [branch {:id (uuid/next)}
|
|
store (make-store)]
|
|
(ptk/emit! store (dwb/merge-branch branch {:comment " Ships the header "}))
|
|
(t/is (= "Ships the header" (:comment (last-params calls :merge)))
|
|
"the comment is trimmed")
|
|
(t/testing "the conflict answer keeps the comment for the retry"
|
|
(t/is (= " Ships the header "
|
|
(get-in @store [:workspace-branch-conflicts :comment]))))
|
|
(t/testing "a blank comment sends no `:comment` at all"
|
|
(ptk/emit! store (dwb/merge-branch branch {:comment " "}))
|
|
(t/is (not (contains? (last-params calls :merge) :comment))))
|
|
(rx/dispose! store))
|
|
(done'))
|
|
done))))
|
|
|
|
;;; --- Review marks: kept for the profile, dropped when the change moves ---
|
|
|
|
(def ^:private title
|
|
{:kind :shape :status :modified :id (uuid/next) :key "shape/p/title"
|
|
:changed-attrs {:opacity {:main 1 :branch 0.5}}})
|
|
|
|
(def ^:private logo
|
|
{:kind :shape :status :modified :id (uuid/next) :key "shape/p/logo"
|
|
:changed-attrs {:rx {:main 0 :branch 8}}})
|
|
|
|
(defn- review-stub
|
|
"Fake `rp/cmd!` for a comparison that lists `title` and `logo`: the diff
|
|
answers at once, the marks answer with `marks`, and keeping a mark
|
|
fails when `fail-set?` holds. Every call is recorded into `calls`."
|
|
[calls marks fail-set?]
|
|
(mock/stub (fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(case cmd
|
|
:get-branch-diff (rx/of {:changes [title logo] :conflicts []})
|
|
:get-branch-change-reviews (rx/of @marks)
|
|
:set-branch-change-review (if fail-set?
|
|
(rx/throw (ex-info "refused" {}))
|
|
(rx/of nil))
|
|
(rx/empty)))))
|
|
|
|
(defn- last-call
|
|
"Params of the last call of `cmd` recorded in `calls`."
|
|
[calls cmd]
|
|
(->> @calls (filter #(= cmd (first %))) (last) (second)))
|
|
|
|
(defn- reviewed
|
|
[store]
|
|
(get-in @store [:workspace-branch-diff :reviewed]))
|
|
|
|
(t/deftest ^:async a-mark-counts-while-its-change-is-what-it-was
|
|
(let [calls (atom [])
|
|
branch {:id (uuid/next)}
|
|
marks (atom [{:change-key (:key title) :fingerprint (dwb/change-fingerprint title)}
|
|
;; the logo changed again after it was marked
|
|
{:change-key (:key logo) :fingerprint "what-it-was-before"}
|
|
;; a change the comparison no longer lists
|
|
{:change-key "shape/p/gone" :fingerprint "x"}])]
|
|
(await
|
|
(mock/with-mocks* {rp/cmd! (review-stub calls marks false)}
|
|
(let [store (make-store)]
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(await (async/wait-for-store store #(seq (reviewed store)) "the marks load"))
|
|
(t/is (= #{(:key title)} (reviewed store)))
|
|
(t/is (= {:branch-id (:id branch) :direction :branch->main}
|
|
(last-call calls :get-branch-change-reviews))
|
|
"the marks are the ones of the direction compared")
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest ^:async marking-a-change-keeps-it-with-its-fingerprint
|
|
(let [calls (atom [])
|
|
branch {:id (uuid/next)}
|
|
marks (atom [])]
|
|
(await
|
|
(mock/with-mocks* {rp/cmd! (review-stub calls marks false)}
|
|
(let [store (make-store)]
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(await (async/wait-for #(some? (last-call calls :get-branch-change-reviews))
|
|
"the marks are asked for"))
|
|
(ptk/emit! store (dwb/toggle-diff-reviewed (:key logo) true))
|
|
(t/is (= #{(:key logo)} (reviewed store)) "the mark shows at once")
|
|
(await (async/wait-for #(some? (last-call calls :set-branch-change-review))
|
|
"the mark is kept"))
|
|
(t/is (= {:branch-id (:id branch)
|
|
:direction :branch->main
|
|
:change-key (:key logo)
|
|
:fingerprint (dwb/change-fingerprint logo)
|
|
:reviewed true}
|
|
(last-call calls :set-branch-change-review)))
|
|
(ptk/emit! store (dwb/toggle-diff-reviewed (:key logo)))
|
|
(t/is (= #{} (reviewed store)) "without a side it flips")
|
|
(await (async/wait-for #(false? (:reviewed (last-call calls :set-branch-change-review)))
|
|
"the mark is cleared"))
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest ^:async a-mark-that-cannot-be-kept-does-not-stay
|
|
(let [calls (atom [])
|
|
branch {:id (uuid/next)}
|
|
marks (atom [])]
|
|
(await
|
|
(mock/with-mocks* {rp/cmd! (review-stub calls marks true)}
|
|
(let [store (make-store)]
|
|
(ptk/emit! store (dwb/fetch-branch-diff (:id branch)))
|
|
(await (async/wait-for #(some? (last-call calls :get-branch-change-reviews))
|
|
"the marks are asked for"))
|
|
(ptk/emit! store (dwb/toggle-diff-reviewed (:key title) true))
|
|
(await (async/wait-for-store store #(empty? (reviewed store))
|
|
"the marks are read again"))
|
|
(t/is (= #{} (reviewed store)))
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest the-fingerprint-follows-what-the-change-is
|
|
(t/is (= (dwb/change-fingerprint title) (dwb/change-fingerprint (assoc title :label "Title"))))
|
|
(t/is (not= (dwb/change-fingerprint title)
|
|
(dwb/change-fingerprint (assoc-in title [:changed-attrs :opacity :branch] 0.6))))
|
|
(t/is (not= (dwb/change-fingerprint title)
|
|
(dwb/change-fingerprint (assoc title :status :deleted)))))
|
|
|
|
;;; --- Branch switcher: the entry point of the menu and the shortcut ---
|
|
|
|
(defn- make-store-with
|
|
[state]
|
|
(ptk/store {:state state
|
|
:on-error (fn [cause] (t/is false (str cause)))}))
|
|
|
|
(def ^:private file-id (uuid/next))
|
|
|
|
(def ^:private main-without-branches
|
|
{:current-file-id file-id
|
|
:files {file-id {:id file-id :name "Checkout"}}
|
|
:workspace-branch-count {:file-id file-id :count 0}
|
|
:workspace-branch-context {:file-id file-id :loaded? true :info nil}})
|
|
|
|
(def ^:private main-with-branches
|
|
(assoc main-without-branches :workspace-branch-count {:file-id file-id :count 1}))
|
|
|
|
(def ^:private on-a-branch
|
|
(assoc main-without-branches :workspace-branch-context
|
|
{:file-id file-id :loaded? true :info {:id (uuid/next) :name "feature-login"}}))
|
|
|
|
(t/deftest the-switcher-only-exists-once-the-file-has-branches
|
|
(t/is (false? (dwb/has-branches? main-without-branches)))
|
|
(t/is (true? (dwb/has-branches? main-with-branches)))
|
|
(t/is (true? (dwb/has-branches? on-a-branch))
|
|
"a branch counts even before the count loads"))
|
|
|
|
(t/deftest the-listing-never-decides-whether-the-switcher-exists
|
|
(t/is (true? (dwb/has-branches? (assoc main-with-branches :workspace-branches {:status :error})))
|
|
"a failed listing keeps the switcher")
|
|
(t/is (true? (dwb/has-branches? (assoc main-with-branches :workspace-branches {:status :loading})))
|
|
"a loading listing keeps the switcher")
|
|
(t/is (false? (dwb/has-branches? (assoc main-without-branches :workspace-branches
|
|
{:status :loaded :data [{:id (uuid/next)}]})))
|
|
"the count decides, not a listing left over from another file"))
|
|
|
|
(t/deftest ^:async a-failed-listing-is-an-error-not-an-empty-list
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [_ _] (rx/throw (ex-info "network" {}))))}
|
|
(let [store (make-store-with main-with-branches)]
|
|
(ptk/emit! store (dwb/init-branches-state))
|
|
(await (async/wait-for #(not= :loading (get-in @store [:workspace-branches :status]))
|
|
"the listing settles"))
|
|
(t/is (= :error (get-in @store [:workspace-branches :status])))
|
|
(t/is (nil? (get-in @store [:workspace-branches :data])))
|
|
(t/is (true? (dwb/has-branches? @store)) "the switcher stays")
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async the-count-loads-without-the-listing
|
|
(let [calls (atom [])]
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(rx/of {:count 3})))}
|
|
(let [store (make-store-with (dissoc main-without-branches :workspace-branch-count))]
|
|
(ptk/emit! store (dwb/fetch-branch-count))
|
|
(await (async/wait-for #(some? (:workspace-branch-count @store)) "the count lands"))
|
|
(t/is (= {:file-id file-id :count 3} (:workspace-branch-count @store)))
|
|
(t/is (= [[:get-file-branch-count {:file-id file-id}]] @calls)
|
|
"only the count is asked, never the listing")
|
|
(t/is (true? (dwb/has-branches? @store)))
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest ^:async the-count-of-another-file-is-dropped-at-once
|
|
(let [other (uuid/next)]
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [_ _] (rx/subject)))}
|
|
(let [store (make-store-with (assoc main-with-branches :workspace-branch-count
|
|
{:file-id other :count 4}))]
|
|
(ptk/emit! store (dwb/fetch-branch-count))
|
|
(t/is (nil? (:workspace-branch-count @store)))
|
|
(t/is (false? (dwb/has-branches? @store)))
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest ^:async a-failed-count-shows-the-switcher-with-an-error
|
|
(await (mock/with-mocks*
|
|
{cf/flags (conj cf/flags :branching)
|
|
rp/cmd! (mock/stub (fn [_ _] (rx/throw (ex-info "network" {}))))}
|
|
(let [store (make-store-with (dissoc main-without-branches :workspace-branch-count))]
|
|
(ptk/emit! store (dwb/fetch-branch-count))
|
|
(await (async/wait-for #(some? (:workspace-branch-count @store)) "the count settles"))
|
|
(t/is (= {:file-id file-id :status :error} (:workspace-branch-count @store)))
|
|
(t/is (true? (dwb/branch-count-failed? @store)))
|
|
(t/is (true? (dwb/has-branches? @store))
|
|
"a count that failed never hides the switcher")
|
|
(ptk/emit! store (dwb/show-branches))
|
|
(await (async/wait-for #(some? (::modal/modal @store))
|
|
"the shortcut opens the branches dialog, which retries"))
|
|
(t/is (= :branches-list (get-in @store [::modal/modal :type]))
|
|
"no create dialog on an unknown count")
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async a-listing-after-a-failed-count-settles-it
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [cmd _]
|
|
(case cmd
|
|
:get-file-branch-info (rx/of nil)
|
|
:get-file-branches (rx/of [{:id (uuid/next) :status "open"}])
|
|
(rx/empty))))}
|
|
(let [store (make-store-with (assoc main-without-branches :workspace-branch-count
|
|
{:file-id file-id :status :error}))]
|
|
(ptk/emit! store (dwb/init-branches-state))
|
|
(await (async/wait-for #(= :loaded (get-in @store [:workspace-branches :status]))
|
|
"the listing lands"))
|
|
(t/is (= {:file-id file-id :count 1} (:workspace-branch-count @store)))
|
|
(t/is (false? (dwb/branch-count-failed? @store)))
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async a-listing-refreshes-the-count
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [cmd _]
|
|
(case cmd
|
|
:get-file-branch-info (rx/of nil)
|
|
:get-file-branches (rx/of [])
|
|
(rx/empty))))}
|
|
(let [store (make-store-with main-with-branches)]
|
|
(ptk/emit! store (dwb/fetch-branches))
|
|
(await (async/wait-for #(= :loaded (get-in @store [:workspace-branches :status]))
|
|
"the listing lands"))
|
|
(t/is (= 0 (get-in @store [:workspace-branch-count :count]))
|
|
"deleting the last branch from the listing hides the switcher")
|
|
(t/is (false? (dwb/has-branches? @store)))
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async a-pull-request-from-the-open-branch-saves-first-without-the-listing
|
|
(let [waits (atom 0)
|
|
branch-id (uuid/next)]
|
|
(await (mock/with-mocks*
|
|
{dwp/wait-persisted (mock/stub (fn [& _] (swap! waits inc) (rx/of :saved)))
|
|
rp/cmd! (mock/stub (fn [_ _] (rx/empty)))}
|
|
;; the bottom banner opens the dialog with the branch context;
|
|
;; the listing only loads with the switcher, so it is absent
|
|
(let [store (make-store-with
|
|
(assoc main-without-branches :workspace-branch-context
|
|
{:file-id file-id
|
|
:loaded? true
|
|
:info {:id branch-id :branch-file-id file-id}}))]
|
|
(ptk/emit! store (dwpr/create-pull-request branch-id {:title "Review me"}))
|
|
(await (async/wait-for #(pos? @waits) "the pending edits are saved first"))
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest the-switcher-toggles-and-can-be-forced
|
|
(let [store (make-store-with main-with-branches)]
|
|
(ptk/emit! store (dwb/toggle-branch-switcher))
|
|
(t/is (true? (:workspace-branch-switcher @store)))
|
|
(ptk/emit! store (dwb/toggle-branch-switcher))
|
|
(t/is (false? (:workspace-branch-switcher @store)))
|
|
(ptk/emit! store (dwb/toggle-branch-switcher true))
|
|
(ptk/emit! store (dwb/toggle-branch-switcher true))
|
|
(t/is (true? (:workspace-branch-switcher @store)) "forcing it open twice keeps it open")
|
|
(rx/dispose! store)))
|
|
|
|
(t/deftest ^:async show-branches-opens-the-branches-dialog-when-there-are-branches
|
|
(await (mock/with-mocks*
|
|
{cf/flags (conj cf/flags :branching)}
|
|
(let [store (make-store-with (assoc main-with-branches :workspace-branch-switcher true))]
|
|
(ptk/emit! store (dwb/show-branches))
|
|
(await (async/wait-for #(some? (::modal/modal @store))
|
|
"the branches dialog opens"))
|
|
(t/is (= :branches-list (get-in @store [::modal/modal :type])))
|
|
(t/is (false? (:workspace-branch-switcher @store)) "the switcher closes")
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async show-branches-asks-for-the-first-branch-when-there-are-none
|
|
(await (mock/with-mocks*
|
|
{cf/flags (conj cf/flags :branching)}
|
|
(let [store (make-store-with main-without-branches)]
|
|
(ptk/emit! store (dwb/show-branches))
|
|
(await (async/wait-for #(some? (::modal/modal @store))
|
|
"the create dialog opens"))
|
|
(t/is (= :create-branch (get-in @store [::modal/modal :type])))
|
|
(t/is (not (:workspace-branch-switcher @store)))
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async show-branches-does-nothing-without-the-flag
|
|
(await (mock/with-mocks*
|
|
{cf/flags (disj cf/flags :branching)}
|
|
(let [store (make-store-with main-without-branches)]
|
|
(ptk/emit! store (dwb/show-branches))
|
|
(await (async/settle))
|
|
(t/is (nil? (::modal/modal @store)))
|
|
(t/is (nil? (:workspace-branch-switcher @store)))
|
|
(rx/dispose! store)))))
|
|
|
|
(t/deftest ^:async opening-a-branch-closes-the-switcher-and-navigates
|
|
(let [navigations (atom [])
|
|
branch-id (uuid/next)]
|
|
(await (mock/with-mocks*
|
|
{dcm/go-to-workspace
|
|
(fn [& {:as params}]
|
|
(swap! navigations conj params)
|
|
(ptk/data-event ::navigated params))}
|
|
(let [store (make-store-with (assoc main-with-branches :workspace-branch-switcher true))]
|
|
(ptk/emit! store (dwb/open-branch branch-id))
|
|
(await (async/wait-for #(seq @navigations) "it navigates"))
|
|
(t/is (false? (:workspace-branch-switcher @store)))
|
|
(t/is (= {:file-id branch-id} (first @navigations)))
|
|
(rx/dispose! store))))))
|
|
|
|
;;; --- Creating a branch: one path, from the open file ---
|
|
|
|
(t/deftest ^:async creating-a-branch-branches-the-open-file
|
|
(let [calls (atom [])
|
|
branch-id (uuid/next)
|
|
navigations (atom [])]
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(rx/of {:branch-file-id branch-id})))
|
|
dcm/go-to-workspace
|
|
(fn [& {:as params}]
|
|
(swap! navigations conj params)
|
|
(ptk/data-event ::navigated params))}
|
|
(let [store (make-store-with main-without-branches)]
|
|
(ptk/emit! store (dwb/create-branch "feature-login" "from the workspace"))
|
|
(await (async/wait-for #(seq @navigations) "it lands in the new branch"))
|
|
(t/is (= [[:create-file-branch
|
|
{:file-id file-id
|
|
:name "feature-login"
|
|
:description "from the workspace"}]]
|
|
@calls)
|
|
"it creates the branch from the open file, once")
|
|
(t/is (= [{:file-id branch-id}] @navigations)
|
|
"it opens the branch that was created")
|
|
(rx/dispose! store))))))
|
|
|
|
;;; --- Reviews dialog: the merges into main ---
|
|
|
|
(t/deftest ^:async the-merges-load-for-the-open-file
|
|
(let [calls (atom [])
|
|
merges [{:id (uuid/next) :branch-name "header" :comment "Ships it"}]]
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [cmd params]
|
|
(swap! calls conj [cmd params])
|
|
(rx/of merges)))}
|
|
(let [store (make-store-with main-without-branches)]
|
|
(ptk/emit! store (dwb/fetch-branch-merges))
|
|
(await (async/wait-for #(= :loaded (get-in @store [:workspace-branch-merges :status]))
|
|
"the merges land"))
|
|
(t/is (= merges (get-in @store [:workspace-branch-merges :data])))
|
|
(t/is (= [[:get-file-branch-merges {:file-id file-id}]] @calls)
|
|
"the open file is asked as is: the command resolves a branch to main")
|
|
(rx/dispose! store))))))
|
|
|
|
(t/deftest ^:async a-failed-merges-load-is-an-error-not-an-empty-list
|
|
(await (mock/with-mocks*
|
|
{rp/cmd! (mock/stub (fn [_ _] (rx/throw (ex-info "network" {}))))}
|
|
(let [store (make-store-with main-without-branches)]
|
|
(ptk/emit! store (dwb/fetch-branch-merges))
|
|
(await (async/wait-for #(= :error (get-in @store [:workspace-branch-merges :status]))
|
|
"the failure lands"))
|
|
(t/is (nil? (get-in @store [:workspace-branch-merges :data])))
|
|
(rx/dispose! store)))))
|