Skip to content

Commit

Permalink
Fix nondeterministic timezone for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wdoug committed Nov 18, 2017
1 parent 45b4418 commit 6af7916
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
9 changes: 5 additions & 4 deletions client/src/utils/dateFormatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import moment from 'moment-timezone';
export function getFormattedDayAndTime(date, endDate) {
const localTimezone = moment.tz.guess();

const startDateMoment = moment(date);
const startDateMoment = moment(date).tz(localTimezone);
const endDateMoment = moment(endDate).tz(localTimezone);
const day = startDateMoment.format('dddd, MMMM D, YYYY');
const start = moment(date).tz(localTimezone).format('h:mm');
const end = moment(endDate).tz(localTimezone).format('h:mm a z');
const startTime = startDateMoment.format('h:mm');
const endTime = endDateMoment.format('h:mm a z');
return {
day,
time: `${start}-${end}`
time: `${startTime}-${endTime}`
};
}

Expand Down
5 changes: 5 additions & 0 deletions client/stories/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"globals": {
"jest": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`Storyshots Event Event with customizable props 1`] = `
<h4>
Tuesday, January 1, 1901
|
4:00-7:30 pm UTC
11:00-2:30 am GMT
</h4>
<p>
Galvanize, Golden Triangle, Denver
Expand Down Expand Up @@ -87,7 +87,7 @@ exports[`Storyshots EventRow Event row with customizable props 1`] = `
<div
className="small-12 medium-2 columns"
>
12:00-12:00 am MST
12:00-12:00 am GMT
</div>
<div
className="small-12 medium-5 columns"
Expand Down
4 changes: 4 additions & 0 deletions client/stories/__tests__/storyshots.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import initStoryshots from 'storyshots';
import moment from 'moment-timezone';

moment.tz.setDefault('Europe/London');
moment.tz.guess = jest.fn(() => 'Europe/London');

initStoryshots({
configPath: 'client/stories/snapshotConfig'
Expand Down
5 changes: 3 additions & 2 deletions client/stories/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ storiesOf('Event', module)
'Check the knobs tab in the panel below to customize the props for this component',
() => {
const eventData = {
date: date('data.date', new Date('Jan 1, 1901 4:00 pm')),
endDate: date('data.endDate', new Date('Jan 1, 1901 7:30 pm')),
date: date('data.date', new Date('Jan 1, 1901 4:00 pm MST')),
endDate: date('data.endDate', new Date('Jan 1, 1901 7:30 pm MST')),
id: 2,
location: text('data.location', 'Galvanize, Golden Triangle, Denver'),
name: text('data.name', 'The best event'),
Expand All @@ -38,6 +38,7 @@ storiesOf('Event', module)
isRegistered={boolean('is Registered', false)}
signUpForEvent={action('sign up for event')}
cancelSignUpForEvent={action('cancel sign up for event')}
deleteEvent={action('delete event')}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"loopback-component-explorer": "^2.4.0",
"loopback-connector-postgresql": "^2.4.1",
"loopback-datasource-juggler": "^2.39.0",
"moment": "^2.17.1",
"moment-timezone": "^0.5.13",
"moment": "^2.19.2",
"moment-timezone": "^0.5.14",
"node-sass": "^4.5.0",
"nodemailer": "^3.1.8",
"numeral": "^1.5.3",
Expand Down

0 comments on commit 6af7916

Please sign in to comment.