import { expect } from 'chai' import { useFakeTimers } from 'sinon' import { humanizeTime, humanizeDate } from '../../js/utils/humanize' const ONE_MINUTE = 1000 * 60 const ONE_HOUR = ONE_MINUTE * 60 const sept2nd2017midnight = 1504310400000 const sept3rd2017midnight = 1504396800000 const sept4th2017midnight = 1504483200000 describe('humanize', () => { let clock: sinon.SinonFakeTimers before(() => { clock = useFakeTimers(sept4th2017midnight) }) after(() => { clock.restore() }) it('humanizeTime correctly', () => { expect(humanizeTime(sept4th2017midnight - 1)).to.equal('Now') expect(humanizeTime(sept4th2017midnight - (2 * ONE_MINUTE))).to.equal('2 min ago') expect(humanizeTime(sept4th2017midnight - (2 * ONE_MINUTE))).to.equal('2 min ago') expect(humanizeTime(sept4th2017midnight - (2 * ONE_HOUR))).to.equal('6:00 PM') expect(humanizeTime(sept3rd2017midnight)).to.equal('Sep 2') // timezones }) it('humanizeDate correctly', () => { expect(humanizeDate(sept4th2017midnight)).to.equal('Today') expect(humanizeDate(sept3rd2017midnight)).to.equal('Yesterday') expect(humanizeDate(sept2nd2017midnight)).to.equal('Sep 1') // timezones }) })