aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/date_utils/date_utils.spec.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-08-31 22:38:02 +0300
committerHenry Jameson <me@hjkos.com>2019-08-31 22:38:02 +0300
commit18ec13d796c0928d09fa93de4117822d2e35502c (patch)
tree1cfb4d68a246c604396bb64bbba3e69bdf4fe511 /test/unit/specs/services/date_utils/date_utils.spec.js
parentb3e9a5a71819c7d3a4b35c5b6ad551785a7ba44f (diff)
parent018a650166a5dce0878b696359a999ab67634cfc (diff)
Merge remote-tracking branch 'upstream/develop' into docs
* upstream/develop: (193 commits) fix user avatar fallback logic remove dead code make bio textarea resizable vertically only remove dead code remove dead code fix crazy watch logic in conversation show three dot button only if needed hide mute conversation button to guests update keyBy generate idObj at timeline level fix pin showing logic in conversation Show a message when JS is disabled Initialize chat only if user is logged in and it wasn't initialized before i18n/Update Japanese i18n/Update pedantic Japanese sync profile tab state with location query refactor TabSwitcher use better name of controlled prop fix potential bug to render active tab in controlled way remove unused param ...
Diffstat (limited to 'test/unit/specs/services/date_utils/date_utils.spec.js')
-rw-r--r--test/unit/specs/services/date_utils/date_utils.spec.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/unit/specs/services/date_utils/date_utils.spec.js b/test/unit/specs/services/date_utils/date_utils.spec.js
new file mode 100644
index 00000000..2d61dbac
--- /dev/null
+++ b/test/unit/specs/services/date_utils/date_utils.spec.js
@@ -0,0 +1,40 @@
+import * as DateUtils from 'src/services/date_utils/date_utils.js'
+
+describe('DateUtils', () => {
+ describe('relativeTime', () => {
+ it('returns now with low enough amount of seconds', () => {
+ const futureTime = Date.now() + 20 * DateUtils.SECOND
+ const pastTime = Date.now() - 20 * DateUtils.SECOND
+ expect(DateUtils.relativeTime(futureTime, 30)).to.eql({ num: 0, key: 'time.now' })
+ expect(DateUtils.relativeTime(pastTime, 30)).to.eql({ num: 0, key: 'time.now' })
+ })
+
+ it('rounds down for past', () => {
+ const time = Date.now() - 1.8 * DateUtils.HOUR
+ expect(DateUtils.relativeTime(time)).to.eql({ num: 1, key: 'time.hour' })
+ })
+
+ it('rounds up for future', () => {
+ const time = Date.now() + 1.8 * DateUtils.HOUR
+ expect(DateUtils.relativeTime(time)).to.eql({ num: 2, key: 'time.hours' })
+ })
+
+ it('uses plural when necessary', () => {
+ const time = Date.now() - 3.8 * DateUtils.WEEK
+ expect(DateUtils.relativeTime(time)).to.eql({ num: 3, key: 'time.weeks' })
+ })
+
+ it('works with date string', () => {
+ const time = Date.now() - 4 * DateUtils.MONTH
+ const dateString = new Date(time).toISOString()
+ expect(DateUtils.relativeTime(dateString)).to.eql({ num: 4, key: 'time.months' })
+ })
+ })
+
+ describe('relativeTimeShort', () => {
+ it('returns the short version of the same relative time', () => {
+ const time = Date.now() + 2 * DateUtils.YEAR
+ expect(DateUtils.relativeTimeShort(time)).to.eql({ num: 2, key: 'time.years_short' })
+ })
+ })
+})