From fdb042f4e9d386b320ef4d88b8f3f9296a51e167 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Mon, 19 Jun 2023 09:21:44 +0100 Subject: [PATCH] chore: fix unit test for slide button (#16302) --- .../buttons/slide_button/component_spec.cljs | 27 ++++++++++++++----- src/quo2/core_spec.cljs | 5 ++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/quo2/components/buttons/slide_button/component_spec.cljs b/src/quo2/components/buttons/slide_button/component_spec.cljs index c72d1cd8e2..b56950cf73 100644 --- a/src/quo2/components/buttons/slide_button/component_spec.cljs +++ b/src/quo2/components/buttons/slide_button/component_spec.cljs @@ -63,6 +63,15 @@ :track-icon :face-id}) (h/describe "slide-button" + (h/before-each + (fn [] + (h/use-fake-timers))) + + (h/after-each + (fn [] + (h/clear-all-timers) + (h/use-real-timers))) + (h/test "render the correct text" (h/render [slide-button/view default-props]) (h/is-truthy (h/get-by-text :test-track-text))) @@ -90,9 +99,12 @@ slide-dest constants/default-width gesture-events (slide-events slide-dest)] (h/render [slide-button/view props]) - (-> (act #(gestures-jest/fireGestureHandler (get-by-gesture-test-id :slide-button-gestures) - gesture-events)) - (.then #(h/was-called (:on-complete props)))))) + (let [promise + (-> (act #(gestures-jest/fireGestureHandler (get-by-gesture-test-id :slide-button-gestures) + gesture-events)))] + (h/advance-timers-by-time 250) + (-> promise + (.then #(h/was-called (:on-complete props))))))) (h/test "doesn't call on-complete if the slide was incomplete" @@ -100,6 +112,9 @@ slide-dest (- constants/default-width 100) gesture-events (slide-events slide-dest)] (h/render [slide-button/view props]) - (-> (act #(gestures-jest/fireGestureHandler (get-by-gesture-test-id :slide-button-gestures) - gesture-events)) - (.then #(h/was-not-called (:on-complete props))))))) + (let [promise (-> (act #(gestures-jest/fireGestureHandler (get-by-gesture-test-id + :slide-button-gestures) + gesture-events)))] + (h/advance-timers-by-time 250) + (-> promise (.then #(h/was-not-called (:on-complete props)))))))) + diff --git a/src/quo2/core_spec.cljs b/src/quo2/core_spec.cljs index 2b11830769..b16d32b8c9 100644 --- a/src/quo2/core_spec.cljs +++ b/src/quo2/core_spec.cljs @@ -4,6 +4,7 @@ [quo2.components.banners.banner.component-spec] [quo2.components.buttons.--tests--.buttons-component-spec] [quo2.components.buttons.predictive-keyboard.component-spec] + [quo2.components.buttons.slide-button.component-spec] [quo2.components.colors.color-picker.component-spec] [quo2.components.counter.--tests--.counter-component-spec] [quo2.components.counter.step.component-spec] @@ -32,7 +33,7 @@ [quo2.components.selectors.filter.component-spec] [quo2.components.selectors.reactions.component-spec] [quo2.components.selectors.selectors.component-spec] + [quo2.components.settings.reorder-item.component-spec] [quo2.components.settings.settings-list.component-spec] [quo2.components.share.share-qr-code.component-spec] - [quo2.components.tags.--tests--.status-tags-component-spec] - [quo2.components.settings.reorder-item.component-spec])) + [quo2.components.tags.--tests--.status-tags-component-spec]))