mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 10:48:10 +00:00
c5f6d9116e
depracated husky usage - Replace Webpack with Vite for faster client bundling and HMR. - Migrate tests from Jest to Vitest and update configuration. - Update Web Worker instantiation to standard ESM syntax. - Implement Env utility in `src/core` for safe, hybrid environment variable access (Vite vs Node). - Refactor configuration loaders to remove direct `process.env` dependencies in shared code. - Update TypeScript environment definitions and project scripts for the new toolchain. - Remove the [depracated usage of the husky](https://github.com/typicode/husky/releases/tag/v9.0.1). build(vite): implement robust git commit resolution with fallback
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { vi, type MockInstance } from "vitest";
|
|
import { getMessageTypeClasses, severityColors } from "../src/client/Utils";
|
|
import { MessageType } from "../src/core/game/Game";
|
|
|
|
describe("getMessageTypeClasses", () => {
|
|
// Spy on console.warn to track when the default case is hit
|
|
let consoleSpy: MockInstance;
|
|
|
|
beforeEach(() => {
|
|
consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
});
|
|
|
|
afterEach(() => {
|
|
consoleSpy.mockRestore();
|
|
});
|
|
|
|
it("should return a valid CSS class for every MessageType", () => {
|
|
const messageTypes = Object.values(MessageType).filter(
|
|
(value): value is MessageType => typeof value === "number",
|
|
);
|
|
|
|
messageTypes.forEach((messageType) => {
|
|
const result = getMessageTypeClasses(messageType);
|
|
|
|
expect(Object.values(severityColors)).toContain(result);
|
|
|
|
expect(result).toBeTruthy();
|
|
expect(typeof result).toBe("string");
|
|
});
|
|
});
|
|
|
|
it("should not trigger console.warn for any MessageType", () => {
|
|
const messageTypes = Object.values(MessageType).filter(
|
|
(value): value is MessageType => typeof value === "number",
|
|
);
|
|
|
|
messageTypes.forEach((messageType) => {
|
|
getMessageTypeClasses(messageType);
|
|
});
|
|
|
|
// No message type should fall through to the default case
|
|
expect(consoleSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return white color and warn for unknown message types", () => {
|
|
// Cast to MessageType to test the default case
|
|
const unknownType = 999 as MessageType;
|
|
|
|
const result = getMessageTypeClasses(unknownType);
|
|
|
|
expect(result).toBe(severityColors["white"]);
|
|
expect(consoleSpy).toHaveBeenCalledWith(
|
|
"Message type 999 has no explicit color",
|
|
);
|
|
});
|
|
});
|