|
| 1 | +import { parseData, parseLayout, parseConfig } from "../utils/utils"; |
| 2 | + |
| 3 | +describe("parseData", () => { |
| 4 | + it("returns empty array when all inputs are empty", () => { |
| 5 | + expect(parseData()).toEqual([]); |
| 6 | + }); |
| 7 | + |
| 8 | + it("parses staticData only", () => { |
| 9 | + const staticData = JSON.stringify([{ x: [1], y: [2] }]); |
| 10 | + expect(parseData(staticData)).toEqual([{ x: [1], y: [2] }]); |
| 11 | + }); |
| 12 | + |
| 13 | + it("parses sampleData when attributeData and staticData are empty", () => { |
| 14 | + const sampleData = JSON.stringify([{ x: [3], y: [4] }]); |
| 15 | + expect(parseData(undefined, undefined, sampleData)).toEqual([{ x: [3], y: [4] }]); |
| 16 | + }); |
| 17 | + |
| 18 | + it("parses attributeData and ignores sampleData if attributeData is present", () => { |
| 19 | + const attributeData = JSON.stringify([{ x: [5], y: [6] }]); |
| 20 | + const sampleData = JSON.stringify([{ x: [7], y: [8] }]); |
| 21 | + expect(parseData(undefined, attributeData, sampleData)).toEqual([{ x: [5], y: [6] }]); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +describe("parseLayout", () => { |
| 26 | + it("returns empty object when all inputs are empty", () => { |
| 27 | + expect(parseLayout()).toEqual({}); |
| 28 | + }); |
| 29 | + |
| 30 | + it("parses staticLayout only", () => { |
| 31 | + const staticLayout = JSON.stringify({ title: "Test" }); |
| 32 | + expect(parseLayout(staticLayout)).toEqual({ title: "Test" }); |
| 33 | + }); |
| 34 | + |
| 35 | + it("parses sampleLayout when attributeLayout and staticLayout are empty", () => { |
| 36 | + const sampleLayout = JSON.stringify({ title: "Sample" }); |
| 37 | + expect(parseLayout(undefined, undefined, sampleLayout)).toEqual({ title: "Sample" }); |
| 38 | + }); |
| 39 | + |
| 40 | + it("parses attributeLayout and ignores sampleLayout if attributeLayout is present", () => { |
| 41 | + const attributeLayout = JSON.stringify({ title: "Attr" }); |
| 42 | + const sampleLayout = JSON.stringify({ title: "Sample" }); |
| 43 | + expect(parseLayout(undefined, attributeLayout, sampleLayout)).toEqual({ title: "Attr" }); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +describe("parseConfig", () => { |
| 48 | + it("returns empty object when configOptions is empty", () => { |
| 49 | + expect(parseConfig()).toEqual({}); |
| 50 | + }); |
| 51 | + |
| 52 | + it("parses configOptions", () => { |
| 53 | + const configOptions = JSON.stringify({ responsive: true }); |
| 54 | + expect(parseConfig(configOptions)).toEqual({ responsive: true }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments