Skip to content

Commit

Permalink
chore: continue migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfrancois authored and Alexandre Amalric committed Nov 28, 2023
1 parent d167e89 commit c21ed83
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isAfter from 'date-fns/is_after';
import subHours from 'date-fns/sub_hours';
import isAfter from 'date-fns/isAfter';
import subHours from 'date-fns/subHours';
import {
checkSupportedDateFormat,
checkSupportedTimezone,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import isBefore from 'date-fns/is_before';
import isBefore from 'date-fns/isBefore';

import { DateRangeContext } from '../Context';
import getErrorMessage from '../../shared/error-messages';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import isBefore from 'date-fns/is_before';
import isEqual from 'date-fns/is_equal';
import isBefore from 'date-fns/isBefore';
import isEqual from 'date-fns/isEqual';

import { DateTimeRangeContext } from '../Context';
import getErrorMessage from '../../shared/error-messages';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from '@storybook/addon-actions';
import isBefore from 'date-fns/is_before';
import startOfDay from 'date-fns/start_of_day';
import isBefore from 'date-fns/isBefore';
import startOfDay from 'date-fns/startOfDay';

import InputDatePicker from './InputDatePicker.component';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import isSameSecond from 'date-fns/is_same_second';
import isSameSecond from 'date-fns/isSameSecond';

import { DateTimeContext } from '../Context';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { screen, render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import isSameDay from 'date-fns/is_same_day';
import isToday from 'date-fns/is_today';
import isSameDay from 'date-fns/isSameDay';
import isToday from 'date-fns/isToday';

import DatePicker from './DatePicker.component';

jest.mock('date-fns/is_today');
jest.mock('date-fns/isToday');

function mockIsTodayWith(newToday) {
isToday.mockImplementation(date => isSameDay(date, newToday));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { screen, render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import isSameDay from 'date-fns/is_same_day';
import isToday from 'date-fns/is_today';
import isSameDay from 'date-fns/isSameDay';
import isToday from 'date-fns/isToday';

import DatePicker from './DatePicker.component';

jest.mock('date-fns/is_today');
jest.mock('date-fns/isToday');

function mockIsTodayWith(newToday) {
isToday.mockImplementation(date => isSameDay(date, newToday));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import { withTranslation } from 'react-i18next';
import { getRowData } from '../../VirtualizedList/utils/gridrow';
import I18N_DOMAIN_COMPONENTS from '../../constants';
Expand All @@ -17,7 +17,7 @@ const FLAGS = {
};

function getDateLabel(t, date) {
return distanceInWordsToNow(date, {
return formatDistanceToNow(date, {
addSuffix: true,
locale: getLocale(t),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { render } from '@testing-library/react';
import Resource from './Resource.component';

jest.mock('date-fns/distance_in_words_to_now', () => () => 'over 2 years ago');
jest.mock('date-fns/formatDistanceToNow', () => () => 'over 2 years ago');

describe('Resource component snaps', () => {
afterAll(() => {
jest.unmock('date-fns/distance_in_words_to_now');
jest.unmock('date-fns/formatDistanceToNow');
});

describe('renderers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Component } from 'react';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import pick from 'lodash/pick';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import format from 'date-fns/format';
import isValid from 'date-fns/is_valid';
import isValid from 'date-fns/isValid';
import parse from 'date-fns/parse';
import { withTranslation } from 'react-i18next';
import { date as dateUtils } from '@talend/utils';
Expand All @@ -23,7 +23,7 @@ export function computeValue(cellData, columnData, t) {

if (isDateValid) {
if (cellData && columnData.mode === 'ago') {
return distanceInWordsToNow(cellData, {
return formatDistanceToNow(cellData, {
addSuffix: true,
locale: getLocale(t),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* eslint-disable react/prop-types */

/* eslint-disable react/display-name */
import { render, screen } from '@testing-library/react';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import format from 'date-fns/format';
import distanceInWordsToNow from 'date-fns/formatDistanceToNow';

import { date as dateUtils } from '@talend/utils';

import { computeValue, CellDatetimeComponent } from './CellDatetime.component';
import getDefaultT from '../../translate';
import getLocale from '../../i18n/DateFnsLocale/locale';
import getDefaultT from '../../translate';
import { CellDatetimeComponent, computeValue } from './CellDatetime.component';

jest.mock('../../i18n/DateFnsLocale/locale');

jest.mock('date-fns/distance_in_words_to_now', () => ({
jest.mock('date-fns/formatDistanceToNow', () => ({
__esModule: true,
default: jest.fn(() => 'about 1 month ago'),
}));
Expand Down Expand Up @@ -49,7 +51,7 @@ describe('CellDatetime', () => {

afterAll(() => {
jest.unmock('../../i18n/DateFnsLocale/locale');
jest.unmock('date-fns/distance_in_words_to_now');
jest.unmock('date-fns/formatDistanceToNow');
jest.unmock('date-fns/format');
});

Expand Down Expand Up @@ -125,7 +127,7 @@ describe('CellDatetime', () => {
const cellData = 1474495200000 + 3600 * 11 * 1000;
const timezoneOffset = new Date(cellData).getTimezoneOffset();
const cellDataWithOffset = cellData + timezoneOffset * 60 * 1000;
const hours = 11 + timezoneOffset / 60;

const expectedStrDate = '2016-09-22 09:00:00';
const computedStrOffset = computeValue(cellDataWithOffset, columnData, t);
// then
Expand Down

0 comments on commit c21ed83

Please sign in to comment.