-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move frontend tests to common #4535
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5611fcf
:wrench: Add generator function for update-shapes
hirunatan a40afd5
:white_check_mark: Add test for touched shapes
hirunatan 77d4901
:white_check_mark: Add more tests for touched
hirunatan de6d8cc
:white_check_mark: Small fix on components touched test
pabloalba File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
common/test/common_tests/logic/components_touched_test.cljc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
;; 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 | ||
|
||
(ns common-tests.logic.components-touched-test | ||
(:require | ||
[app.common.files.changes-builder :as pcb] | ||
[app.common.files.libraries-helpers :as cflh] | ||
[clojure.test :as t] | ||
[common-tests.helpers.compositions :as tho] | ||
[common-tests.helpers.files :as thf] | ||
[common-tests.helpers.ids-map :as thi])) | ||
|
||
(t/use-fixtures :each thi/test-fixture) | ||
|
||
(t/deftest test-touched-when-changing-attribute | ||
(let [;; Setup | ||
file (-> (thf/sample-file :file1) | ||
(tho/add-simple-component-with-copy :component1 | ||
:main-root | ||
:main-child | ||
:copy-root | ||
:main-child-params {:fills (thf/sample-fills-color | ||
:fill-color "#abcdef")})) | ||
page (thf/current-page file) | ||
copy-root (thf/get-shape file :copy-root) | ||
|
||
;; Action | ||
update-fn (fn [shape] | ||
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) | ||
|
||
changes (cflh/generate-update-shapes (pcb/empty-changes nil (:id page)) | ||
(:shapes copy-root) | ||
update-fn | ||
(:objects page) | ||
{}) | ||
|
||
file' (thf/apply-changes file changes) | ||
|
||
;; Get | ||
copy-root' (thf/get-shape file' :copy-root) | ||
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root'))) | ||
fills' (:fills copy-child') | ||
fill' (first fills')] | ||
|
||
;; Check | ||
(t/is (= (count fills') 1)) | ||
(t/is (= (:fill-color fill') "#fabada")) | ||
(t/is (= (:fill-opacity fill') 1)) | ||
(t/is (= (:touched copy-root') nil)) | ||
(t/is (= (:touched copy-child') #{:fill-group})))) | ||
|
||
(t/deftest test-not-touched-when-adding-shape | ||
(let [;; Setup | ||
file (-> (thf/sample-file :file1) | ||
(tho/add-simple-component-with-copy :component1 | ||
:main-root | ||
:main-child | ||
:copy-root) | ||
(thf/add-sample-shape :free-shape)) | ||
|
||
page (thf/current-page file) | ||
|
||
;; Action | ||
;; IMPORTANT: as modifying copies structure is now forbidden, this action | ||
;; will not have any effect, and so the parent shape won't also be touched. | ||
changes (cflh/generate-relocate-shapes (pcb/empty-changes) | ||
(:objects page) | ||
#{(thi/id :copy-root)} ; parents | ||
(thi/id :copy-root) ; parent-id | ||
(:id page) ; page-id | ||
0 ; to-index | ||
#{(thi/id :free-shape)}) ; ids | ||
|
||
file' (thf/apply-changes file changes) | ||
|
||
;; Get | ||
copy-root' (thf/get-shape file' :copy-root) | ||
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] | ||
|
||
;; Check | ||
(t/is (= (:touched copy-root') nil)) | ||
(t/is (= (:touched copy-child') nil)))) | ||
|
||
(t/deftest test-touched-when-deleting-shape | ||
(let [;; Setup | ||
file (-> (thf/sample-file :file1) | ||
(tho/add-simple-component-with-copy :component1 | ||
:main-root | ||
:main-child | ||
:copy-root)) | ||
|
||
page (thf/current-page file) | ||
copy-root (thf/get-shape file :copy-root) | ||
|
||
;; Action | ||
;; IMPORTANT: as modifying copies structure is now forbidden, this action will not | ||
;; delete the child shape, but hide it (thus setting the visibility group). | ||
[_all-parents changes] | ||
(cflh/generate-delete-shapes (pcb/empty-changes) | ||
file | ||
page | ||
(:objects page) | ||
(set (:shapes copy-root)) | ||
{:components-v2 true}) | ||
|
||
file' (thf/apply-changes file changes) | ||
|
||
;; Get | ||
copy-root' (thf/get-shape file' :copy-root) | ||
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] | ||
|
||
;; Check | ||
(t/is (= (:touched copy-root') nil)) | ||
(t/is (= (:touched copy-child') #{:visibility-group})))) | ||
|
||
(t/deftest test-not-touched-when-moving-shape | ||
(let [;; Setup | ||
file (-> (thf/sample-file :file1) | ||
(tho/add-component-with-many-children-and-copy :component1 | ||
:main-root | ||
[:main-child1 :main-child2 :main-child3] | ||
:copy-root) | ||
(thf/add-sample-shape :free-shape)) | ||
|
||
page (thf/current-page file) | ||
copy-root (thf/get-shape file :copy-root) | ||
copy-child1 (thf/get-shape-by-id file (first (:shapes copy-root))) | ||
|
||
;; Action | ||
;; IMPORTANT: as modifying copies structure is now forbidden, this action | ||
;; will not have any effect, and so the parent shape won't also be touched. | ||
changes (cflh/generate-relocate-shapes (pcb/empty-changes) | ||
(:objects page) | ||
#{(thi/id :copy-root)} ; parents | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the parent of the shape that you are moving: |
||
(thi/id :copy-root) ; parent-id | ||
(:id page) ; page-id | ||
2 ; to-index | ||
#{(:id copy-child1)}) ; ids | ||
|
||
file' (thf/apply-changes file changes) | ||
|
||
;; Get | ||
copy-root' (thf/get-shape file' :copy-root) | ||
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] | ||
|
||
;; Check | ||
(t/is (= (:touched copy-root') nil)) | ||
(t/is (= (:touched copy-child') nil)))) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the parent of the shape that you are moving:
#{(:parent-id (thf/get-shape :free-shape))}
Or in this caseuuid/zero