polylines tooltip content
This commit is contained in:
42
__tests__/unit/hooks/useLineData.test.js
Normal file
42
__tests__/unit/hooks/useLineData.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { renderHook, act, waitFor } from "@testing-library/react";
|
||||
import useLineData from "../../../hooks/useLineData";
|
||||
import React from "react";
|
||||
|
||||
const mockUrl = "http://mockurl.com";
|
||||
const mockData1 = {
|
||||
Statis: [{ IdLD: 1, Modul: "mod1", PrioColor: "red", ModulName: "Module 1", ModulTyp: "Type 1", Message: "Message 1", PrioName: "High", DpName: "DP 1", Value: "Value 1" }],
|
||||
};
|
||||
const mockData2 = [{ idLD: 1, idModul: "mod1" }];
|
||||
|
||||
global.fetch = jest.fn((url) => {
|
||||
if (url === mockUrl) {
|
||||
return Promise.resolve({
|
||||
json: () => Promise.resolve(mockData1),
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
json: () => Promise.resolve(mockData2),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("useLineData", () => {
|
||||
test("should fetch line data and set line colors and tooltip contents", async () => {
|
||||
const setLineStatusData = jest.fn();
|
||||
|
||||
const { result } = renderHook(() => useLineData(mockUrl, setLineStatusData));
|
||||
|
||||
await waitFor(
|
||||
() => {
|
||||
expect(setLineStatusData).toHaveBeenCalledWith(expect.any(Array));
|
||||
expect(result.current).toEqual(
|
||||
expect.objectContaining({
|
||||
lineColors: expect.any(Object),
|
||||
tooltipContents: expect.any(Object),
|
||||
})
|
||||
);
|
||||
},
|
||||
{ timeout: 5000 } // Increase the timeout to 5000ms
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user