Skip to content

Commit

Permalink
Make vector arg to fill-multi/fill-human-multi fill in order (#652)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dgr authored Aug 31, 2024
1 parent b24a866 commit 5bbe8c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ A release with an intentional breaking changes is marked with:
* Changes
** {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])
** {issue}559[#559]: Make `get-active-element` a public API. This was previously private. ({person}dgr[@dgr])
** {issue}629[#629]: Added `fill-human-active` as a convenience function that fills the currently active input using `fill-human-el`. ({person}dgr[@dgr])
** {issue}620[#620]: Get stricter when unwrapping elements. ({person}dgr[@dgr])
* Docs
** {issue}559[#559]: Deprecate use of `:active` with `query` and other APIs that use `query` under the hood. ({person}dgr[@dgr])
** {issue}620[#620]: Get stricter when unwrapping elements. ({person}dgr[@dgr])
** {issue}629[#629]: Added `fill-human-active` as a convenience function that fills the currently active input using `fill-human-el`. ({person}dgr[@dgr])
** {issue}642[#642]: Add `driver-type` to retrieve driver type keyword. ({person}dgr[@dgr])
** {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])
** {issue}647[#647]: Fix logic bug in `intersects?`. Added tests to test suite. ({person}dgr[@dgr])
** {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])

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

Expand Down
26 changes: 20 additions & 6 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2743,8 +2743,10 @@
"Have `driver` fill multiple inputs via `q-text`.
`q-text` can be:
- a map of `{q1 \"text1\" q2 \"text2\" ...}`
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`
- a map of `{q1 \"text1\" q2 \"text2\" ...}`. There are no guarantees
about the order in which fields are filled.
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`. The fields are filled
in the order the fields are listed in the vector.
See [[query]] for details on `q`s."
[driver q-text]
Expand All @@ -2754,7 +2756,12 @@
(fill driver q text))

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

:else (throw+ {:type :etaoin/argument
:message "Wrong argument type"
Expand Down Expand Up @@ -2809,8 +2816,10 @@
"Have `driver` fill multiple elements as if it were a real human being via `q-text` using `opts`.
`q-text` can be:
- a map of `{q1 \"text1\" q2 \"text2\" ...}`
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`
- a map of `{q1 \"text1\" q2 \"text2\" ...}`. There are no guarantees
about the order in which fields are filled.
- a vector of `[q1 \"text1\" q2 \"text2\" ...]`. The fields are filled
in the order the fields are listed in the vector.
See [[query]] for details on `q`s.
Expand All @@ -2823,7 +2832,12 @@
(fill-human driver q text opts))

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

:else (throw+ {:type :etaoin/argument
:message "Wrong argument type"
Expand Down

0 comments on commit 5bbe8c7

Please sign in to comment.