Skip to content

Commit bd6a14f

Browse files
authored
Unit test updates 2 (#34)
* fill out manifestUtil tests * DownloadStepForm snapshot tests * context Provider basic render test pattern * NeonAuth / UserCard snapshot tests * expand testing for DataProductAvailability; add snapshots * more DataProductAvailability snapshot coverage * test coverage for final remaining worker * DownloadDataContext tests first pass * first pass parellelizing series building in TimeSeriesViewer * first pass unit testing generateTimeSeriesGraphData worker * complete unit testing of generateTimeSeriesGraphData worker * more TimeSeriesViewerContext unit tests (reducer) * more TimeSeriesViewerContext reducer tests * complete TimeSeriesViewerContext reducer tests * v1.6.3 tag; clean lint; lib export
1 parent d25f60f commit bd6a14f

File tree

62 files changed

+15235
-1506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+15235
-1506
lines changed

lib/components/DataProductAvailability/AvailabilityContext.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ var reducer = function reducer(state, action) {
223223
return calculateRows(hydrateNeonContextData(newState, action.neonContextData));
224224

225225
case 'setBreakouts':
226+
if (!action.breakouts) {
227+
return state;
228+
}
229+
226230
if (!action.breakouts.every(function (b) {
227231
return state.validBreakouts.includes(b);
228232
})) {

lib/components/DataProductAvailability/BasicAvailabilityInterface.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,6 @@ var BasicAvailabilityInterface = function BasicAvailabilityInterface(props) {
706706

707707

708708
var renderSelection = function renderSelection() {
709-
if (!selectionEnabled) {
710-
return null;
711-
}
712-
713709
var sitesPlural = sites.value.length > 1 ? 's' : '';
714710
var siteChipLabel = "".concat(sites.value.length, " site").concat(sitesPlural);
715711
var siteChipProps = {

lib/components/DataProductAvailability/BasicAvailabilityKey.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ function BasicAvailabilityKey(props) {
158158

159159

160160
var renderSelectionLegend = function renderSelectionLegend() {
161-
if (!selectionEnabled) {
162-
return null;
163-
}
164-
165161
var totalRows = 2;
166162
var rowHeight = _AvailabilityUtils.SVG.CELL_HEIGHT + 2 * _AvailabilityUtils.SVG.CELL_PADDING;
167163
var totalHeight = rowHeight * totalRows - _AvailabilityUtils.SVG.CELL_PADDING;

lib/components/DownloadDataContext/DownloadDataContext.d.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,108 @@
11
export default DownloadDataContext;
2+
export function getTestableItems(): {
3+
productDataIsValid?: undefined;
4+
yearMonthIsValid?: undefined;
5+
newStateIsAllowable?: undefined;
6+
newStateIsValid?: undefined;
7+
mutateNewStateIntoRange?: undefined;
8+
estimatePostSize?: undefined;
9+
getValidValuesFromProductData?: undefined;
10+
getInitialStateFromProps?: undefined;
11+
getS3FilesFilteredFileCount?: undefined;
12+
getAndValidateNewS3FilesState?: undefined;
13+
regenerateS3FilesFiltersAndValidValues?: undefined;
14+
getAndValidateNewState?: undefined;
15+
ALL_POSSIBLE_VALID_DATE_RANGE?: undefined;
16+
} | {
17+
productDataIsValid: (productData: any) => boolean;
18+
yearMonthIsValid: (yearMonth?: string) => boolean;
19+
newStateIsAllowable: (key: any, value: any) => boolean;
20+
newStateIsValid: (key: any, value: any, validValues?: any[]) => any;
21+
mutateNewStateIntoRange: (key: any, value: any, validValues?: any[]) => any;
22+
estimatePostSize: (s3FilesState: any, sitesState: any) => any;
23+
getValidValuesFromProductData: (productData: any, key: any) => any;
24+
getInitialStateFromProps: (props: any) => {
25+
availabilityView: any;
26+
productData: any;
27+
downloadContextIsActive: boolean;
28+
broadcast: boolean;
29+
dialogOpen: boolean;
30+
awaitingHigherOrderUpdateWhenDialogOpens: boolean;
31+
cachedHigherOrderState: {};
32+
requiredSteps: never[];
33+
allStepsComplete: boolean;
34+
fromManifest: boolean;
35+
fromAOPManifest: boolean;
36+
fromExternalHost: boolean;
37+
manifest: {
38+
status: string;
39+
value: null;
40+
error: null;
41+
};
42+
s3FileFetches: {};
43+
s3FileFetchProgress: number;
44+
s3Files: {
45+
value: never[];
46+
cachedValues: never[];
47+
validValues: never[];
48+
isValid: boolean;
49+
bytesByUrl: {};
50+
totalSize: number;
51+
estimatedPostSize: number;
52+
filteredFileCount: number;
53+
lastFilterChanged: null;
54+
filters: {
55+
site: never[];
56+
type: never[];
57+
visit: never[];
58+
yearMonth: never[];
59+
};
60+
valueLookups: {
61+
site: {};
62+
type: {};
63+
visit: {};
64+
yearMonth: {};
65+
};
66+
visibleColumns: string[];
67+
};
68+
latestRelease: null;
69+
release: {
70+
value: null;
71+
validValues: never[];
72+
isValid: boolean;
73+
};
74+
sites: {
75+
value: never[];
76+
validValues: never[];
77+
isValid: boolean;
78+
};
79+
dateRange: {
80+
value: string[];
81+
validValues: string[];
82+
isValid: boolean;
83+
};
84+
documentation: {
85+
value: string;
86+
validValues: string[];
87+
isValid: boolean;
88+
};
89+
packageType: {
90+
value: null;
91+
validValues: string[];
92+
isValid: boolean;
93+
};
94+
policies: {
95+
value: boolean;
96+
validValues: null;
97+
isValid: boolean;
98+
};
99+
};
100+
getS3FilesFilteredFileCount: (state: any) => any;
101+
getAndValidateNewS3FilesState: (previousState: any, action: any, broadcast?: boolean) => any;
102+
regenerateS3FilesFiltersAndValidValues: (state: any) => any;
103+
getAndValidateNewState: (previousState: any, action: any, broadcast?: boolean) => any;
104+
ALL_POSSIBLE_VALID_DATE_RANGE: string[];
105+
};
2106
declare namespace DownloadDataContext {
3107
export { Provider };
4108
export { useDownloadDataState };

lib/components/DownloadDataContext/DownloadDataContext.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.default = void 0;
6+
exports.getTestableItems = exports.default = void 0;
77

88
var _react = _interopRequireWildcard(require("react"));
99

@@ -228,6 +228,11 @@ var productDataIsValid = function productDataIsValid(productData) {
228228

229229
var yearMonthIsValid = function yearMonthIsValid() {
230230
var yearMonth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
231+
232+
if (typeof yearMonth !== 'string') {
233+
return false;
234+
}
235+
231236
var match = yearMonth.match(/^([\d]{4})-([\d]{2})$/);
232237

233238
if (!match) {
@@ -254,7 +259,7 @@ var newStateIsAllowable = function newStateIsAllowable(key, value) {
254259
});
255260

256261
case 'dateRange':
257-
return Array.isArray(value) && value.length === 2 && yearMonthIsValid(value[0]) && yearMonthIsValid(value[1]) && value[0] >= ALL_POSSIBLE_VALID_DATE_RANGE[0] && value[1] <= ALL_POSSIBLE_VALID_DATE_RANGE[1];
262+
return Array.isArray(value) && value.length === 2 && yearMonthIsValid(value[0]) && yearMonthIsValid(value[1]) && value[0] >= ALL_POSSIBLE_VALID_DATE_RANGE[0] && value[1] <= ALL_POSSIBLE_VALID_DATE_RANGE[1] && value[0] <= value[1];
258263

259264
case 'documentation':
260265
return ALL_POSSIBLE_VALID_DOCUMENTATION.includes(value) || value === null;
@@ -288,24 +293,27 @@ var newStateIsValid = function newStateIsValid(key, value) {
288293

289294
switch (key) {
290295
case 'sites':
291-
return Array.isArray(value) && Array.isArray(validValues) && value.length > 0 && value.every(function (site) {
296+
return newStateIsAllowable(key, value) && Array.isArray(validValues) && value.length > 0 && value.every(function (site) {
292297
return validValues.includes(site);
293298
});
294299

295300
case 'dateRange':
296-
return Array.isArray(value) && value.length === 2 && Array.isArray(validValues) && validValues.length === 2 && yearMonthIsValid(value[0]) && yearMonthIsValid(value[1]) && yearMonthIsValid(validValues[0]) && yearMonthIsValid(validValues[1]) && value[0] >= validValues[0] && value[1] <= validValues[1];
301+
return newStateIsAllowable(key, value) && newStateIsAllowable(key, validValues) && value[0] >= validValues[0] && value[1] <= validValues[1];
297302

298303
case 's3Files':
304+
if (!Array.isArray(validValues) || !validValues.length || !validValues.every(function (f) {
305+
return _typeof(f) === 'object' && f !== null && typeof f.url === 'string' && f.url.length;
306+
})) {
307+
return false;
308+
}
309+
299310
idList = validValues.map(function (fileObj) {
300311
return fileObj.url;
301312
});
302-
return Array.isArray(value) && value.length > 0 && value.every(function (id) {
313+
return newStateIsAllowable(key, value) && value.length > 0 && value.every(function (id) {
303314
return idList.includes(id);
304315
});
305316

306-
case 'policies':
307-
return value === true;
308-
309317
default:
310318
return newStateIsAllowable(key, value) && validValues.includes(value);
311319
}
@@ -329,7 +337,7 @@ var mutateNewStateIntoRange = function mutateNewStateIntoRange(key, value) {
329337

330338
case 'dateRange':
331339
valueIsDefault = valueIsAllowable && value[0] === ALL_POSSIBLE_VALID_DATE_RANGE[0] && value[1] === ALL_POSSIBLE_VALID_DATE_RANGE[1];
332-
return valueIsAllowable || valueIsDefault ? [value[0] < validValues[0] ? validValues[0] : value[0], value[1] > validValues[0] ? validValues[1] : value[1]] : validValues;
340+
return valueIsAllowable || valueIsDefault ? [value[0] < validValues[0] ? validValues[0] : value[0], value[1] > validValues[1] ? validValues[1] : value[1]] : validValues;
333341

334342
default:
335343
return valueIsAllowable ? value : DEFAULT_STATE[key].value;
@@ -1281,5 +1289,26 @@ var DownloadDataContext = {
12811289
ALL_STEPS: ALL_STEPS,
12821290
getStateObservable: getStateObservable
12831291
};
1284-
var _default = DownloadDataContext;
1285-
exports.default = _default;
1292+
var _default = DownloadDataContext; // Additional items exported for unit testing
1293+
1294+
exports.default = _default;
1295+
1296+
var getTestableItems = function getTestableItems() {
1297+
return process.env.NODE_ENV !== 'test' ? {} : {
1298+
productDataIsValid: productDataIsValid,
1299+
yearMonthIsValid: yearMonthIsValid,
1300+
newStateIsAllowable: newStateIsAllowable,
1301+
newStateIsValid: newStateIsValid,
1302+
mutateNewStateIntoRange: mutateNewStateIntoRange,
1303+
estimatePostSize: estimatePostSize,
1304+
getValidValuesFromProductData: getValidValuesFromProductData,
1305+
getInitialStateFromProps: getInitialStateFromProps,
1306+
getS3FilesFilteredFileCount: getS3FilesFilteredFileCount,
1307+
getAndValidateNewS3FilesState: getAndValidateNewS3FilesState,
1308+
regenerateS3FilesFiltersAndValidValues: regenerateS3FilesFiltersAndValidValues,
1309+
getAndValidateNewState: getAndValidateNewState,
1310+
ALL_POSSIBLE_VALID_DATE_RANGE: ALL_POSSIBLE_VALID_DATE_RANGE
1311+
};
1312+
};
1313+
1314+
exports.getTestableItems = getTestableItems;

lib/components/DownloadStepForm/DownloadStepForm.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
114114
var useStyles = (0, _styles.makeStyles)(function (theme) {
115115
return {
116116
copyButton: {
117-
marginLeft: _Theme.default.spacing(2)
117+
marginLeft: theme.spacing(2)
118118
},
119119
fileTable: {
120120
position: 'relative',
@@ -146,13 +146,13 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
146146
marginRight: theme.spacing(2)
147147
},
148148
calloutIconBrown: {
149-
color: theme.colors.BROWN[300],
149+
color: _Theme.default.colors.BROWN[300],
150150
marginRight: theme.spacing(2)
151151
},
152152
calloutBrown: {
153-
marginBottom: _Theme.default.spacing(3),
154-
backgroundColor: theme.colors.BROWN[50],
155-
borderColor: theme.colors.BROWN[300]
153+
marginBottom: theme.spacing(3),
154+
backgroundColor: _Theme.default.colors.BROWN[50],
155+
borderColor: _Theme.default.colors.BROWN[300]
156156
},
157157
radio: {
158158
marginBottom: theme.spacing(1)
@@ -678,7 +678,7 @@ function DownloadStepForm(props) {
678678
marginBottom: _Theme.default.spacing(4)
679679
}
680680
}, "Loading files (".concat(Math.floor(s3FileFetchProgress || 0), "%)...")), /*#__PURE__*/_react.default.createElement(_CircularProgress.default, {
681-
variant: "static",
681+
variant: "determinate",
682682
value: s3FileFetchProgress
683683
}))) : /*#__PURE__*/_react.default.createElement(_Typography.default, {
684684
variant: "subtitle1",

lib/components/TimeSeriesViewer/TimeSeriesViewerContext.d.ts

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ export function getTestableItems(): {
110110
getTimeStep?: undefined;
111111
getUpdatedValueRange?: undefined;
112112
getContinuousDatesArray?: undefined;
113+
limitVariablesToTwoUnits?: undefined;
113114
parseProductData?: undefined;
114115
parseSiteMonthData?: undefined;
115116
parseSiteVariables?: undefined;
116117
parseSitePositions?: undefined;
117118
reducer?: undefined;
119+
setDataFileFetchStatuses?: undefined;
118120
TimeSeriesViewerPropTypes?: undefined;
119121
} | {
120122
DEFAULT_STATE: {
@@ -176,11 +178,16 @@ export function getTestableItems(): {
176178
getTimeStep: (input?: string) => string | null;
177179
getUpdatedValueRange: (existingRange: any, newValue: any) => any;
178180
getContinuousDatesArray: (dateRange: any[], roundToYears?: boolean) => any[];
181+
limitVariablesToTwoUnits: (state: any, variables: any) => {
182+
selectedUnits: any[];
183+
variables: any;
184+
};
179185
parseProductData: (productData?: Object) => Object;
180186
parseSiteMonthData: (site: Object, files: any[]) => Object;
181187
parseSiteVariables: (previousVariables: Object, siteCode: string, csv: string) => ParseSiteVariablesReturn;
182188
parseSitePositions: (site: Object, csv: string) => Object;
183189
reducer: (state: any, action: any) => any;
190+
setDataFileFetchStatuses: (state: any, fetches: any) => any;
184191
TimeSeriesViewerPropTypes: {
185192
productCode: (props: any, propName: any, componentName: any) => Error | null;
186193
productData: (props: any, propName: any, componentName: any) => Error | null;
@@ -226,54 +233,7 @@ declare namespace Provider {
226233
export { productData_1 as productData };
227234
}
228235
}
229-
declare function useTimeSeriesViewerState(): any[] | {
230-
status: string;
231-
displayError: null;
232-
fetchProduct: {
233-
status: string;
234-
error: null;
235-
};
236-
metaFetches: {};
237-
dataFetches: {};
238-
dataFetchProgress: number;
239-
variables: {};
240-
product: {
241-
productCode: null;
242-
productName: null;
243-
productDescription: null;
244-
productSensor: null;
245-
dateRange: null[];
246-
continuousDateRange: never[];
247-
sites: {};
248-
};
249-
graphData: {
250-
data: never[];
251-
qualityData: never[];
252-
monthOffsets: {};
253-
timestampMap: {};
254-
series: never[];
255-
labels: string[];
256-
qualityLabels: string[];
257-
};
258-
selection: {
259-
dateRange: null[];
260-
continuousDateRange: never[];
261-
variables: never[];
262-
dateTimeVariable: null;
263-
sites: never[];
264-
timeStep: string;
265-
autoTimeStep: null;
266-
qualityFlags: never[];
267-
rollPeriod: number;
268-
logscale: boolean;
269-
yAxes: {
270-
y1: any;
271-
y2: any;
272-
};
273-
};
274-
availableQualityFlags: Set<any>;
275-
availableTimeSteps: Set<string>;
276-
};
236+
declare function useTimeSeriesViewerState(): any;
277237
declare namespace TimeSeriesViewerPropTypes {
278238
export function productCode_2(props: any, propName: any, componentName: any): Error | null;
279239
export { productCode_2 as productCode };

0 commit comments

Comments
 (0)