Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit tests for the Plot panel module #318

Merged
merged 105 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
af0b6ec
Datum tests
laisspportugal Dec 30, 2024
e140045
MathFunctions tests
laisspportugal Dec 31, 2024
09edb94
Remove lint checker
laisspportugal Dec 31, 2024
b5fdedb
Undo modifications on mathFunction logic and undo creation of Basic B…
laisspportugal Dec 31, 2024
c06d58c
Modifying math functions
laisspportugal Dec 31, 2024
cba2f14
Update function to treat exceptions
laisspportugal Dec 31, 2024
1b2cb9a
Fix lint
laisspportugal Dec 31, 2024
9d31880
Plot legend tests
laisspportugal Jan 3, 2025
43113a4
Adding more tests to PlotLegend
laisspportugal Jan 3, 2025
7badc63
restructuring of ChartRenderer file: created types.ts, EventHandler.t…
ctw-joao-luis Jan 6, 2025
e29e6ca
update imports from ChartRenderer to types.ts
ctw-joao-luis Jan 6, 2025
3b6746f
import fixes
ctw-joao-luis Jan 6, 2025
b15bd8a
ChartOptions and EventHandler unit tests
ctw-joao-luis Jan 6, 2025
f98f8ed
Vertical bars test
laisspportugal Jan 7, 2025
0da3e84
change tests
aneuwald-ctw Jan 8, 2025
026a361
restructuring Plot.tsx file: created hook for MouseEvents
ctw-joao-luis Jan 8, 2025
8c912be
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
ctw-joao-luis Jan 8, 2025
3efd948
Vanising tests
laisspportugal Jan 8, 2025
93ff92e
Merge branch 'feature/plot-unit-tests' of https://github.com/bmw-soft…
laisspportugal Jan 8, 2025
1815b73
lint
laisspportugal Jan 8, 2025
fe1fc95
chart renderer unit tests
luluiz Jan 8, 2025
8a1b46e
getElementsAtPixel unit tests
luluiz Jan 9, 2025
f0e8782
updateDatasets unit tests
luluiz Jan 9, 2025
a89f682
added unit test when update should return undefined
luluiz Jan 9, 2025
6190801
Moving types from Verticalbars
laisspportugal Jan 9, 2025
3432f90
Merge branch 'feature/plot-unit-tests' of https://github.com/bmw-soft…
laisspportugal Jan 9, 2025
c3138b1
Rename PlotProps type
laisspportugal Jan 9, 2025
ff391ec
Moving styles to another file
laisspportugal Jan 9, 2025
a88cef0
Lint fixes
laisspportugal Jan 9, 2025
9468a18
unit tests for interaction events
luluiz Jan 9, 2025
96f6812
Moving getPixelForXValue function to another file and adding unit tests
laisspportugal Jan 9, 2025
9dc9a0e
Merge branch 'feature/plot-unit-tests' of https://github.com/bmw-soft…
laisspportugal Jan 9, 2025
3dd53d5
removed unused imports
luluiz Jan 9, 2025
e9c169a
Merge branch 'feature/plot-unit-tests' of https://github.com/bmw-soft…
laisspportugal Jan 9, 2025
0a94698
more hooks and code restructured from Plot.tsx
ctw-joao-luis Jan 9, 2025
d12cfe1
Adding more test contions to verticalBars
laisspportugal Jan 9, 2025
a525741
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
ctw-joao-luis Jan 9, 2025
0393e7e
VerticalBars.test lint fix
ctw-joao-luis Jan 9, 2025
01fc544
test to handle reference lines in update action
luluiz Jan 9, 2025
752a1d5
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
luluiz Jan 9, 2025
39380f2
improved chart renderer unit test
luluiz Jan 9, 2025
553fa0b
added usePannign hook, fixed useRenderer lint issue
ctw-joao-luis Jan 9, 2025
e668065
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
ctw-joao-luis Jan 9, 2025
c0564cb
Addint useSubscriptions tests
laisspportugal Jan 9, 2025
e2010ff
Lint fixes
laisspportugal Jan 9, 2025
be45037
Adding more test cases
laisspportugal Jan 9, 2025
79780f2
Adding more tests to useSubscriptions
laisspportugal Jan 9, 2025
507468b
Organizing tests
laisspportugal Jan 9, 2025
30ae992
Add tests when xAxisPath is invalid
laisspportugal Jan 10, 2025
5731317
created usePlotDataHandling hook | updated useHoverHandlers name to …
ctw-joao-luis Jan 10, 2025
e9c3328
additional refactoring on Plot.tsx
ctw-joao-luis Jan 10, 2025
58cf0d5
Add tests for useGlobalSync, usePanning
laisspportugal Jan 10, 2025
7ad2334
Merge branch 'feature/plot-unit-tests' of https://github.com/bmw-soft…
laisspportugal Jan 10, 2025
6675cdd
Small fixes on usePanning tests
laisspportugal Jan 10, 2025
1c5f878
added unit tests to useRenderer
ctw-joao-luis Jan 10, 2025
3470a91
Add test plot Interaction Handlers
laisspportugal Jan 13, 2025
2764d8c
Lint fixes
laisspportugal Jan 13, 2025
2d2615d
Lint fixes
laisspportugal Jan 13, 2025
838d5b6
lint
laisspportugal Jan 13, 2025
7cf7c9f
added unit tests to usePlotDataHandling hook
ctw-joao-luis Jan 13, 2025
bee57ab
Add more tests
laisspportugal Jan 13, 2025
848876d
lint
laisspportugal Jan 13, 2025
322235a
Adding more tests to PlotInteractionHandlers
laisspportugal Jan 13, 2025
ff51f87
Adding more tests to usePlotInteraction when no coordinator is informed
laisspportugal Jan 13, 2025
7538929
Plot unit tests
luluiz Jan 13, 2025
da77ba0
Fix lint rule on usePanning test
laisspportugal Jan 13, 2025
b39e657
Add and improve tests on usePlotInteractionHandlers
laisspportugal Jan 13, 2025
db2527e
Adding more tests to PlotInteractionHandlers
laisspportugal Jan 14, 2025
3f3ea96
Lint fixes
laisspportugal Jan 14, 2025
7e0bca5
plot unit test improvements
luluiz Jan 14, 2025
f4c9432
Plot.tsx using i18n
luluiz Jan 14, 2025
c42f30e
Adding more tests to usePlotInteratctionHandlers
laisspportugal Jan 14, 2025
86cad33
Lint fixes
laisspportugal Jan 14, 2025
3b00636
Add more tests to useSubscriptions
laisspportugal Jan 14, 2025
957356d
fixed Reset view button behaviour
luluiz Jan 14, 2025
b3c32aa
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
luluiz Jan 14, 2025
d4c7568
Remove unnecessary if condition and add more tests to usePlotInteract…
laisspportugal Jan 14, 2025
2bedcc7
Lint fixes
laisspportugal Jan 14, 2025
af826b9
Lint ci fixes
laisspportugal Jan 14, 2025
972e2d7
Cleaning useSubscriptions tests
laisspportugal Jan 14, 2025
6eaa9ee
Clean usePanning tests
laisspportugal Jan 14, 2025
f38ef8b
refactoring and restructuring some files
ctw-joao-luis Jan 14, 2025
acc2879
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
ctw-joao-luis Jan 14, 2025
6dfb7bd
Improve usePlotIteractionHandlers test
laisspportugal Jan 15, 2025
d15a081
improve testes on useplotInterationHandler
laisspportugal Jan 15, 2025
4c32e7d
Fix test plotLegend
laisspportugal Jan 15, 2025
cf61683
improved unit tests for usePlotInteractionHandlers
luluiz Jan 15, 2025
5724c94
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
luluiz Jan 15, 2025
b600bdf
improved unit tests of usePlotDataHandling
luluiz Jan 15, 2025
9181d96
added unit test in usePlotDataHandling when xAxisPath in not supported
luluiz Jan 15, 2025
2e4a8e4
added unit test to usePlotDataHandling when xAxisVal is timestamp
luluiz Jan 15, 2025
f7b5a61
Merge remote-tracking branch 'origin' into feature/plot-unit-tests
luluiz Jan 15, 2025
d6cd685
Refactoring some tests to use basicbuilder into getPixelForXValue tests
laisspportugal Jan 16, 2025
d1f0523
refactored unit tests of usePanning
luluiz Jan 17, 2025
1d67f43
unit test use panning
luluiz Jan 17, 2025
fd09e4f
Small improvements on useRenderer test
laisspportugal Jan 17, 2025
80030ee
Removing unnecessary comments
laisspportugal Jan 17, 2025
fc88c3b
Lint fixes
laisspportugal Jan 17, 2025
f4c7a04
improved useSubscriptions
luluiz Jan 17, 2025
b8a4942
Merge branch 'feature/plot-unit-tests' of github.com:Lichtblick-Suite…
luluiz Jan 17, 2025
d702bdf
added unit test in useSubscriptions
luluiz Jan 17, 2025
e01c0dd
called config properties by the original name
luluiz Jan 17, 2025
169d708
add typing in preloadType var
luluiz Jan 20, 2025
9d4e245
Removing unnecessary library
laisspportugal Jan 20, 2025
0acac82
Lint fixes
laisspportugal Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/suite-base/src/components/Chart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ export type RpcElement = {
y: number;
};
};

export type EventListenerHandler = (eventName: string, fn?: () => void) => void;
23 changes: 4 additions & 19 deletions packages/suite-base/src/components/Chart/worker/ChartJSManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import EventEmitter from "eventemitter3";
import { Zoom as ZoomPlugin } from "@lichtblick/chartjs-plugin-zoom";
import Logger from "@lichtblick/log";
import { RpcElement, RpcScales } from "@lichtblick/suite-base/components/Chart/types";
import {
addEventListener,
removeEventListener,
} from "@lichtblick/suite-base/components/Chart/worker/eventHandler";
import { maybeCast } from "@lichtblick/suite-base/util/maybeCast";
import { fontMonospace } from "@lichtblick/theme";

Expand All @@ -54,25 +58,6 @@ export type InitOpts = {
// allows us to override the chart.ctx instance field which zoom plugin uses for adding event listeners
type MutableContext<T> = Omit<Chart, "ctx"> & { ctx: T };

function addEventListener(emitter: EventEmitter) {
return (eventName: string, fn?: () => void) => {
const existing = emitter.listeners(eventName);
if (!fn || existing.includes(fn)) {
return;
}

emitter.on(eventName, fn);
};
}

function removeEventListener(emitter: EventEmitter) {
return (eventName: string, fn?: () => void) => {
if (fn) {
emitter.off(eventName, fn);
}
};
}

type ZoomableChart = Chart & {
$zoom: {
panStartHandler(event: HammerInput): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
// SPDX-License-Identifier: MPL-2.0

import EventEmitter from "eventemitter3";

import { addEventListener, removeEventListener } from "./eventHandler";

describe("EventHandler", () => {
let emitter: EventEmitter;

beforeEach(() => {
emitter = new EventEmitter();
});

describe("addEventListener", () => {
it("should add an event listener if it doesn't already exist", () => {
const handler = jest.fn();
const addListener = addEventListener(emitter);

addListener("testEvent", handler);
emitter.emit("testEvent");

expect(handler).toHaveBeenCalledTimes(1);
});

it("should not add the same event listener multiple times", () => {
const handler = jest.fn();
const addListener = addEventListener(emitter);

addListener("testEvent", handler);
addListener("testEvent", handler);
emitter.emit("testEvent");

expect(handler).toHaveBeenCalledTimes(1);
});

it("should not add a listener if the function is undefined", () => {
const addListener = addEventListener(emitter);

addListener("testEvent");
expect(emitter.listeners("testEvent")).toHaveLength(0);
});
});

describe("removeEventListener", () => {
it("should remove an existing event listener", () => {
const handler = jest.fn();
const addListener = addEventListener(emitter);
const removeListener = removeEventListener(emitter);

addListener("testEvent", handler);
removeListener("testEvent", handler);
emitter.emit("testEvent");

expect(handler).not.toHaveBeenCalled();
});

it("should not throw if removing a listener that doesn't exist", () => {
const handler = jest.fn();
const removeListener = removeEventListener(emitter);

expect(() => {
removeListener("testEvent", handler);
}).not.toThrow();
});

it("should not remove listeners if the function is undefined", () => {
const handler = jest.fn();
const addListener = addEventListener(emitter);
const removeListener = removeEventListener(emitter);

addListener("testEvent", handler);
removeListener("testEvent");
emitter.emit("testEvent");

expect(handler).toHaveBeenCalledTimes(1);
});
});
});
25 changes: 25 additions & 0 deletions packages/suite-base/src/components/Chart/worker/eventHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
// SPDX-License-Identifier: MPL-2.0

import EventEmitter from "eventemitter3";

import { EventListenerHandler } from "@lichtblick/suite-base/components/Chart/types";

export function addEventListener(emitter: EventEmitter): EventListenerHandler {
return (eventName: string, fn?: () => void): void => {
const existing = emitter.listeners(eventName);
if (!fn || existing.includes(fn)) {
return;
}

emitter.on(eventName, fn);
};
}

export function removeEventListener(emitter: EventEmitter): EventListenerHandler {
return (eventName: string, fn?: () => void) => {
if (fn) {
emitter.off(eventName, fn);
}
};
}
1 change: 1 addition & 0 deletions packages/suite-base/src/i18n/en/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const plot = {
min: "Min",
position: "Position",
receiveTime: "Receive Time",
resetView: "Reset view",
secondsRange: "Range (seconds)",
series: "Series",
showLabels: "Show labels",
Expand Down
Loading
Loading