-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: uts for areaChart, barChart, sparkAreaChart, Legend (#1065)
* uts for areaChart, barChart, sparkAreaChart, Legend * removed test code * lint --------- Co-authored-by: wajahat5 <[email protected]> Co-authored-by: severinlandolt <[email protected]>
- Loading branch information
1 parent
866d578
commit dfc8978
Showing
4 changed files
with
290 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import AreaChart from "components/chart-elements/AreaChart/AreaChart"; | ||
|
||
describe("AreaChart", () => { | ||
beforeAll(() => { | ||
global.ResizeObserver = class MockedResizeObserver { | ||
observe = jest.fn(); | ||
unobserve = jest.fn(); | ||
disconnect = jest.fn(); | ||
}; | ||
const mockChildMethod = jest.fn(); | ||
jest.spyOn(React, "useRef").mockReturnValue({ | ||
current: { | ||
childMethod: mockChildMethod, | ||
}, | ||
}); | ||
}); | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
it("renders the chart with data", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const { container } = render( | ||
<AreaChart data={data} categories={["A", "B", "C"]} index="name" ref={ref} />, | ||
); | ||
expect(container.getElementsByClassName("w-full h-80").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart without gradient", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
showGradient={false} | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-full h-80").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with custom colors", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
colors={["#ff0000", "#00ff00", "#0000ff"]} | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-full h-80").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with custom curve type", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
curveType="monotone" | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-full h-80").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with connectNulls", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: null }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const { container } = render( | ||
<AreaChart data={data} categories={["A", "B", "C"]} index="name" connectNulls />, | ||
); | ||
expect(container.getElementsByClassName("w-full h-80").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with no data", () => { | ||
const { getByText } = render(<AreaChart data={[]} categories={[]} index="name" />); | ||
expect(getByText("No data")).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import BarChart from "components/chart-elements/BarChart/BarChart"; | ||
|
||
describe("BarChart", () => { | ||
beforeAll(() => { | ||
global.ResizeObserver = class MockedResizeObserver { | ||
observe = jest.fn(); | ||
unobserve = jest.fn(); | ||
disconnect = jest.fn(); | ||
}; | ||
const mockChildMethod = jest.fn(); | ||
jest.spyOn(React, "useRef").mockReturnValue({ | ||
current: { | ||
childMethod: mockChildMethod, | ||
}, | ||
}); | ||
}); | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
it("renders the chart with data", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
render(<BarChart data={data} categories={["A", "B", "C"]} index="name" ref={ref} />); | ||
}); | ||
|
||
it("renders the chart with no data", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { getByText } = render(<BarChart data={[]} categories={[]} index="name" ref={ref} />); | ||
expect(getByText("No data")).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import AreaChart from "components/spark-elements/SparkAreaChart/SparkAreaChart"; | ||
|
||
describe("AreaChart", () => { | ||
beforeAll(() => { | ||
global.ResizeObserver = class MockedResizeObserver { | ||
observe = jest.fn(); | ||
unobserve = jest.fn(); | ||
disconnect = jest.fn(); | ||
}; | ||
const mockChildMethod = jest.fn(); | ||
jest.spyOn(React, "useRef").mockReturnValue({ | ||
current: { | ||
childMethod: mockChildMethod, | ||
}, | ||
}); | ||
}); | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
it("renders the chart with data", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
className="test" | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-28 h-12 test").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart without gradient", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
className="test" | ||
showGradient={false} | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-28 h-12 test").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with custom colors", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
className="test" | ||
colors={["#ff0000", "#00ff00", "#0000ff"]} | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-28 h-12 test").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with custom curve type", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: 20 }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
className="test" | ||
curveType="monotone" | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-28 h-12 test").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with connectNulls", () => { | ||
const data = [ | ||
{ name: "A", value: 10 }, | ||
{ name: "B", value: null }, | ||
{ name: "C", value: 30 }, | ||
]; | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { container } = render( | ||
<AreaChart | ||
data={data} | ||
categories={["A", "B", "C"]} | ||
index="name" | ||
className="test" | ||
connectNulls | ||
ref={ref} | ||
/>, | ||
); | ||
expect(container.getElementsByClassName("w-28 h-12 test").length).toBe(1); | ||
}); | ||
|
||
it("renders the chart with no data", () => { | ||
const ref = React.useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const { getByText } = render(<AreaChart data={[]} categories={[]} index="name" ref={ref} />); | ||
expect(getByText("No data")).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters