@fusioncharts/fusiontime
Version:
FusionCharts JavaScript time-series charting framework
1 lines • 5.14 kB
JavaScript
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _axis=_interopRequireDefault(require("./axis"));var _index=_interopRequireDefault(require("@fusioncharts/datatable/src/aggregators/index.js"));var expand=function expand(expandedAxis,actions){if(expandedAxis===void 0){expandedAxis=[]}if(actions===void 0){actions=[]}return{expandedAxis:expandedAxis,actions:actions}};describe("Axis expander",(function(){describe("by default",(function(){it("expands all input column names to correct axis configurations",(function(){expect((0,_axis.default)(["Weight","Horsepower","Mileage","TopSpeed"])).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"},{plot:[{type:"line",value:"Mileage",aggregation:"avg"}],title:"Mileage"},{plot:[{type:"line",value:"TopSpeed",aggregation:"avg"}],title:"TopSpeed"}]))}))}));describe("expands the input columns correctly when the input configuration is",(function(){var columnNames=["Weight","Horsepower"];it("undefined",(function(){expect((0,_axis.default)(columnNames)).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}));it("null",(function(){expect((0,_axis.default)(columnNames,null)).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}));it("an empty string",(function(){expect((0,_axis.default)(columnNames,"")).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}));it("an empty array",(function(){expect((0,_axis.default)(columnNames,[])).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}))}));it("should exactly match its output to a fully expanded input",(function(){var expandedInput=[{plot:[{type:"line",typeinnavigator:undefined,value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",typeinnavigator:undefined,value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}];expect((0,_axis.default)(["Weight","Horsepower"],expandedInput)).toEqual(expand(expandedInput))}));describe("should create configurations with valid column name properties",(function(){var columnNames=["Horsepower","Mileage"];it("when input is a string",(function(){expect((0,_axis.default)(columnNames,"Horsepower")).toEqual(expand([{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}));it("when input is an object",(function(){expect((0,_axis.default)(columnNames,{plot:"Horsepower"})).toEqual(expand([{plot:[{type:"line",typeinnavigator:undefined,value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}));it("when input is an array",(function(){expect((0,_axis.default)(columnNames,[{plot:[{value:"Horsepower"}]}])).toEqual(expand([{plot:[{type:"line",typeinnavigator:undefined,value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}]))}))}));it("should not change the case of any keys is the input",(function(){expect((0,_axis.default)(["Mileage","Horsepower"],{plot:"Mileage",stYle:{}})).toEqual(expand([{plot:[{value:"Mileage",typeinnavigator:undefined,type:"line",aggregation:"avg"}],title:"Mileage",stYle:{}}]))}));describe('should create "fullaxis" actions with default expansion when',(function(){var columnNames=["Weight","Horsepower"];it("invalid objects are provided",(function(){expect((0,_axis.default)(columnNames,[{plot:"TopSpeed"},{plot:"Mileage"}])).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}],["fullaxis"]))}));it("invalid strings are provided",(function(){expect((0,_axis.default)(columnNames,["TopSpeed","Mileage"])).toEqual(expand([{plot:[{type:"line",value:"Weight",aggregation:"avg"}],title:"Weight"},{plot:[{type:"line",value:"Horsepower",aggregation:"avg"}],title:"Horsepower"}],["fullaxis"]))}))}));it("should normalize the casing of provided aggregations to lowercase if the aggregation is a default aggregation",(function(){var defaultAggs=Object.keys(_index.default.getDefaultAggregations());defaultAggs.forEach((function(agg){expect((0,_axis.default)(["Horsepower"],{plot:"Horsepower",aggregation:agg.toUpperCase()})).toEqual(expand([{title:"Horsepower",plot:[{type:"line",typeinnavigator:undefined,value:"Horsepower",aggregation:agg}],aggregation:agg}]))}))}));it("should NOT normalize the casing of provided aggregations to lowercase if the aggregation is a default aggregation",(function(){_index.default.register("myAgg",(function(){return 84}));expect((0,_axis.default)(["Horsepower"],{plot:"Horsepower",aggregation:"myAgg"})).toEqual(expand([{title:"Horsepower",plot:[{type:"line",typeinnavigator:undefined,value:"Horsepower",aggregation:"myAgg"}],aggregation:"myAgg"}]))}))}));