2015-02-24 16:20:57 -08:00
|
|
|
moment = require 'moment'
|
|
|
|
React = require 'react/addons'
|
|
|
|
TestUtils = React.addons.TestUtils
|
2015-03-20 17:51:49 -07:00
|
|
|
MessageTimestamp = require '../lib/message-timestamp'
|
2015-02-24 16:20:57 -08:00
|
|
|
|
2015-08-12 14:52:03 -07:00
|
|
|
msgTime = ->
|
2016-01-11 17:23:04 -07:00
|
|
|
moment([2010, 1, 14, 15, 25, 50, 125]) # Feb 14, 2010 at 3:25 PM
|
2015-02-24 16:20:57 -08:00
|
|
|
|
|
|
|
describe "MessageTimestamp", ->
|
|
|
|
beforeEach ->
|
|
|
|
@item = TestUtils.renderIntoDocument(
|
2015-08-12 14:52:03 -07:00
|
|
|
<MessageTimestamp date={msgTime()} />
|
2015-02-24 16:20:57 -08:00
|
|
|
)
|
2015-03-09 11:17:22 -07:00
|
|
|
|
2015-08-12 14:52:03 -07: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-24 16:20:57 -08:00
|
|
|
|
2015-08-12 14:52:03 -07: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 07:06:57 -07:00
|
|
|
|
2015-08-12 14:52:03 -07:00
|
|
|
it "displays the time from messages shown today", ->
|
|
|
|
now = msgTime().add(2, 'hours')
|
2016-01-11 17:23:04 -07:00
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 PM"
|
2015-02-24 16:20:57 -08:00
|
|
|
|
2015-08-12 14:52:03 -07: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')
|
2016-01-11 17:23:04 -07:00
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 PM (21 hours ago)"
|
2015-02-24 16:20:57 -08:00
|
|
|
|
2015-08-12 14:52:03 -07:00
|
|
|
now = msgTime().add(30, 'hours')
|
2016-01-11 17:23:04 -07:00
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "3:25 PM (a day ago)"
|
2015-02-24 16:20:57 -08:00
|
|
|
|
2015-08-12 14:52:03 -07: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-09 11:17:22 -07:00
|
|
|
|
2015-08-12 14:52:03 -07:00
|
|
|
it "displays month, day, and year for messages over a year ago", ->
|
|
|
|
now = msgTime().add(2, 'years')
|
2015-08-28 11:12:53 -07:00
|
|
|
expect(@item._formattedDate(msgTime(), now)).toBe "Feb 14, 2010"
|