-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#16377] fix: improve unit test and use i18n-goog for months
- Loading branch information
1 parent
58e24aa
commit 311731b
Showing
16 changed files
with
106 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 43 additions & 46 deletions
89
src/quo2/components/calendar/calendar/days_grid/utils_test.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
(ns quo2.components.calendar.calendar.days-grid.utils-test | ||
(:require [cljs.test :refer-macros [deftest is testing]] | ||
[quo2.components.calendar.calendar.days-grid.utils :as utils] | ||
[cljs-time.core :as time] | ||
[utils.number :as number-utils])) | ||
[cljs-time.core :as time])) | ||
|
||
(deftest calendar-days-grid-utils-test | ||
(testing "day-grid" | ||
(let [day-grid-result (utils/day-grid "2023" "7")] | ||
(testing "it returns correct days grid" | ||
(is (= 35 (count day-grid-result))) | ||
(is (time/equal? (time/date-time 2023 6 25) (first day-grid-result))) | ||
(is (time/equal? (time/date-time 2023 7 29) (last day-grid-result)))))) | ||
(deftest day-grid-test | ||
(let [day-grid-result (utils/day-grid "2023" "7")] | ||
(testing "it returns correct days grid" | ||
(is (= 35 (count day-grid-result))) | ||
(is (time/equal? (time/date-time 2023 6 25) (first day-grid-result))) | ||
(is (time/equal? (time/date-time 2023 7 29) (last day-grid-result)))))) | ||
|
||
(testing "get-day-state" | ||
(let [today (time/date-time 2023 7 27) | ||
year 2023 | ||
month 7 | ||
start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns :today when day equals today" | ||
(is (= :today (utils/get-day-state today today year month start-date end-date)))) | ||
(testing "it returns :selected when day equals start-date and not today" | ||
(is | ||
(= :selected (utils/get-day-state start-date today year month start-date end-date)))) | ||
(testing "it returns :selected when day equals end-date and not today" | ||
(is | ||
(= :selected (utils/get-day-state end-date today year month start-date end-date)))))) | ||
(deftest get-day-state-test | ||
(let [today (time/date-time 2023 7 27) | ||
year 2023 | ||
month 7 | ||
start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30)] | ||
(testing "it returns :today when day equals today" | ||
(is (= :today (utils/get-day-state today today year month start-date end-date)))) | ||
(testing "it returns :selected when day equals start-date and not today" | ||
(is | ||
(= :selected (utils/get-day-state start-date today year month start-date end-date)))) | ||
(testing "it returns :selected when day equals end-date and not today" | ||
(is | ||
(= :selected (utils/get-day-state end-date today year month start-date end-date)))))) | ||
|
||
(testing "update-range" | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns updated range" | ||
(is | ||
(= {:start-date day :end-date nil} (utils/update-range day start-date end-date)))))) | ||
(deftest update-range-test | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns updated range" | ||
(is | ||
(= {:start-date day :end-date nil} (utils/update-range day start-date end-date)))))) | ||
|
||
(testing "in-range?" | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns true when day is within range" | ||
(is (utils/in-range? day start-date end-date)) | ||
(is (not (utils/in-range? (time/date-time 2023 7 19) start-date end-date)))) | ||
(deftest in-range-test | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns true when day is within range" | ||
(is (utils/in-range? day start-date end-date)) | ||
(is (not (utils/in-range? (time/date-time 2023 7 19) start-date end-date)))))) | ||
|
||
(testing "get-in-range-pos" | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns correct position within range" | ||
(is (= :start (utils/get-in-range-pos start-date start-date end-date))) | ||
(is (= :end (utils/get-in-range-pos end-date start-date end-date))) | ||
(is (= :middle (utils/get-in-range-pos day start-date end-date))))))))) | ||
(deftest get-in-range-pos-test | ||
(let [start-date (time/date-time 2023 7 20) | ||
end-date (time/date-time 2023 7 30) | ||
day (time/date-time 2023 7 27)] | ||
(testing "it returns correct position within range" | ||
(is (= :start (utils/get-in-range-pos start-date start-date end-date))) | ||
(is (= :end (utils/get-in-range-pos end-date start-date end-date))) | ||
(is (= :middle (utils/get-in-range-pos day start-date end-date)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 2 additions & 18 deletions
20
src/quo2/components/calendar/calendar/month_picker/utils.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
src/quo2/components/calendar/calendar/month_picker/utils_test.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
(ns quo2.components.calendar.calendar.month-picker.utils-test | ||
(:require [cljs.test :refer-macros [deftest is testing]] | ||
[quo2.components.calendar.calendar.month-picker.utils :as utils] | ||
[utils.i18n :as i18n])) | ||
[quo2.components.calendar.calendar.month-picker.utils :as utils])) | ||
|
||
(deftest calendar-month-picker-utils-test | ||
(testing "format-month-year" | ||
(deftest format-month-year-test | ||
(testing "returns correct format for given year and month" | ||
(is (= (utils/format-month-year 2023 1) "January 2023")) | ||
(is (= (utils/format-month-year 2023 12) "December 2023")) | ||
(is (= (utils/format-month-year 2023 0) "January 2023")) | ||
(is (= (utils/format-month-year 2023 13) "December 2023"))) | ||
(is (= (utils/format-month-year 2023 13) "December 2023")))) | ||
|
||
(testing "next-month" | ||
(deftest next-month-test | ||
(testing "returns the next month and year" | ||
(is (= (utils/next-month 2023 1) {:year "2023" :month "2"})) | ||
(is (= (utils/next-month 2023 12) {:year "2024" :month "1"}))) | ||
(is (= (utils/next-month 2023 12) {:year "2024" :month "1"})))) | ||
|
||
(testing "previous-month" | ||
(deftest previous-month-test | ||
(testing "returns the previous month and year" | ||
(is (= (utils/previous-month 2023 1) {:year "2022" :month "12"})) | ||
(is (= (utils/previous-month 2023 12) {:year "2023" :month "11"})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/quo2/components/calendar/calendar/weekdays_header/style.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.