Comment time bomb test out (#16452)
This commit is contained in:
parent
f015eb929a
commit
186ac482ee
|
@ -1,9 +1,7 @@
|
||||||
(ns utils.datetime-test
|
(ns utils.datetime-test
|
||||||
(:require [cljs-time.coerce :as time-coerce]
|
(:require [cljs-time.coerce :as time-coerce]
|
||||||
[cljs-time.core :as t]
|
[cljs-time.core :as t]
|
||||||
[cljs-time.format :as t.format]
|
[cljs.test :refer-macros [deftest testing is]]
|
||||||
[cljs.test :refer-macros [deftest testing is are]]
|
|
||||||
[clojure.string :as string]
|
|
||||||
[utils.datetime :as datetime]
|
[utils.datetime :as datetime]
|
||||||
[utils.i18n-goog :as i18n-goog]))
|
[utils.i18n-goog :as i18n-goog]))
|
||||||
|
|
||||||
|
@ -192,74 +190,76 @@
|
||||||
#'utils.datetime/medium-date-time-format)]
|
#'utils.datetime/medium-date-time-format)]
|
||||||
(is (= (datetime/day-relative epoch) "01 gen 1970, 12:00:00 AM")))))
|
(is (= (datetime/day-relative epoch) "01 gen 1970, 12:00:00 AM")))))
|
||||||
|
|
||||||
(deftest format-mute-till-test
|
;; TODO(@ibrkhalil): This test sometimes fail in the CI. Make the test agnostic
|
||||||
(let [remove-msecs #(string/replace % #"\.\w*Z" "Z")
|
;; of the current time and timezone.
|
||||||
time-str-to-obj #(t.format/parse (remove-msecs (time-coerce/to-string %)))
|
#_(deftest format-mute-till-test
|
||||||
curr-time (t/now)
|
(let [remove-msecs #(string/replace % #"\.\w*Z" "Z")
|
||||||
custom-HH-MM-formatter (t.format/formatter "HH:mm")
|
time-str-to-obj #(t.format/parse (remove-msecs (time-coerce/to-string %)))
|
||||||
custom-DD-formatter (t.format/formatter "DD")
|
curr-time (t/now)
|
||||||
get-hh-mm #(t.format/unparse custom-HH-MM-formatter %)
|
custom-HH-MM-formatter (t.format/formatter "HH:mm")
|
||||||
get-day #(t.format/unparse custom-DD-formatter %)
|
custom-DD-formatter (t.format/formatter "DD")
|
||||||
get-week-day #(->> %
|
get-hh-mm #(t.format/unparse custom-HH-MM-formatter %)
|
||||||
t/day-of-week
|
get-day #(t.format/unparse custom-DD-formatter %)
|
||||||
(get datetime/int->weekday))
|
get-week-day #(->> %
|
||||||
mock-today (t.format/unparse (t.format/formatters :date-time-no-ms) curr-time)
|
t/day-of-week
|
||||||
in-n-days #(-> (time-str-to-obj mock-today)
|
(get datetime/int->weekday))
|
||||||
(t/plus (t/days %)))
|
mock-today (t.format/unparse (t.format/formatters :date-time-no-ms) curr-time)
|
||||||
in-n-minutes #(-> (time-str-to-obj mock-today)
|
in-n-days #(-> (time-str-to-obj mock-today)
|
||||||
(t/plus (t/minutes %)))
|
(t/plus (t/days %)))
|
||||||
in-n-hours #(-> (time-str-to-obj mock-today)
|
in-n-minutes #(-> (time-str-to-obj mock-today)
|
||||||
(t/plus (t/hours %)))
|
(t/plus (t/minutes %)))
|
||||||
mock-tomorrow (in-n-days 1)
|
in-n-hours #(-> (time-str-to-obj mock-today)
|
||||||
mock-in-two-days (in-n-days 2)
|
(t/plus (t/hours %)))
|
||||||
mock-in-three-days (in-n-days 3)
|
mock-tomorrow (in-n-days 1)
|
||||||
mock-in-four-days (in-n-days 4)
|
mock-in-two-days (in-n-days 2)
|
||||||
mock-in-five-days (in-n-days 5)
|
mock-in-three-days (in-n-days 3)
|
||||||
mock-in-six-days (in-n-days 6)
|
mock-in-four-days (in-n-days 4)
|
||||||
mock-in-15-minutes (in-n-minutes 15)
|
mock-in-five-days (in-n-days 5)
|
||||||
mock-in-1-hour (in-n-hours 1)
|
mock-in-six-days (in-n-days 6)
|
||||||
mock-in-8-hour (in-n-hours 8)
|
mock-in-15-minutes (in-n-minutes 15)
|
||||||
get-month-day-int #(int (get-day %))
|
mock-in-1-hour (in-n-hours 1)
|
||||||
today? (fn [mocked curr-time]
|
mock-in-8-hour (in-n-hours 8)
|
||||||
(=
|
get-month-day-int #(int (get-day %))
|
||||||
(t.format/unparse (t.format/formatter "MM:DD") mocked)
|
today? (fn [mocked curr-time]
|
||||||
(t.format/unparse (t.format/formatter "MM:DD") curr-time)))
|
(=
|
||||||
tomorrow? (fn [mocked curr-time]
|
(t.format/unparse (t.format/formatter "MM:DD") mocked)
|
||||||
(some #(= %
|
(t.format/unparse (t.format/formatter "MM:DD") curr-time)))
|
||||||
(-
|
tomorrow? (fn [mocked curr-time]
|
||||||
(int (get-month-day-int mocked))
|
(some #(= %
|
||||||
(int (get-month-day-int curr-time))))
|
(-
|
||||||
[1 30 29 27]))
|
(int (get-month-day-int mocked))
|
||||||
form-full-date #(str (get-hh-mm %)
|
(int (get-month-day-int curr-time))))
|
||||||
" " (string/capitalize (get-week-day %))
|
[1 30 29 27]))
|
||||||
" " (get-month-day-int %)
|
form-full-date #(str (get-hh-mm %)
|
||||||
" " (string/capitalize (get datetime/months (t/month %))))
|
" " (string/capitalize (get-week-day %))
|
||||||
today-date #(str (get-hh-mm %) " today")
|
" " (get-month-day-int %)
|
||||||
tomorrow-date #(str (get-hh-mm %) " tomorrow")
|
" " (string/capitalize (get datetime/months (t/month %))))
|
||||||
write-date #(cond (today? % curr-time) (today-date %)
|
today-date #(str (get-hh-mm %) " today")
|
||||||
(tomorrow? % curr-time) (tomorrow-date %)
|
tomorrow-date #(str (get-hh-mm %) " tomorrow")
|
||||||
:else (form-full-date %))
|
write-date #(cond (today? % curr-time) (today-date %)
|
||||||
will-unmute-in-1-hour (remove-msecs (time-coerce/to-string mock-in-1-hour))
|
(tomorrow? % curr-time) (tomorrow-date %)
|
||||||
will-unmute-in-8-hours (remove-msecs (time-coerce/to-string mock-in-8-hour))
|
:else (form-full-date %))
|
||||||
will-unmute-in-15-mins (remove-msecs (time-coerce/to-string mock-in-15-minutes))
|
will-unmute-in-1-hour (remove-msecs (time-coerce/to-string mock-in-1-hour))
|
||||||
will-unmute-in-two-days (remove-msecs (time-coerce/to-string mock-in-two-days))
|
will-unmute-in-8-hours (remove-msecs (time-coerce/to-string mock-in-8-hour))
|
||||||
will-unmute-tomorrow (remove-msecs (time-coerce/to-string mock-tomorrow))
|
will-unmute-in-15-mins (remove-msecs (time-coerce/to-string mock-in-15-minutes))
|
||||||
will-unmute-in-three-days (remove-msecs (time-coerce/to-string mock-in-three-days))
|
will-unmute-in-two-days (remove-msecs (time-coerce/to-string mock-in-two-days))
|
||||||
will-unmute-in-four-days (remove-msecs (time-coerce/to-string mock-in-four-days))
|
will-unmute-tomorrow (remove-msecs (time-coerce/to-string mock-tomorrow))
|
||||||
will-unmute-in-five-days (remove-msecs (time-coerce/to-string mock-in-five-days))
|
will-unmute-in-three-days (remove-msecs (time-coerce/to-string mock-in-three-days))
|
||||||
will-unmute-in-six-days (remove-msecs (time-coerce/to-string mock-in-six-days))]
|
will-unmute-in-four-days (remove-msecs (time-coerce/to-string mock-in-four-days))
|
||||||
(testing "Mute for minutes and hours"
|
will-unmute-in-five-days (remove-msecs (time-coerce/to-string mock-in-five-days))
|
||||||
(are [arg expected] (= (datetime/format-mute-till arg) expected)
|
will-unmute-in-six-days (remove-msecs (time-coerce/to-string mock-in-six-days))]
|
||||||
will-unmute-in-15-mins (write-date mock-in-15-minutes)
|
(testing "Mute for minutes and hours"
|
||||||
will-unmute-in-1-hour (write-date mock-in-1-hour)
|
(are [arg expected] (= (datetime/format-mute-till arg) expected)
|
||||||
will-unmute-in-8-hours (write-date mock-in-8-hour)))
|
will-unmute-in-15-mins (write-date mock-in-15-minutes)
|
||||||
(testing "Weekdays"
|
will-unmute-in-1-hour (write-date mock-in-1-hour)
|
||||||
(are [arg expected] (= (datetime/format-mute-till arg) expected)
|
will-unmute-in-8-hours (write-date mock-in-8-hour)))
|
||||||
will-unmute-tomorrow (write-date mock-tomorrow)
|
(testing "Weekdays"
|
||||||
will-unmute-in-two-days (write-date mock-in-two-days)
|
(are [arg expected] (= (datetime/format-mute-till arg) expected)
|
||||||
will-unmute-in-three-days (write-date mock-in-three-days)
|
will-unmute-tomorrow (write-date mock-tomorrow)
|
||||||
will-unmute-in-four-days (write-date mock-in-four-days)
|
will-unmute-in-two-days (write-date mock-in-two-days)
|
||||||
will-unmute-in-five-days (write-date mock-in-five-days)
|
will-unmute-in-three-days (write-date mock-in-three-days)
|
||||||
will-unmute-in-six-days (write-date mock-in-six-days)))
|
will-unmute-in-four-days (write-date mock-in-four-days)
|
||||||
(testing "Until the user turns it back on"
|
will-unmute-in-five-days (write-date mock-in-five-days)
|
||||||
(is (= "you turn it back on" (datetime/format-mute-till datetime/go-default-time))))))
|
will-unmute-in-six-days (write-date mock-in-six-days)))
|
||||||
|
(testing "Until the user turns it back on"
|
||||||
|
(is (= "you turn it back on" (datetime/format-mute-till datetime/go-default-time))))))
|
||||||
|
|
Loading…
Reference in New Issue