|
| 1 | +/* eslint max-nested-callbacks: 0 */ |
| 2 | +import { helperMethods } from "victory-candlestick"; |
| 3 | +import { range } from "lodash"; |
| 4 | +import { fromJS } from "immutable"; |
| 5 | + |
| 6 | +const immutableGetDataTest = { |
| 7 | + createData: (x) => fromJS(x), |
| 8 | + testLabel: "with immutable data" |
| 9 | +}; |
| 10 | +const getDataTest = { |
| 11 | + createData: (x) => x, |
| 12 | + testLabel: "with js data" |
| 13 | +}; |
| 14 | + |
| 15 | +const { getData, getDomain } = helperMethods; |
| 16 | + |
| 17 | +[getDataTest, immutableGetDataTest].forEach(({ createData, testLabel }) => { |
| 18 | + describe(`victory-candlestick/helper-methods ${testLabel}`, () => { |
| 19 | + describe("getData", () => { |
| 20 | + it("sorts data by sortKey", () => { |
| 21 | + const data = createData( |
| 22 | + range(5) |
| 23 | + .map((i) => ({ x: i, open: i, close: i, high: i, low: i })) |
| 24 | + .reverse() |
| 25 | + ); |
| 26 | + |
| 27 | + const dataResult = getData({ |
| 28 | + data, |
| 29 | + x: "x", |
| 30 | + open: "open", |
| 31 | + close: "close", |
| 32 | + high: "high", |
| 33 | + low: "low", |
| 34 | + sortKey: "x" |
| 35 | + }); |
| 36 | + |
| 37 | + expect(dataResult.map((datum) => datum.x)).toEqual([0, 1, 2, 3, 4]); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe("getDomain", () => { |
| 42 | + const dataSet = createData([ |
| 43 | + { x: 5, open: 10, close: 20, high: 25, low: 5 }, |
| 44 | + { x: 10, open: 15, close: 25, high: 30, low: 10 } |
| 45 | + ]); |
| 46 | + |
| 47 | + it("returns a domain array for the x axis", () => { |
| 48 | + const domainXResult = getDomain( |
| 49 | + { |
| 50 | + data: dataSet, |
| 51 | + x: "x", |
| 52 | + open: "open", |
| 53 | + close: "close", |
| 54 | + high: "high", |
| 55 | + low: "low" |
| 56 | + }, |
| 57 | + "x" |
| 58 | + ); |
| 59 | + expect(domainXResult).toEqual([5, 10]); |
| 60 | + }); |
| 61 | + |
| 62 | + it("returns a domain array for the y axis", () => { |
| 63 | + const domainYResult = getDomain( |
| 64 | + { |
| 65 | + data: dataSet, |
| 66 | + open: "open", |
| 67 | + close: "close", |
| 68 | + high: "high", |
| 69 | + low: "low" |
| 70 | + }, |
| 71 | + "y" |
| 72 | + ); |
| 73 | + expect(domainYResult).toEqual([5, 30]); |
| 74 | + }); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments