Skip to content

Commit

Permalink
Make find-wrapper-parent to handle followups
Browse files Browse the repository at this point in the history
  • Loading branch information
SalamaGofore authored and hajoa committed Nov 22, 2024
1 parent b81a3c8 commit a7f9199
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
23 changes: 22 additions & 1 deletion spec/ataru/util_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[ataru.fixtures.answer :refer [answer]]
[ataru.fixtures.person-info-form :refer [form]]
[ataru.component-data.person-info-module :as person-module]
[ataru.component-data.kk-application-payment-module :as payment-module]
[medley.core :refer [find-first]]
[ataru.component-data.kk-application-payment-module :as payment-module :refer [kk-application-payment-wrapper-key asiakasnumero-migri-key kk-application-payment-choice-key]]
[ataru.util :as util]))

(def form-with-visibility-conditions (assoc form :content [(person-module/person-info-module :onr-kk-application-payment)
Expand Down Expand Up @@ -53,6 +54,26 @@
payment-wrapper
false))))

(describe "find-wrapper-parent"
(tags :unit :form)

(it "returns nil for element with no parent"
(let [flattened-form (util/flatten-form-fields (:content form-with-visibility-conditions))
wrapper-field (find-first #(= (:id %) kk-application-payment-wrapper-key) flattened-form)]
(should= nil (util/find-wrapper-parent flattened-form wrapper-field))))

(it "finds parent that is wrapper"
(let [flattened-form (util/flatten-form-fields (:content form-with-visibility-conditions))
choice-field (find-first #(= (:id %) kk-application-payment-choice-key) flattened-form)]
(should= kk-application-payment-wrapper-key
(:id (util/find-wrapper-parent flattened-form choice-field)))))

(it "finds grandparent that is wrapper"
(let [flattened-form (util/flatten-form-fields (:content form-with-visibility-conditions))
migri-field (find-first #(= (:id %) asiakasnumero-migri-key) flattened-form)]
(should= kk-application-payment-wrapper-key
(:id (util/find-wrapper-parent flattened-form migri-field))))))

(def field-descriptor-id "64d4a625-370b-4814-ae4f-d5956e8881be")
(def field-descriptor {:id field-descriptor-id
:label {:fi "Pohjakoulutuksesi?" :sv ""}
Expand Down
2 changes: 1 addition & 1 deletion src/clj/ataru/hakija/validator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
(apply disj (set answer-keys) form-keys))

(defn- passed? [has-applied form flattened-form-fields answer validators answers-by-key field-descriptor virkailija?]
(let [wrapper-parent (util/findWrapperParent flattened-form-fields field-descriptor)
(let [wrapper-parent (util/find-wrapper-parent flattened-form-fields field-descriptor)
parent-hidden? (and (some? wrapper-parent) (util/is-field-hidden-by-section-visibility-conditions form answers-by-key wrapper-parent false))]
(or parent-hidden?
(every? (fn [validator]
Expand Down
9 changes: 4 additions & 5 deletions src/cljc/ataru/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@
rest-of-fields)
acc)))})))

(defn findWrapperParent [flat-form-fields field]
(let [id (:id field)
parent-id (-> (find-first #(= (:id %) id) flat-form-fields)
:children-of)
(defn find-wrapper-parent [flat-form-fields field]
(let [field-from-flattened-fields (find-first #(= (:id %) (:id field)) flat-form-fields)
parent-id (or (:children-of field-from-flattened-fields) (:followup-of field-from-flattened-fields))
parent-element (find-first #(= (:id %) parent-id) flat-form-fields)]
(when parent-element
(if (= "wrapperElement" (:fieldClass parent-element))
parent-element
(findWrapperParent flat-form-fields parent-element)))))
(find-wrapper-parent flat-form-fields parent-element)))))

(def ^:private b-limit 1024)
(def ^:private kb-limit 102400)
Expand Down

0 comments on commit a7f9199

Please sign in to comment.