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

Adding unit tests for FoxgloveWebSocketPlayer module #335

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ctw-joao-luis
Copy link
Contributor

@ctw-joao-luis ctw-joao-luis commented Jan 23, 2025

User-Facing Changes
N/A

Description

Added some unit tests to files that provide support for the WebSocket player, also did some refactoring on the module.
Couldn't finish testing the whole module because I was having trouble accessing private fields and methods of the websocket class.

Checklist

  • The web version was tested and it is running ok
  • The desktop version was tested and it is running ok
  • This change is covered by unit tests
  • Files constants.ts, types.ts and *.style.ts have been checked and relevant code snippets have been relocated

@ctw-joao-luis ctw-joao-luis added the enhancement New feature or request label Jan 23, 2025
@ctw-joao-luis ctw-joao-luis marked this pull request as ready for review January 29, 2025 10:37

const result = dataTypeToFullName(message);

expect(result).toContain("/msg/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(result).toBe("unit/msg/test") to be more precise

export type ToWorkerMessage =
| { type: "open"; data: { wsUrl: string; protocols?: string[] | string } }
| { type: "close"; data: undefined }
| { type: "data"; data: string | ArrayBuffer | ArrayBufferView }; // SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ours from here and put the old one in the top of the file

it("should not call onerror if it is undefined", () => {
mockWorker.onmessage?.({ data: { type: "error" } } as MessageEvent);

expect(adapter.onerror).toBeUndefined();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expect the onerror not to have been called as well.

Suggested change
expect(adapter.onerror).toBeUndefined();
expect(adapter.onerror).toBeUndefined();
expect(onErrorMock).not.toHaveBeenCalled();

it("should not call onmessage if it is undefined", () => {
mockWorker.onmessage?.({ data: { type: "message" } } as MessageEvent);

expect(adapter.onmessage).toBeUndefined();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expect the onmessage not to have been called as well.

Suggested change
expect(adapter.onmessage).toBeUndefined();
expect(adapter.onmessage).toBeUndefined();
expect(onMessageMock).not.toHaveBeenCalled();

const errorEvent = { message: "error" } as ErrorEvent;
mockWorker.onerror?.(errorEvent);

expect(adapter.onerror).toBeUndefined();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be undefined since it is being set as undefined in L169. You can delete this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants