[Date] Relative date badge (#2244)

Close #749
This commit is contained in:
Ang YC
2019-01-05 00:32:38 +08:00
committed by Paul Melnikow
parent 576f30fce5
commit f6357da8ee
5 changed files with 110 additions and 0 deletions

View File

@@ -109,6 +109,12 @@ function formatDate(d) {
return dateString.replace(` ${moment().year()}`, '').toLowerCase()
}
function formatRelativeDate(timestamp) {
return moment()
.to(moment.unix(parseInt(timestamp, 10)))
.toLowerCase()
}
function renderTestResultMessage({
passed,
failed,
@@ -193,6 +199,7 @@ module.exports = {
addv,
maybePluralize,
formatDate,
formatRelativeDate,
renderTestResultMessage,
renderTestResultBadge,
}

View File

@@ -11,6 +11,7 @@ const {
addv,
maybePluralize,
formatDate,
formatRelativeDate,
renderTestResultMessage,
renderTestResultBadge,
} = require('./text-formatters')
@@ -100,6 +101,28 @@ describe('Text formatters', function() {
})
})
context('in october', function() {
let clock
beforeEach(function() {
clock = sinon.useFakeTimers(new Date(2018, 9, 29).getTime())
})
afterEach(function() {
clock.restore()
})
test(formatRelativeDate, () => {
given(new Date(2018, 9, 31).getTime() / 1000)
.describe('when given the end of october')
.expect('in 2 days')
})
test(formatRelativeDate, () => {
given(new Date(2018, 9, 1).getTime() / 1000)
.describe('when given the beginning of october')
.expect('a month ago')
})
})
function renderBothStyles(props) {
const { message: standardMessage, color } = renderTestResultBadge(props)
const compactMessage = renderTestResultMessage({