Skip to content

Commit

Permalink
Adding more tests to useSubscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
laisspportugal committed Jan 9, 2025
1 parent be45037 commit 79780f2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/suite-base/src/panels/Plot/hooks/useSubscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
});

});

0 comments on commit 79780f2

Please sign in to comment.