Skip to content

Commit a2cda59

Browse files
* Create helper to format Date
1 parent 5e57435 commit a2cda59

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

app/components/Visit/Show/Visit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Link } from 'react-router'
44
import VisitService from 'services/Visit'
55
import Error from 'components/Error/Error'
66
import styles from 'components/Visit/Show/styles.css'
7-
import DateHelper from 'helpers/DateHelper'
7+
import DateHelper from 'helpers/Date'
88

99
class Visit extends React.Component
1010
{
@@ -51,7 +51,7 @@ class Visit extends React.Component
5151
<strong>{this.state.visit.client.name}</strong>
5252
</h3>
5353
<p className="tagline">
54-
<strong>Visit Date: </strong>{DateHelper.formateDate(this.state.visit.visit_date)}
54+
<strong>Visit Date: </strong>{DateHelper.format(this.state.visit.visit_date)}
5555
</p>
5656
<p className="tagline">
5757
<strong>Address: </strong>{this.state.visit.client.address}

app/components/Visit/Visit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { Link } from 'react-router'
3+
import DateHelper from 'helpers/Date'
34

45
class Visit extends React.Component
56
{
@@ -15,7 +16,7 @@ class Visit extends React.Component
1516
return this.state.visits.map((areaVisit, key) => (
1617
<tr key={ key } >
1718
<td>{ areaVisit.visit.client.name }</td>
18-
<td>{ areaVisit.visit.visit_date }</td>
19+
<td>{ DateHelper.format(areaVisit.visit.visit_date) }</td>
1920
<td className="is-icon">
2021
<Link to={ `/visit/${areaVisit.visit._id}` } >
2122
<i className="fa fa-info-circle" />

app/helpers/Date.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const Date = {
2+
format(date) {
3+
let dateObj = new window.Date(date);
4+
let options = {
5+
day: '2-digit',
6+
month: '2-digit',
7+
year: 'numeric'
8+
}
9+
return dateObj.toGMTString();
10+
}
11+
}
12+
13+
export default Date;

app/helpers/DateHelper.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/DateHelper.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
describe('Test DateHelper', () => {
3+
4+
const DateHelper = require('helpers/Date').default;
5+
6+
it ('should return date on format GMT', (done) => {
7+
let date = DateHelper.format('2016-10-19T13:30:13.329Z');
8+
expect(date).toEqual("Wed, 19 Oct 2016 13:30:13 GMT");
9+
done();
10+
});
11+
});

tests/Show.Visit.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.dontMock('axios');
77
jest.dontMock('axios-mock-adapter');
88
jest.dontMock('enzyme');
99
jest.dontMock('services/Visit');
10-
jest.dontMock('helpers/DateHelper');
10+
jest.dontMock('helpers/Date');
1111

1212
describe('Test Visit', () => {
1313
require('../tests/__mocks__/LocalStorageMock');
@@ -57,7 +57,7 @@ describe('Test Visit', () => {
5757
setTimeout(() => {
5858

5959
try {
60-
expect(component.find('.name p').at(0).text()).toEqual('Visit Date: 10/01/2017');
60+
expect(component.find('.name p').at(0).text()).toEqual('Visit Date: Sun, 01 Oct 2017 00:00:00 GMT');
6161
expect(component.find('.name p').at(1).text()).toEqual('Address: 7 Street');
6262
expect(component.find('.name p').at(2).text()).toEqual('Area: Center');
6363
expect(component.find('.followers p').at(0).text()).toEqual('R$ 300');

tests/Visit.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ describe('Test Visit', () => {
5353

5454
expect(component.find('td').length).toEqual(6);
5555
expect(component.find('td').at(0).text()).toEqual('Jon Snow');
56-
expect(component.find('td').at(1).text()).toEqual('2016-10-19T13:30:13.329Z');
56+
expect(component.find('td').at(1).text()).toEqual('Wed, 19 Oct 2016 13:30:13 GMT');
5757
expect(component.find('td').at(2).text()).toEqual('<Link />');
5858

5959
expect(component.find('td').at(3).text()).toEqual('Cotter Pyke');
60-
expect(component.find('td').at(4).text()).toEqual('2016-10-18T13:31:14.430Z');
60+
expect(component.find('td').at(4).text()).toEqual('Tue, 18 Oct 2016 13:31:14 GMT');
6161
expect(component.find('td').at(5).text()).toEqual('<Link />');
6262
done();
6363
});

0 commit comments

Comments
 (0)