Skip to content

Commit

Permalink
fix: calendar component specs to avoid duplicate day entries (#21164)
Browse files Browse the repository at this point in the history
This change attempts to fix the calendar component specs to avoid errors with finding multiple elements with the same text. Prior to this change it was possible for multiple elements to be found with the same number of the day, like "5", which caused the tests helpers to thrown an exception. Now the specs will use a different test helper to avoid the exceptions, and we've adjusted the test data to avoid duplicate day numbers too.
  • Loading branch information
seanstrom authored Sep 3, 2024
1 parent 97d4edc commit 5b75e1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/quo/components/calendar/calendar/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[quo.components.calendar.calendar.view :as calendar]
[test-helpers.component :as h]))

(def start-date (time/date-time (time/year (time/now)) (time/month (time/now)) 5))
(def start-date (time/date-time (time/year (time/now)) (time/month (time/now)) 8))
(def end-date (time/date-time (time/plus start-date (time/days 2))))

(h/describe "calendar component"
Expand All @@ -23,15 +23,15 @@
{:start-date nil
:end-date nil
:on-change on-change}])
(h/fire-event :press (h/query-by-text (str (time/day start-date))))
(h/fire-event :press (h/query-first-by-text (str (time/day start-date))))
(h/was-called-with on-change {:start-date start-date :end-date nil})))

(h/test "should call on-change with start and end date on second click"
(let [on-change (h/mock-fn)]
(h/render
[calendar/view
{:start-date start-date :end-date nil :on-change on-change}])
(h/fire-event :press (h/query-by-text (str (time/day end-date))))
(h/fire-event :press (h/query-first-by-text (str (time/day end-date))))
(h/was-called-with on-change {:start-date start-date :end-date end-date})))

(h/test "should reset the dates on third click"
Expand All @@ -41,7 +41,7 @@
{:start-date start-date
:end-date end-date
:on-change on-change}])
(h/fire-event :press (h/query-by-text (str (time/day start-date))))
(h/fire-event :press (h/query-first-by-text (str (time/day start-date))))
(h/was-called-with on-change {:start-date start-date :end-date nil})))

(h/test "should reset dates when start date is clicked again"
Expand All @@ -51,7 +51,7 @@
{:start-date start-date
:end-date nil
:on-change on-change}])
(h/fire-event :press (h/query-by-text (str (time/day start-date))))
(h/fire-event :press (h/query-first-by-text (str (time/day start-date))))
(h/was-called-with on-change {:start-date nil :end-date nil})))

(h/test "should assign start and end date correctly when upper range selected first"
Expand All @@ -61,5 +61,5 @@
{:start-date end-date
:end-date nil
:on-change on-change}])
(h/fire-event :press (h/query-by-text (str (time/day start-date))))
(h/fire-event :press (h/query-first-by-text (str (time/day start-date))))
(h/was-called-with on-change {:start-date start-date :end-date end-date}))))
1 change: 1 addition & 0 deletions src/test_helpers/component.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
(def get-by-text (with-node-or-screen :get-by-text))
(def query-all-by-text (with-node-or-screen :query-all-by-text))
(def query-by-text (with-node-or-screen :query-by-text))
(def query-first-by-text (comp first query-all-by-text))

(def get-all-by-label-text (with-node-or-screen :get-all-by-label-text))
(def get-by-label-text (with-node-or-screen :get-by-label-text))
Expand Down

0 comments on commit 5b75e1d

Please sign in to comment.