mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Add backup langauges and remove tests that aren't useful.
This commit is contained in:
parent
b450d36a64
commit
b1d4c6d1b5
2 changed files with 17 additions and 27 deletions
|
@ -35,7 +35,7 @@ const getTimeUnitAndDuration = timeStamp => {
|
|||
* @returns {string} A phrase representing the relative time in the future. e.g. 3 days 5 hours.
|
||||
*/
|
||||
module.exports.formatRelativeTime = (futureTime, lang) => {
|
||||
const formatter = new Intl.RelativeTimeFormat(lang, {
|
||||
const formatter = new Intl.RelativeTimeFormat([lang].concat(window.navigator.languages), {
|
||||
localeMatcher: 'best fit',
|
||||
numeric: 'always',
|
||||
style: 'long'
|
||||
|
|
|
@ -20,68 +20,58 @@ describe('unit test lib/format-time.js', () => {
|
|||
});
|
||||
|
||||
test('test timestamp that is 2 minutes in the future', () => {
|
||||
let response;
|
||||
const twoMin = 2 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 2 minutes');
|
||||
response = format.formatRelativeTime(twoMin, 'en');
|
||||
format.formatRelativeTime(twoMin, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(2, 'minute');
|
||||
expect(response).toEqual('in 2 minutes');
|
||||
});
|
||||
|
||||
test('test rounding timestamp that is 4.4 minutes rounds to 4', () => {
|
||||
let response;
|
||||
const twoMin = 4.4 * 60 * 1000;
|
||||
const fourPlusMin = 4.4 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 4 minutes');
|
||||
response = format.formatRelativeTime(twoMin, 'en');
|
||||
format.formatRelativeTime(fourPlusMin, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(4, 'minute');
|
||||
expect(response).toEqual('in 4 minutes');
|
||||
});
|
||||
|
||||
test('test timestamp that is 95.25 minutes in the future', () => {
|
||||
let response;
|
||||
const ninetyFiveMin = 95.25 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 95 minutes');
|
||||
response = format.formatRelativeTime(ninetyFiveMin, 'en');
|
||||
format.formatRelativeTime(ninetyFiveMin, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(95, 'minute');
|
||||
expect(response).toEqual('in 95 minutes');
|
||||
});
|
||||
|
||||
test('test timestamp that is 119 minutes in the future', () => {
|
||||
const ninetyFiveMin = 119 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 199 minutes');
|
||||
format.formatRelativeTime(ninetyFiveMin, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(119, 'minute');
|
||||
});
|
||||
|
||||
test('test timestamp that is 48 hours in the future', () => {
|
||||
let response;
|
||||
const fortyEightHrs = 48 * 60 * 60 * 1000;
|
||||
|
||||
mockFormatExpression.format.mockReturnValue('in 48 hours');
|
||||
response = format.formatRelativeTime(fortyEightHrs, 'en');
|
||||
format.formatRelativeTime(fortyEightHrs, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(48, 'hour');
|
||||
expect(response).toEqual('in 48 hours');
|
||||
});
|
||||
|
||||
test('test timestamp that is 2.6 hours rounds to 3', () => {
|
||||
let response;
|
||||
const twoPlusHours = 2.6 * 60 * 60 * 1000;
|
||||
|
||||
mockFormatExpression.format.mockReturnValue('in 3 hours');
|
||||
response = format.formatRelativeTime(twoPlusHours, 'en');
|
||||
format.formatRelativeTime(twoPlusHours, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(3, 'hour');
|
||||
expect(response).toEqual('in 3 hours');
|
||||
});
|
||||
|
||||
test('test timestamp that is 4.2 hours in the future rounds to 4', () => {
|
||||
let response;
|
||||
const fourPlusHours = 4.2 * 60 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 4 hours');
|
||||
response = format.formatRelativeTime(fourPlusHours, 'en');
|
||||
format.formatRelativeTime(fourPlusHours, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(4, 'hour');
|
||||
expect(response).toEqual('in 4 hours');
|
||||
});
|
||||
|
||||
test('test timestamp that is 2 hours in the future is in hours', () => {
|
||||
let response;
|
||||
const threeHours = 2 * 60 * 60 * 1000;
|
||||
|
||||
const twoHours = 2 * 60 * 60 * 1000;
|
||||
mockFormatExpression.format.mockReturnValue('in 2 hours');
|
||||
response = format.formatRelativeTime(threeHours, 'en');
|
||||
format.formatRelativeTime(twoHours, 'en');
|
||||
expect(mockFormatExpression.format).toHaveBeenCalledWith(2, 'hour');
|
||||
expect(response).toEqual('in 2 hours');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue