Skip to content

Commit

Permalink
Fix logic bug in intersects? (#648)
Browse files Browse the repository at this point in the history
* Fix intersects?

Fix logic bug in intersects?

* Update CHANGELOG with intersects? fix
  • Loading branch information
dgr authored Aug 25, 2024
1 parent e0ae5ab commit f7e7c3a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ A release with an intentional breaking changes is marked with:
** {issue}559[#559]: Deprecate use of `:active` with `query` and other APIs that use `query` under the hood. ({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])

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

Expand Down
11 changes: 7 additions & 4 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1192,10 +1192,13 @@
[driver q1 q2]
(let [a (get-element-box driver q1)
b (get-element-box driver q2)]
(or (< (a :y1) (b :y2))
(> (a :y2) (b :y1))
(< (a :x2) (b :x1))
(> (a :x1) (b :x2)))))
;; Elements do not intersect if one element is above, below, left
;; or right of the other element. So, elements do intersect if
;; none of these conditions apply.
(not (or (> (a :y1) (b :y2))
(< (a :y2) (b :y1))
(< (a :x2) (b :x1))
(> (a :x1) (b :x2))))))

;;
;; properties
Expand Down
12 changes: 12 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,18 @@
(deftest test-driver-type
(is (#{:chrome :firefox :safari :edge} (e/driver-type *driver*))))

(deftest test-intersects
(testing "self-intersection"
;; Things must intersect with themselves
(is (e/intersects? *driver* {:class :target} {:class :target})))
(testing "non-intersection"
;; Choose two things near each other, that overlap in one
;; dimension, but not two
(is (not (e/intersects? *driver*
{:class :target}
[{:class :bar} {:class :deep}
{:class :inside} {:tag :span}])))))

(deftest test-timeouts
(let [timeouts {:implicit 32134
:script 78921
Expand Down

0 comments on commit f7e7c3a

Please sign in to comment.