From 79780f2a05d8b2cfa419e9f11f4db478e2c38170 Mon Sep 17 00:00:00 2001 From: Lais Portugal Date: Thu, 9 Jan 2025 20:32:13 +0000 Subject: [PATCH] Adding more tests to useSubscriptions --- .../Plot/hooks/useSubscriptions.test.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/suite-base/src/panels/Plot/hooks/useSubscriptions.test.ts b/packages/suite-base/src/panels/Plot/hooks/useSubscriptions.test.ts index 3a5c5d1347..a195e24663 100644 --- a/packages/suite-base/src/panels/Plot/hooks/useSubscriptions.test.ts +++ b/packages/suite-base/src/panels/Plot/hooks/useSubscriptions.test.ts @@ -5,6 +5,7 @@ import { renderHook } from "@testing-library/react"; +import { parseMessagePath } from "@lichtblick/message-path"; import { useMessagePipeline } from "@lichtblick/suite-base/components/MessagePipeline"; import useGlobalVariables from "@lichtblick/suite-base/hooks/useGlobalVariables"; import { PlotConfig } from "@lichtblick/suite-base/panels/Plot/config"; @@ -21,6 +22,10 @@ jest.mock("@lichtblick/suite-base/hooks/useGlobalVariables", () => ({ default: jest.fn(), })); +jest.mock("@lichtblick/message-path", () => ({ + parseMessagePath: jest.fn(), +})); + describe("useSubscriptions", () => { let setSubscriptions: jest.Mock; let globalVariables: any; @@ -38,6 +43,10 @@ describe("useSubscriptions", () => { (useGlobalVariables as jest.Mock).mockReturnValue({ globalVariables }); jest.clearAllMocks(); + + jest.mock("@lichtblick/message-path", () => ({ + parseMessagePath: jest.fn(), + })); }); const setup = (config: PlotConfig = defaultConfig, subscriberId: string = testSubscriber) => { @@ -118,16 +127,18 @@ describe("useSubscriptions", () => { expect(setSubscriptions).toHaveBeenCalledWith(testSubscriber, expect.any(Array)); }); - it("does not set subscriptions for invalid xAxisPath", () => { - const invalidXAxisConfig: PlotConfig = { - paths: [], + it("does not set subscriptions when parsedPath is undefined", () => { + const mockPath = BasicBuilder.string(); + const configWithInvalidPath: PlotConfig = { + paths: [{ value: mockPath }], xAxisVal: BasicBuilder.string(), - xAxisPath: null, } as any; - setup(invalidXAxisConfig); + (parseMessagePath as jest.Mock).mockReturnValue(undefined); + + setup(configWithInvalidPath); expect(setSubscriptions).toHaveBeenCalledWith(testSubscriber, []); + expect(parseMessagePath).toHaveBeenCalledWith(mockPath); }); - });