React-admin: Tests not passing

Created on 28 Apr 2017  路  7Comments  路  Source: marmelab/react-admin

/src/mui/field/DateField.spec.js#18, /src/mui/field/DateField.spec.js#28 and /src/mui/field/DateField.spec.js#38 the test may fail because of the timezone. By default a date is set on 00:00:00. My timezone is UTC-3 so on the DateField tests the time shows the wrong date (previous day at 21:00:00).

Also it asked for aor-json-rest-client, aor-language-french and aor-rich-text-input when running the tests. Is something missing on package.json?

bug

All 7 comments

cd example/
npm i

I think the test uses example app so the above commands fix the lib errors

@valueshimoda indeed the dependencies were fixed when running the command above. But the date field issue still happens.

Strange, these tests manipulate dates, not datetimes. Can you paste the results of these tests on your computer?

@fzaninotto Will do it today. The problem is that it sets the Locale. When setting the locale it applies the timezone too. As I'm UTC-3 and it uses US timezone (UTC-6 I believe) setting the locale makes it shift back 3 hours.

  1) <DateField /> should render a date:

      AssertionError: '<span>4/22/2017</span>' == '<span>4/23/2017</span>'
      + expected - actual

      -<span>4/22/2017</span>
      +<span>4/23/2017</span>

      at Context.<anonymous> (src/mui/field/DateField.spec.js:17:45)

  2) <DateField /> should pass the options prop to Intl.DateTimeFormat:

      AssertionError: '<span>Saturday, April 22, 2017</span>' == '<span>Sunday, April 23, 2017</span>'
      + expected - actual

      -<span>Saturday, April 22, 2017</span>
      +<span>Sunday, April 23, 2017</span>

      at Context.<anonymous> (src/mui/field/DateField.spec.js:27:76)

  3) <DateField /> should use the locales props as an argument to Intl.DateTimeFormat:

      AssertionError: '<span>22/04/2017</span>' == '<span>23/04/2017</span>'
      + expected - actual

      -<span>22/04/2017</span>
      +<span>23/04/2017</span>

      at Context.<anonymous> (src/mui/field/DateField.spec.js:37:91)

and then I added on line 18 the following:

      const date = new Date('2017-04-23');
      console.log(date);
      console.log(date.toLocaleString('en-US', {}));
      console.log(date.toLocaleString());
      console.log(date.toLocaleDateString('en-US', {}));
      console.log(date.toLocaleDateString());

and got this output:

2017-04-23T00:00:00.000Z
4/22/2017, 9:00:00 PM
4/22/2017, 9:00:00 PM
4/22/2017
4/22/2017

Now. if I set the hours:


      const date = new Date('2017-04-23 13:00:00');
      console.log(date);
      console.log(date.toLocaleString('en-US', {}));
      console.log(date.toLocaleString());
      console.log(date.toLocaleDateString('en-US', {}));
      console.log(date.toLocaleDateString());
````
then

2017-04-23T16:00:00.000Z
4/23/2017, 1:00:00 PM
4/23/2017, 1:00:00 PM
4/23/2017
4/23/2017
```

and the test passes.

Screen Shot 2019-05-15 at 02 20 03
Screen Shot 2019-05-15 at 01 58 37
Hi, using either timestamp with time zone or date I get the wrong day with DateField. You can see the string I get from my data provider on the TextField column and how the filter does work.

I am still facing the same issue. Date displays a day back.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ric-kin picture ric-kin  路  24Comments

saf-1 picture saf-1  路  20Comments

xiaomingplus picture xiaomingplus  路  22Comments

MhdSyrwan picture MhdSyrwan  路  24Comments

keulu-ing picture keulu-ing  路  22Comments