forked from Ivasoft/mattermost-mobile
* Global threads * Added translations * User avatar stack * In-Channel experience * Misc Fixes * Fixed fetchPostThread & added observer * using the observable for participants & check fix * Test case fix * Fix tablet view thread screen switching * No back button for tablets * folders for thread options only if needed * Using the existing observable * Users stack refactor fix * Reusing the user component * Refactor fix * Fixes double loaders when empty threads * Feedback * Moved some post options to common post options * Combined follow/unfollow functions * Feedback fixes * Addressing Feedback * Merge fix * Threads button component moved * Addressing feedbackk * Not rendering message when it's empty, removed unwanted Props exports * Addressing feedbac * Updated snapshot * Added emoji to removemarkdown component * Moved MD rendering into the component Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: koox00 <3829551+koox00@users.noreply.github.com>
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
|
|
import {renderWithIntl} from '@test/intl-test-helper';
|
|
|
|
import FriendlyDate from './index';
|
|
|
|
describe('Friendly Date', () => {
|
|
it('should render correctly', () => {
|
|
const justNow = new Date();
|
|
justNow.setSeconds(justNow.getSeconds() - 10);
|
|
const justNowText = renderWithIntl(
|
|
<FriendlyDate value={justNow}/>,
|
|
);
|
|
expect(justNowText.getByText('Now')).toBeTruthy();
|
|
|
|
const minutesAgo = new Date();
|
|
minutesAgo.setMinutes(minutesAgo.getMinutes() - 1);
|
|
const minutesAgoText = renderWithIntl(
|
|
<FriendlyDate value={minutesAgo}/>,
|
|
);
|
|
expect(minutesAgoText.getByText('1 min ago')).toBeTruthy();
|
|
|
|
const hoursAgo = new Date();
|
|
hoursAgo.setHours(hoursAgo.getHours() - 4);
|
|
const hoursAgoText = renderWithIntl(
|
|
<FriendlyDate value={hoursAgo}/>,
|
|
);
|
|
expect(hoursAgoText.getByText('4 hours ago')).toBeTruthy();
|
|
|
|
const yesterday = new Date();
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
const yesterdayText = renderWithIntl(
|
|
<FriendlyDate value={yesterday}/>,
|
|
);
|
|
expect(yesterdayText.getByText('Yesterday')).toBeTruthy();
|
|
|
|
const daysAgo = new Date();
|
|
daysAgo.setDate(daysAgo.getDate() - 10);
|
|
const daysAgoText = renderWithIntl(
|
|
<FriendlyDate value={daysAgo}/>,
|
|
);
|
|
expect(daysAgoText.getByText('10 days ago')).toBeTruthy();
|
|
|
|
// Difference is less than 30 days
|
|
const daysEdgeCase = new Date(2020, 3, 28);
|
|
const daysEdgeCaseTodayDate = new Date(2020, 4, 28);
|
|
const daysEdgeCaseText = renderWithIntl(
|
|
<FriendlyDate
|
|
sourceDate={daysEdgeCaseTodayDate}
|
|
value={daysEdgeCase}
|
|
/>,
|
|
);
|
|
expect(daysEdgeCaseText.getByText('1 month ago')).toBeTruthy();
|
|
|
|
const daysAgoMax = new Date(2020, 4, 6);
|
|
const daysAgoMaxTodayDate = new Date(2020, 5, 5);
|
|
const daysAgoMaxText = renderWithIntl(
|
|
<FriendlyDate
|
|
sourceDate={daysAgoMaxTodayDate}
|
|
value={daysAgoMax}
|
|
/>,
|
|
);
|
|
expect(daysAgoMaxText.getByText('30 days ago')).toBeTruthy();
|
|
|
|
const monthsAgo = new Date();
|
|
monthsAgo.setMonth(monthsAgo.getMonth() - 2);
|
|
const monthsAgoText = renderWithIntl(
|
|
<FriendlyDate value={monthsAgo}/>,
|
|
);
|
|
expect(monthsAgoText.getByText('2 months ago')).toBeTruthy();
|
|
|
|
const yearsAgo = new Date();
|
|
yearsAgo.setFullYear(yearsAgo.getFullYear() - 2);
|
|
const yearsAgoText = renderWithIntl(
|
|
<FriendlyDate value={yearsAgo}/>,
|
|
);
|
|
expect(yearsAgoText.getByText('2 years ago')).toBeTruthy();
|
|
});
|
|
});
|