fix(test): replaces LocaleString with date-nfs/format

fix(test): replaces timezone to UTC

fix(test): updates variable definitions

fix(test): updates time format
This commit is contained in:
Ayush Sharma 2018-03-21 16:56:27 +05:30
parent be293a7641
commit 0d3cf84c01
7 changed files with 22 additions and 52 deletions

View File

@ -27,6 +27,7 @@
"compression": "1.7.2",
"cookies": "0.7.1",
"cors": "2.8.4",
"date-fns": "1.29.0",
"express": "4.16.2",
"global": "4.3.2",
"handlebars": "4.0.11",
@ -147,10 +148,10 @@
"prepublish": "in-publish && npm run build:webui && npm run code:build || not-in-publish",
"flow": "flow",
"pretest": "npm run code:build",
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest --maxWorkers 2",
"test": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest --maxWorkers 2",
"test:e2e": "cross-env BABEL_ENV=registry jest --config ./jest.e2e.config.js --maxWorkers 2",
"test:all": "npm run test && npm run test:e2e",
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2",
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2",
"test:func": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/functional.*\\.func)\\.js' --maxWorkers 2",
"pre:ci": "npm run lint && npm run build:webui",
"commitmsg": "commitlint -e $GIT_PARAMS",

View File

@ -1,9 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import format from 'date-fns/format';
import Module from '../../Module';
import datetime from '../../../../../utils/datetime';
import classes from './style.scss';
const TIMEFORMAT = 'YYYY/MM/DD, HH:mm:ss';
export default class LastSync extends React.Component {
static propTypes = {
packageMeta: PropTypes.object.isRequired
@ -19,15 +21,15 @@ export default class LastSync extends React.Component {
}
});
return lastUpdate ? datetime(lastUpdate) : '';
const time = format(new Date(lastUpdate), TIMEFORMAT);
return lastUpdate ? time : '';
}
get recentReleases() {
let recentReleases = Object.keys(this.props.packageMeta.time).map((version) => {
return {
version,
time: datetime(this.props.packageMeta.time[version])
};
const time = format(new Date(this.props.packageMeta.time[version]), TIMEFORMAT);
return {version, time};
});
return recentReleases.slice(recentReleases.length - 3, recentReleases.length).reverse();

View File

@ -1,16 +0,0 @@
/**
* Date time in LocaleString
* @param {string} input
* @returns {string}
*/
export default function datetime(input) {
const date = new Date(input);
return date.toLocaleString('en-GB', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: true
});
}

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<PackageSidebar /> : <LastSync /> should load the LastSync component and match snapshot 1`] = `"<div class=\\"module releasesModule\\"><h2 class=\\"moduleTitle\\">Last Sync<span>Dec 14, 2017, 3:43 PM</span></h2><div><ul><li class=\\"last-sync-item\\"><span>2.7.1</span><span>Dec 14, 2017, 3:43 PM</span></li><li class=\\"last-sync-item\\"><span>2.7.0</span><span>Dec 5, 2017, 11:25 PM</span></li><li class=\\"last-sync-item\\"><span>2.6.6</span><span>Nov 8, 2017, 10:47 PM</span></li></ul></div></div>"`;
exports[`<PackageSidebar /> : <LastSync /> should load the LastSync component and match snapshot 1`] = `"<div class=\\"module releasesModule\\"><h2 class=\\"moduleTitle\\">Last Sync<span>2017/12/14, 15:43:52</span></h2><div><ul><li class=\\"last-sync-item\\"><span>2.7.1</span><span>2017/12/14, 15:43:27</span></li><li class=\\"last-sync-item\\"><span>2.7.0</span><span>2017/12/05, 23:25:06</span></li><li class=\\"last-sync-item\\"><span>2.6.6</span><span>2017/11/08, 22:47:16</span></li></ul></div></div>"`;

View File

@ -6,24 +6,20 @@ import React from 'react';
import { mount, shallow } from 'enzyme';
import LastSync from '../../../../src/webui/src/components/PackageSidebar/modules/LastSync';
import { packageMeta } from '../store/packageMeta';
jest.mock(
'../../../../src/webui/utils/datetime',
() => require('../__mocks__/datetime').default
);
console.error = jest.fn();
describe.skip('<PackageSidebar /> : <LastSync />', () => {
describe('<PackageSidebar /> : <LastSync />', () => {
it('should load the component and check getters: lastUpdate, recentReleases with package data', () => {
const wrapper = mount(<LastSync packageMeta={packageMeta} />);
const instance = wrapper.instance();
const result = [
{ time: 'Dec 14, 2017, 3:43 PM', version: '2.7.1' },
{ time: 'Dec 5, 2017, 11:25 PM', version: '2.7.0' },
{ time: 'Nov 8, 2017, 10:47 PM', version: '2.6.6' }
{ time: '2017/12/14, 15:43:27', version: '2.7.1' },
{ time: '2017/12/05, 23:25:06', version: '2.7.0' },
{ time: '2017/11/08, 22:47:16', version: '2.6.6' }
];
expect(instance.lastUpdate).toEqual('Dec 14, 2017, 3:43 PM');
const lastUpdated = '2017/12/14, 15:43:52';
expect(instance.lastUpdate).toEqual(lastUpdated);
expect(instance.recentReleases).toEqual(result);
});

View File

@ -1,17 +0,0 @@
/**
* Date time in LocaleString
* @param {string} input
* @returns {string}
*/
export default function datetime(input) {
const date = new Date(input);
return date.toLocaleString('en-GB', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: true,
timeZone: 'Europe/London'
});
}

View File

@ -2513,6 +2513,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"
date-fns@1.29.0:
version "1.29.0"
resolved "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz#12e609cdcb935127311d04d33334e2960a2a54e6"
date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"