__tests__.temporals.test.js Maven / Gradle / Ivy
import { interpretString } from 'components/render/utils/render'
import moment from 'helpers/moment'
let language
function setLanguage(lang) {
language = lang
moment.locale(lang)
}
test('Convert datetime string to human readable', () => {
setLanguage('nl')
expect(interpretString('2023-07-21T13:17:19.01Z', language)).toEqual('21 jul. 2023 15:17')
expect(interpretString('2023-11-10T12:13:14.15', language)).toEqual('10 nov. 2023 12:13')
expect(interpretString('1000-11-10T12:13:14.15', language)).toEqual('10 nov. 1000 12:13')
expect(interpretString('2023-11-10T10:10:10', language)).toEqual('10 nov. 2023 10:10')
expect(interpretString('2023-11-10T10:10:10', language)).toEqual('10 nov. 2023 10:10')
})
test('Convert date string to human readable', () => {
setLanguage("nl")
expect(interpretString('2023-10-10', language)).toEqual('10 okt. 2023')
setLanguage("en")
expect(interpretString('2023-10-10', language)).toEqual('10 Oct 2023')
})
test('Convert time string to human readable', () => {
setLanguage('nl')
expect(interpretString('10:11:12', language)).toEqual('10:11')
expect(interpretString('10:11:12.23', language)).toEqual('10:11')
expect(interpretString('10:11:12.99', language)).toEqual('10:11')
//setLanguage('en')
//expect(interpretString('10:11:12', language)).toEqual('10:11 AM')
//expect(interpretString('10:11:12.23', language)).toEqual('10:11 AM')
//expect(interpretString('10:11:12.99', language)).toEqual('10:11 AM')
})
test('Convert period string to human readable', () => {
setLanguage('nl')
expect(interpretString('PT1H10M', language)).toEqual('1 u 10 min')
expect(interpretString('P1DT1H10M', language)).toEqual('1 d 1 u 10 min')
expect(interpretString('P1QT1H10M', language)).toEqual('P1QT1H10M')
})
test('Should not be interpreted', () => {
setLanguage("nl")
expect(interpretString('P1QT1H10M', language)).toEqual('P1QT1H10M')
expect(interpretString('23-10-10T10:10:10.01', language)).toEqual('23-10-10T10:10:10.01')
expect(interpretString('2023', language)).toEqual('2023')
expect(interpretString('2023-10', language)).toEqual('2023-10')
expect(interpretString('2023.10.10', language)).toEqual('2023.10.10')
expect(interpretString('2023-99-99', language)).toEqual('2023-99-99')
expect(interpretString('2023-10-10T10', language)).toEqual('2023-10-10T10')
expect(interpretString('2023-10-10T10:10', language)).toEqual('2023-10-10T10:10')
})