|
| 1 | +const { formatRelativeDate } = require('../../util/relative-date-format') |
| 2 | + |
| 3 | +/* formatRelativeDate(new Date(), new Date(), 'en', { |
| 4 | +
|
| 5 | +}) */ |
| 6 | + |
| 7 | +describe('formatRelativeDate', () => { |
| 8 | + test('no arguments passed - should throw error', () => { |
| 9 | + expect(() => formatRelativeDate()).toThrow() |
| 10 | + }) |
| 11 | + |
| 12 | + describe('toDate passed as seven days ahead', () => { |
| 13 | + test('and locale default as "en" - should return "in 7 days"', () => { |
| 14 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 15 | + const formatted = formatRelativeDate(futureDate) |
| 16 | + expect(formatted).toBe('in 7 days' || 'in 1 week') |
| 17 | + }) |
| 18 | + |
| 19 | + test('and locale passed as "no" - should return "om 1 uke"', () => { |
| 20 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 21 | + const formatted = formatRelativeDate(futureDate, new Date(), 'no') |
| 22 | + expect(formatted).toBe('om 1 uke' || 'om 7 døgn') |
| 23 | + }) |
| 24 | + |
| 25 | + describe('numeric passed as', () => { |
| 26 | + test('"auto" - should return "next week" or "in 7 days"', () => { |
| 27 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 28 | + const formatted = formatRelativeDate(futureDate, new Date(), 'en', { numeric: 'auto' }) |
| 29 | + expect(formatted).toBe('next week' || 'in 7 days') |
| 30 | + }) |
| 31 | + |
| 32 | + test('"always" - should return "in 1 week"', () => { |
| 33 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 34 | + const formatted = formatRelativeDate(futureDate, new Date(), 'en', { numeric: 'always' }) |
| 35 | + expect(formatted).toBe('in 1 week') |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + describe('style passed as', () => { |
| 40 | + test('"long" - should return "in 1 week"', () => { |
| 41 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 42 | + const formatted = formatRelativeDate(futureDate, new Date(), 'en', { style: 'long' }) |
| 43 | + expect(formatted).toBe('in 1 week') |
| 44 | + }) |
| 45 | + |
| 46 | + test('"short" - should return "in 1 wk."', () => { |
| 47 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 48 | + const formatted = formatRelativeDate(futureDate, new Date(), 'en', { style: 'short' }) |
| 49 | + expect(formatted).toBe('in 1 wk.') |
| 50 | + }) |
| 51 | + |
| 52 | + test('"narrow" - should return "in 1 wk." or "in 7 days"', () => { |
| 53 | + const futureDate = new Date(new Date().setDate(new Date().getDate() + 7)) |
| 54 | + const formatted = formatRelativeDate(futureDate, new Date(), 'en', { style: 'narrow' }) |
| 55 | + expect(formatted).toBe('in 1 wk.' || 'in 7 days') |
| 56 | + }) |
| 57 | + }) |
| 58 | + }) |
| 59 | +}) |
0 commit comments