Skip to content

Commit

Permalink
DEV review updates, UTC correction
Browse files Browse the repository at this point in the history
* graphHelpers, minor UTC correction, snapshot corrections
* dateHelpers, initial date defaults, prep for additional date functions
* helpers, index layout
* rhelGraphCard, replace default startDate, endDate props with helper
  • Loading branch information
cdcabrera committed Jul 19, 2019
1 parent bfb0b55 commit ba10156
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 30 deletions.
10 changes: 10 additions & 0 deletions src/common/__tests__/__snapshots__/dateHelpers.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DateHelpers should have specific functions: dateHelpers 1`] = `
Object {
"defaultDateTime": Object {
"end": null,
"start": null,
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Array [
]
`;

exports[`GraphHelpers should have specific functions: helpers 1`] = `
exports[`GraphHelpers should have specific functions: graphHelpers 1`] = `
Object {
"chartDateFormat": "MMM D",
"convertGraphData": [Function],
Expand Down
7 changes: 7 additions & 0 deletions src/common/__tests__/dateHelpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { dateHelpers } from '../dateHelpers';

describe('DateHelpers', () => {
it('should have specific functions', () => {
expect(dateHelpers).toMatchSnapshot('dateHelpers');
});
});
25 changes: 15 additions & 10 deletions src/common/__tests__/graphHelpers.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import moment from 'moment';
import { graphHelpers, getGraphHeight, getTooltipDimensions, getTooltipFontSize } from '../graphHelpers';
import {
graphHelpers,
convertGraphData,
getGraphHeight,
getTooltipDimensions,
getTooltipFontSize
} from '../graphHelpers';
import { helpers } from '../helpers';

describe('GraphHelpers', () => {
const { breakpoints } = helpers;
const startDate = moment.utc(new Date('2019-06-01T00:00:00Z'));
const endDate = moment.utc(new Date('2019-06-05T00:00:00Z'));
const startDate = new Date('2019-06-01T00:00:00Z');
const endDate = new Date('2019-06-05T00:00:00Z');
const socketLabel = 'sockets on';
const previousLabel = 'from previous day';

it('should have specific functions', () => {
expect(graphHelpers).toMatchSnapshot('helpers');
expect(graphHelpers).toMatchSnapshot('graphHelpers');
});

it('should convert graph data and return zeroed usage array if usage is empty', () => {
expect(
graphHelpers.convertGraphData({ usage: [], startDate, endDate, socketLabel, previousLabel })
).toMatchSnapshot('zeroed array');
expect(convertGraphData({ usage: [], startDate, endDate, socketLabel, previousLabel })).toMatchSnapshot(
'zeroed array'
);
});

it('should convert graph data and generate tooltips when usage is populated', () => {
expect(
graphHelpers.convertGraphData({
convertGraphData({
usage: [
{ cores: 56, date: '2019-06-01T00:00:00Z', instance_count: 28 },
{ cores: 30, date: '2019-06-02T00:00:00Z', instance_count: 28 },
Expand All @@ -37,7 +42,7 @@ describe('GraphHelpers', () => {

it('should convert graph data and returned zeroed array when usage throws error', () => {
expect(
graphHelpers.convertGraphData({
convertGraphData({
usage: [null], // unexpected usage, will throw exception
startDate,
endDate,
Expand Down
21 changes: 21 additions & 0 deletions src/common/dateHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import moment from 'moment/moment';
import { helpers } from './helpers';

const defaultDateTime = (helpers.TEST_MODE && {
start: null,
end: null
}) || {
start: moment()
.utc()
.startOf('day')
.subtract(30, 'days'),
end: moment()
.utc()
.endOf('day')
};

const dateHelpers = {
defaultDateTime
};

export { dateHelpers as default, dateHelpers, defaultDateTime };
2 changes: 1 addition & 1 deletion src/common/graphHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const zeroedUsageData = (startDate, endDate) => {

// todo: convert "y" back towards a number if/when we handle "chartDomain.y = [0, 100]" within helpers
for (let i = 0; i <= endDateStartDateDiff; i++) {
const clonedStartDate = moment(startDate);
const clonedStartDate = moment.utc(startDate);
zeroedArray.push({
x: clonedStartDate.add(i, 'days').format(chartDateFormat),
y: '0'
Expand Down
5 changes: 5 additions & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { helpers } from './helpers';
import { dateHelpers } from './dateHelpers';
import { graphHelpers } from './graphHelpers';

export { helpers as default, helpers, dateHelpers, graphHelpers };
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ exports[`RhelGraphCard Component should render a non-connected component: non-co
exports[`RhelGraphCard Component should render multiple states: error shows zeroed bar values 1`] = `
Object {
"chartBarData": Array [
Object {
"x": "May 31",
"y": "0",
},
Object {
"x": "Jun 1",
"y": "0",
Expand Down Expand Up @@ -366,6 +362,10 @@ Object {
"x": "Jun 29",
"y": "0",
},
Object {
"x": "Jun 30",
"y": "0",
},
],
}
`;
Expand Down Expand Up @@ -440,10 +440,6 @@ exports[`RhelGraphCard Component should render multiple states: fulfilled 1`] =
<ChartBar
data={
Array [
Object {
"x": "May 31",
"y": "0",
},
Object {
"x": "Jun 1",
"y": "0",
Expand Down Expand Up @@ -560,6 +556,10 @@ exports[`RhelGraphCard Component should render multiple states: fulfilled 1`] =
"x": "Jun 29",
"y": "0",
},
Object {
"x": "Jun 30",
"y": "0",
},
]
}
labelComponent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { mount, shallow } from 'enzyme';
import { Chart, ChartBar } from '@patternfly/react-charts';
import { RhelGraphCard } from '../rhelGraphCard';
import { helpers } from '../../../common/helpers';
import { helpers } from '../../../common';

describe('RhelGraphCard Component', () => {
const { breakpoints } = helpers;
Expand Down
8 changes: 3 additions & 5 deletions src/components/rhelGraphCard/rhelGraphCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withBreakpoints } from 'react-breakpoints';
import moment from 'moment';
import {
Card,
CardHead,
Expand All @@ -14,8 +13,7 @@ import {
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components';
import { Chart, ChartBar, ChartBaseTheme, ChartLabel, ChartStack, ChartTooltip } from '@patternfly/react-charts';
import { connectTranslate, reduxActions } from '../../redux';
import { helpers } from '../../common/helpers';
import { graphHelpers } from '../../common/graphHelpers';
import { helpers, dateHelpers, graphHelpers } from '../../common';
import { rhelApiTypes } from '../../types/rhelApiTypes';

class RhelGraphCard extends React.Component {
Expand Down Expand Up @@ -176,8 +174,8 @@ RhelGraphCard.defaultProps = {
t: helpers.noopTranslate,
breakpoints: {},
currentBreakpoint: '',
startDate: moment.utc().subtract(1, 'months'),
endDate: moment()
startDate: dateHelpers.defaultDateTime.start,
endDate: dateHelpers.defaultDateTime.end
};

const mapStateToProps = state => ({
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ exports[`i18n locale should generate a predictable pot output snapshot: pot outp
msgstr \\"\\"
\\"Content-Type: text/plain; charset=UTF-8\\\\n\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:109
#: src/components/rhelGraphCard/rhelGraphCard.js:107
msgctxt \\"Daily CPU socket usage\\"
msgid \\"curiosity-graph.heading\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:73
#: src/components/rhelGraphCard/rhelGraphCard.js:71
msgctxt \\"from previous day\\"
msgid \\"curiosity-graph.fromPrevious\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:79
#: src/components/rhelGraphCard/rhelGraphCard.js:77
msgctxt \\"Last 30 Days\\"
msgid \\"curiosity-graph.dropdownDefault\\"
msgstr \\"\\"
#: src/components/rhelGraphCard/rhelGraphCard.js:72
#: src/components/rhelGraphCard/rhelGraphCard.js:70
msgctxt \\"sockets on\\"
msgid \\"curiosity-graph.socketsOn\\"
msgstr \\"\\"
Expand Down

0 comments on commit ba10156

Please sign in to comment.