|
| 1 | +(ns logseq.e2e.property-scoped-choices-test |
| 2 | + (:require [clojure.test :refer [deftest use-fixtures]] |
| 3 | + [logseq.e2e.assert :as assert] |
| 4 | + [logseq.e2e.block :as b] |
| 5 | + [logseq.e2e.fixtures :as fixtures] |
| 6 | + [logseq.e2e.keyboard :as k] |
| 7 | + [logseq.e2e.locator :as loc] |
| 8 | + [logseq.e2e.page :as page] |
| 9 | + [logseq.e2e.util :as util] |
| 10 | + [wally.main :as w] |
| 11 | + [wally.repl :as repl])) |
| 12 | + |
| 13 | +(use-fixtures :once fixtures/open-page) |
| 14 | + |
| 15 | +(use-fixtures :each |
| 16 | + fixtures/new-logseq-page |
| 17 | + fixtures/validate-graph) |
| 18 | + |
| 19 | +(defn- add-property |
| 20 | + [property-name] |
| 21 | + (b/new-blocks ["setup"]) |
| 22 | + (w/click (util/get-by-text "setup" true)) |
| 23 | + (k/press "Control+e") |
| 24 | + (util/input-command "Add new property") |
| 25 | + (w/click "input[placeholder]") |
| 26 | + (util/input property-name) |
| 27 | + (w/click (w/get-by-text "New option:")) |
| 28 | + (w/click (loc/and "span" (util/get-by-text "Text" true))) |
| 29 | + (k/esc) |
| 30 | + (assert/assert-is-visible (format ".property-k:text('%s')" property-name))) |
| 31 | + |
| 32 | +(defn- add-tag-property |
| 33 | + [property-name] |
| 34 | + (w/click "button:has-text('Add tag property')") |
| 35 | + (w/click "input[placeholder='Add or change property']") |
| 36 | + (util/input property-name) |
| 37 | + (w/click (loc/filter "a.menu-link" :has-text property-name)) |
| 38 | + (assert/assert-is-visible (format ".property-k:text('%s')" property-name))) |
| 39 | + |
| 40 | +(defn- open-choices-pane |
| 41 | + [property-name] |
| 42 | + (w/click (loc/filter ".property-k" :has-text property-name)) |
| 43 | + (w/click (loc/filter "div[role='menuitem']" :has-text "Available choices"))) |
| 44 | + |
| 45 | +(defn- add-choice |
| 46 | + [property-name choice] |
| 47 | + (open-choices-pane property-name) |
| 48 | + (w/click (loc/filter "div[role='menuitem']" :has-text "Add choice")) |
| 49 | + (w/fill "input[placeholder='title']" choice) |
| 50 | + (w/click "button:has-text('Save')") |
| 51 | + (k/esc)) |
| 52 | + |
| 53 | +(defn- hide-choice-for-tag |
| 54 | + [property-name choice tag] |
| 55 | + (open-choices-pane property-name) |
| 56 | + (util/wait-timeout 100) |
| 57 | + (w/click (format ".choices-list li:has-text('%s') button[title='More settings']" choice)) |
| 58 | + (util/wait-timeout 100) |
| 59 | + (w/click (loc/filter "div[role='menuitem']" :has-text (str "Hide for #" tag))) |
| 60 | + (k/esc)) |
| 61 | + |
| 62 | +(defn- open-property-value-select |
| 63 | + [property-name] |
| 64 | + (w/click "div.jtrigger span:has-text('Empty')") |
| 65 | + (assert/assert-is-visible (format "input[placeholder='Set %s']" property-name)) |
| 66 | + (w/click (format "input[placeholder='Set %s']" property-name)) |
| 67 | + (assert/assert-is-visible ".cp__select-results")) |
| 68 | + |
| 69 | +(deftest tag-scoped-property-choices-test |
| 70 | + (let [tag "Device" |
| 71 | + property-name "device-type" |
| 72 | + scoped-choice "wired" |
| 73 | + global-choice "wireless"] |
| 74 | + (add-property property-name) |
| 75 | + (page/new-page tag) |
| 76 | + (page/convert-to-tag tag) |
| 77 | + (add-tag-property property-name) |
| 78 | + (add-choice property-name scoped-choice) |
| 79 | + (util/wait-timeout 100) |
| 80 | + (k/esc) |
| 81 | + (page/goto-page property-name) |
| 82 | + (add-choice property-name global-choice) |
| 83 | + (util/wait-timeout 100) |
| 84 | + (k/esc) |
| 85 | + (page/goto-page tag) |
| 86 | + ;; open tag properties |
| 87 | + (w/click (.first (w/-query "a.block-control"))) |
| 88 | + (hide-choice-for-tag property-name global-choice tag) |
| 89 | + (util/wait-timeout 100) |
| 90 | + (k/esc) |
| 91 | + (page/new-page "scoped-choices-test") |
| 92 | + (b/new-block "Device item") |
| 93 | + (util/set-tag tag) |
| 94 | + (open-property-value-select property-name) |
| 95 | + (assert/assert-is-visible (loc/filter ".cp__select-results" :has-text scoped-choice)) |
| 96 | + (assert/assert-have-count (loc/filter ".cp__select-results" :has-text global-choice) 0))) |
0 commit comments