From 5b75e1dca65f27efde9ff5a33425e5b2587909ad Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Tue, 3 Sep 2024 07:16:11 +0100 Subject: [PATCH] fix: calendar component specs to avoid duplicate day entries (#21164) 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. --- .../components/calendar/calendar/component_spec.cljs | 12 ++++++------ src/test_helpers/component.cljs | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/quo/components/calendar/calendar/component_spec.cljs b/src/quo/components/calendar/calendar/component_spec.cljs index d3d0cc1a44..f8ef5bddb8 100644 --- a/src/quo/components/calendar/calendar/component_spec.cljs +++ b/src/quo/components/calendar/calendar/component_spec.cljs @@ -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" @@ -23,7 +23,7 @@ {: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" @@ -31,7 +31,7 @@ (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" @@ -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" @@ -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" @@ -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})))) diff --git a/src/test_helpers/component.cljs b/src/test_helpers/component.cljs index 7e6f03c489..050f37b52d 100644 --- a/src/test_helpers/component.cljs +++ b/src/test_helpers/component.cljs @@ -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))