connector-wordpress/source/front/formatter-test.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-04-13 21:10:28 +02:00
import test from 'ava'
import Formatter from './formatter.js'
2021-04-13 21:10:28 +02:00
2021-12-09 19:46:19 +01:00
test('#formatDate one date', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: '2021-04-15T15:30:00Z',
})
2021-05-05 10:13:16 +02:00
t.is(date, '15/04/2021 10:30 - 15:30')
2021-04-13 21:10:28 +02:00
})
2021-12-09 19:46:19 +01:00
test('#formatDate one date with short offset name', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: '2021-04-15T15:30:00Z',
isShortOffsetNameShown: true,
})
t.is(date, '15/04/2021 10:30 - 15:30 (UTC)')
})
2021-12-09 19:46:19 +01:00
test('#formatDate two dates', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: '2021-04-16T15:30:00Z',
})
2021-05-05 10:13:16 +02:00
t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30')
2021-04-13 21:10:28 +02:00
})
2021-12-09 19:46:19 +01:00
test('#formatDate two dates with short offset name', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: '2021-04-16T15:30:00Z',
isShortOffsetNameShown: true,
})
t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30 (UTC)')
})
test('#formatDate second date is null', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: null,
})
t.is(date, '15/04/2021 10:30')
})
test('#formatDate second date is null with short offset name', (t) => {
const date = Formatter.formatDate({
start: '2021-04-15T10:30:00Z',
end: null,
isShortOffsetNameShown: true,
})
t.is(date, '15/04/2021 10:30 (UTC)')
})
2021-12-09 19:46:19 +01:00
test('#formatLocation both parameters', (t) => {
const location = Formatter.formatLocation({ description: 'a', locality: 'b' })
t.is(location, 'a, b')
2021-04-13 21:10:28 +02:00
})
2021-12-09 19:46:19 +01:00
test('#formatLocation description only', (t) => {
const location = Formatter.formatLocation({ description: 'a' })
t.is(location, 'a')
})
test('#formatLocation description with space only', (t) => {
const location = Formatter.formatLocation({ description: ' ' })
t.is(location, '')
2021-04-13 21:10:28 +02:00
})
2021-12-09 19:46:19 +01:00
test('#formatLocation locality only', (t) => {
const location = Formatter.formatLocation({ locality: 'a' })
t.is(location, 'a')
2021-04-13 21:10:28 +02:00
})