-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c5a155
commit b8f6c8a
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import { render } from '@test/setup'; | ||
import { FormatDate } from '@src'; | ||
import it from 'date-fns/locale/it'; | ||
|
||
const dateISO = '2019-10-14T11:55:39.058Z'; | ||
|
||
describe('FormatDate tests', () => { | ||
test('should render the date string in an human readable way', async () => { | ||
const { getByText } = render(<FormatDate date={dateISO} />); | ||
getByText('10/14/2019, 1:55 PM'); | ||
}); | ||
|
||
test('should render the date string accordingly to the passed format', async () => { | ||
const { getByText } = render(<FormatDate date={dateISO} format={'dMy'} />); | ||
getByText('14102019'); | ||
}); | ||
|
||
test('should render the date string respecting the date-fns config object', async () => { | ||
const { getByText } = render( | ||
<FormatDate date={dateISO} options={{ locale: it }} /> | ||
); | ||
getByText('14/10/2019 13:55'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react'; | ||
import { render } from '@test/setup'; | ||
import { FormatDistance } from '@src'; | ||
import it from 'date-fns/locale/it'; | ||
import { subDays } from 'date-fns'; | ||
|
||
const dateISO = '2019-10-14T11:55:39.058Z'; | ||
const todayMinusOneDay = subDays(new Date(dateISO), 1); | ||
const todayMinusTenDays = subDays(new Date(dateISO), 10); | ||
|
||
describe('FormatDistance tests', () => { | ||
test('should render the date string in an human readable way', async () => { | ||
const { getByText } = render(<FormatDistance date={todayMinusOneDay} />); | ||
getByText('1 day'); | ||
}); | ||
|
||
test('should render the date string accordingly to the passed format', async () => { | ||
const { getByText } = render( | ||
<FormatDistance date={todayMinusTenDays} base={todayMinusOneDay} /> | ||
); | ||
getByText('9 days'); | ||
}); | ||
|
||
test('should render the date string respecting the date-fns config object', async () => { | ||
const { getByText } = render( | ||
<FormatDistance date={todayMinusOneDay} options={{ locale: it }} /> | ||
); | ||
getByText('un giorno'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import { render } from '@test/setup'; | ||
import { FormatRelative } from '@src'; | ||
import it from 'date-fns/locale/it'; | ||
import { subDays } from 'date-fns'; | ||
|
||
const dateISO = '2019-10-14T11:55:39.058Z'; | ||
const todayMinusOneDay = subDays(new Date(dateISO), 1); | ||
|
||
describe('FormatRelative tests', () => { | ||
test('should render the relative time against today', async () => { | ||
const { getByText } = render(<FormatRelative date={todayMinusOneDay} />); | ||
getByText('yesterday at 1:55 PM'); | ||
}); | ||
|
||
test('should render the relative time using the passed base date', async () => { | ||
const { getByText } = render( | ||
<FormatRelative date={todayMinusOneDay} base={todayMinusOneDay} /> | ||
); | ||
getByText('today at 1:55 PM'); | ||
}); | ||
|
||
test('should render the relative time against today respecting the date-fns config object', async () => { | ||
const { getByText } = render( | ||
<FormatRelative date={todayMinusOneDay} options={{ locale: it }} /> | ||
); | ||
getByText('ieri alle 13:55'); | ||
}); | ||
}); |