Skip to content

Commit 5bbe8c7

Browse files
authored
Make vector arg to fill-multi/fill-human-multi fill in order (#652)
* Make vector arg to fill-multi/fill-human-multi fill in order Previously, if the user supplied a vector argument to fill-multi or fill-human-multi, Etaoin would convert the vector to a map, then convert the map to a sequence of MapEntry pairs, and use those to fill multiple fields. Unfortunately, this threw away all the ordering information in the vector. This change processes the vector as a sequence of partitioned pairs and thereby keeps the order intact. * Move CHANGELOG entries to correct section * Move CHANGELOG entries into correct sections * Remove "Docs" heading from CHANGELOG * Ordered CHANGELOG entries numerically
1 parent b24a866 commit 5bbe8c7

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

CHANGELOG.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ A release with an intentional breaking changes is marked with:
2222
* Changes
2323
** {issue}559[#559]: Create `query-from` and `query-all-from` as replacements for `child` and `children`. Rewrite logic such that `q` parameter allows for vector syntax similar to `query` and `query-all`. Deprecate `child` and `children`. ({person}dgr[@dgr])
2424
** {issue}559[#559]: Make `get-active-element` a public API. This was previously private. ({person}dgr[@dgr])
25-
** {issue}629[#629]: Added `fill-human-active` as a convenience function that fills the currently active input using `fill-human-el`. ({person}dgr[@dgr])
26-
** {issue}620[#620]: Get stricter when unwrapping elements. ({person}dgr[@dgr])
27-
* Docs
2825
** {issue}559[#559]: Deprecate use of `:active` with `query` and other APIs that use `query` under the hood. ({person}dgr[@dgr])
26+
** {issue}620[#620]: Get stricter when unwrapping elements. ({person}dgr[@dgr])
27+
** {issue}629[#629]: Added `fill-human-active` as a convenience function that fills the currently active input using `fill-human-el`. ({person}dgr[@dgr])
2928
** {issue}642[#642]: Add `driver-type` to retrieve driver type keyword. ({person}dgr[@dgr])
3029
** {issue}644[#644]: Deprecate `when-predicate` and `when-not-predicate` macros. See docstrings for guidance on alternatives. These will may be removed from the API at the next release that contains breaking changes. ({person}dgr[@dgr])
3130
** {issue}647[#647]: Fix logic bug in `intersects?`. Added tests to test suite. ({person}dgr[@dgr])
31+
** {issue}649[#649]: When supplied a vector argument for `q-text`, `fill-multi` and `fill-human-multi` now fill fields in the order that fields appear in the vector. Previously, the order was not guaranteed. ({person}dgr[@dgr])
3232

3333
== v1.1.41 [minor breaking] - 2024-08-14 [[v1.1.41]]
3434

src/etaoin/api.clj

+20-6
Original file line numberDiff line numberDiff line change
@@ -2743,8 +2743,10 @@
27432743
"Have `driver` fill multiple inputs via `q-text`.
27442744
27452745
`q-text` can be:
2746-
- a map of `{q1 \"text1\" q2 \"text2\" ...}`
2747-
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`
2746+
- a map of `{q1 \"text1\" q2 \"text2\" ...}`. There are no guarantees
2747+
about the order in which fields are filled.
2748+
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`. The fields are filled
2749+
in the order the fields are listed in the vector.
27482750
27492751
See [[query]] for details on `q`s."
27502752
[driver q-text]
@@ -2754,7 +2756,12 @@
27542756
(fill driver q text))
27552757

27562758
(vector? q-text)
2757-
(recur driver (apply hash-map q-text))
2759+
(if (even? (count q-text))
2760+
(doseq [[q text] (partition 2 q-text)]
2761+
(fill driver q text))
2762+
(throw+ {:type :etaoin/argument
2763+
:message "Vector q-text must have even length"
2764+
:arg q-text}))
27582765

27592766
:else (throw+ {:type :etaoin/argument
27602767
:message "Wrong argument type"
@@ -2809,8 +2816,10 @@
28092816
"Have `driver` fill multiple elements as if it were a real human being via `q-text` using `opts`.
28102817
28112818
`q-text` can be:
2812-
- a map of `{q1 \"text1\" q2 \"text2\" ...}`
2813-
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`
2819+
- a map of `{q1 \"text1\" q2 \"text2\" ...}`. There are no guarantees
2820+
about the order in which fields are filled.
2821+
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`. The fields are filled
2822+
in the order the fields are listed in the vector.
28142823
28152824
See [[query]] for details on `q`s.
28162825
@@ -2823,7 +2832,12 @@
28232832
(fill-human driver q text opts))
28242833

28252834
(vector? q-text)
2826-
(recur driver (apply hash-map q-text) opts)
2835+
(if (even? (count q-text))
2836+
(doseq [[q text] (partition 2 q-text)]
2837+
(fill driver q text))
2838+
(throw+ {:type :etaoin/argument
2839+
:message "Vector q-text must have even length"
2840+
:arg q-text}))
28272841

28282842
:else (throw+ {:type :etaoin/argument
28292843
:message "Wrong argument type"

0 commit comments

Comments
 (0)