2015-02-25 08:20:57 +08:00
|
|
|
moment = require 'moment'
|
|
|
|
React = require 'react/addons'
|
|
|
|
TestUtils = React.addons.TestUtils
|
2015-03-21 08:51:49 +08:00
|
|
|
MessageTimestamp = require '../lib/message-timestamp'
|
2015-02-25 08:20:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
msgTime = ->
|
|
|
|
moment([2010, 1, 14, 15, 25, 50, 125]) # Feb 14, 2010 at 3:25pm
|
2015-02-25 08:20:57 +08:00
|
|
|
|
|
|
|
describe "MessageTimestamp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@item = TestUtils.renderIntoDocument(
|
2015-08-13 05:52:03 +08:00
|
|
|
<MessageTimestamp date={msgTime()} />
|
2015-02-25 08:20:57 +08:00
|
|
|
)
|
2015-03-10 02:17:22 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "still processes one day, even if it crosses a month divider", ->
|
|
|
|
# this should be tested in moment.js, but we add a test here for our own sanity too
|
|
|
|
feb28 = moment([2015, 1, 28])
|
|
|
|
mar01 = moment([2015, 2, 1])
|
|
|
|
expect(mar01.diff(feb28, 'days')).toBe 1
|
2015-02-25 08:20:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "displays the full time when in detailed timestamp mode", ->
|
|
|
|
expect(@item._formattedDate(msgTime(), null, true)).toBe "February 14, 2010 at 3:25 PM"
|
2015-06-26 22:06:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "displays the time from messages shown today", ->
|
|
|
|
now = msgTime().add(2, 'hours')
|
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 pm"
|
2015-02-25 08:20:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "displays the time from messages yesterday with the relative time if it's less than 36 hours ago", ->
|
|
|
|
now = msgTime().add(21, 'hours')
|
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 pm (21 hours ago)"
|
2015-02-25 08:20:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
now = msgTime().add(30, 'hours')
|
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 pm (a day ago)"
|
2015-02-25 08:20:57 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "displays month, day for messages less than a year ago, but more than 24 hours ago", ->
|
|
|
|
now = msgTime().add(2, 'months')
|
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "Feb 14"
|
2015-03-10 02:17:22 +08:00
|
|
|
|
2015-08-13 05:52:03 +08:00
|
|
|
it "displays month, day, and year for messages over a year ago", ->
|
|
|
|
now = msgTime().add(2, 'years')
|
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "Feb 14, 2010"
|