|
| 1 | +import "jest"; |
| 2 | +import { applyDefaults } from "../apply-defaults"; |
| 3 | +import { ChartType } from "@data-forge-plot/chart-def"; |
| 4 | + |
| 5 | +describe("apply defaults", () => { |
| 6 | + |
| 7 | + it("chart type defaults to line 1", () => { |
| 8 | + const inputChartDef: any = { data: { columnOrder: [], }, plotConfig: {} }; |
| 9 | + const expanded = applyDefaults(inputChartDef); |
| 10 | + expect(expanded.plotConfig!.chartType!).toEqual(ChartType.Line); |
| 11 | + }); |
| 12 | + |
| 13 | + it("chart type defaults to line 2", () => { |
| 14 | + const inputChartDef: any = { data: { columnOrder: [], }, plotConfig: {} }; |
| 15 | + const expanded = applyDefaults(inputChartDef); |
| 16 | + expect(expanded.plotConfig!.chartType!).toEqual(ChartType.Line); |
| 17 | + }); |
| 18 | + |
| 19 | + it("width defaults to 800", () => { |
| 20 | + const inputChartDef: any = { data: { columnOrder: [], }, plotConfig: {} }; |
| 21 | + const expanded = applyDefaults(inputChartDef); |
| 22 | + expect(expanded.plotConfig!.width).toEqual(800); |
| 23 | + }); |
| 24 | + |
| 25 | + it("height defaults to 600", () => { |
| 26 | + const inputChartDef: any = { data: { columnOrder: [], }, plotConfig: {} }; |
| 27 | + const expanded = applyDefaults(inputChartDef); |
| 28 | + expect(expanded.plotConfig!.height).toEqual(600); |
| 29 | + }); |
| 30 | + |
| 31 | + it("y axis defaults to all columns when no y axis series is specified 1", () => { |
| 32 | + |
| 33 | + const data: any = { columnOrder: ["a", "b", "c"] }; |
| 34 | + const plotConfig: any = {}; |
| 35 | + const axisMap: any = {}; |
| 36 | + const inputChartDef: any = { data, plotConfig, axisMap }; |
| 37 | + const expanded = applyDefaults(inputChartDef); |
| 38 | + expect(expanded.axisMap.y).toEqual([ |
| 39 | + { |
| 40 | + series: "a", |
| 41 | + }, |
| 42 | + { |
| 43 | + series: "b", |
| 44 | + }, |
| 45 | + { |
| 46 | + series: "c", |
| 47 | + }, |
| 48 | + ]); |
| 49 | + expect(expanded.axisMap.y2).toEqual([]); |
| 50 | + }); |
| 51 | + |
| 52 | + it("y axis defaults to all columns when no y axis series is specified 2", () => { |
| 53 | + |
| 54 | + const data: any = { columnOrder: ["a", "b", "c"] }; |
| 55 | + const plotConfig: any = {}; |
| 56 | + const axisMap: any = { y: [], y2: [] }; |
| 57 | + const inputChartDef: any = { data, plotConfig, axisMap }; |
| 58 | + const expanded = applyDefaults(inputChartDef); |
| 59 | + expect(expanded.axisMap.y).toEqual([ |
| 60 | + { |
| 61 | + series: "a", |
| 62 | + }, |
| 63 | + { |
| 64 | + series: "b", |
| 65 | + }, |
| 66 | + { |
| 67 | + series: "c", |
| 68 | + }, |
| 69 | + ]); |
| 70 | + expect(expanded.axisMap.y2).toEqual([]); |
| 71 | + }); |
| 72 | +}); |
0 commit comments