Files
wraith4081 c5f6d9116e build: migrate build system to Vite and test runner to Vitest & Remove
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
2025-12-27 00:12:39 +03:00

56 lines
1.9 KiB
TypeScript

import { ProgressBar } from "../../../src/client/graphics/ProgressBar";
describe("ProgressBar", () => {
let ctx: CanvasRenderingContext2D;
let canvas: HTMLCanvasElement;
beforeEach(() => {
canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 20;
ctx = canvas.getContext("2d")!;
});
it("should initialize and draw the background", () => {
const spyClearRect = vi.spyOn(ctx, "clearRect");
const spyFillRect = vi.spyOn(ctx, "fillRect");
const spyFillStyle = vi.spyOn(ctx, "fillStyle", "set");
const bar = new ProgressBar(["#ff0000", "#00ff00"], ctx, 2, 2, 80, 10, 0.5);
expect(spyClearRect).toHaveBeenCalledWith(0, 0, 82, 12);
expect(spyFillRect).toHaveBeenCalledWith(1, 1, 80, 10);
expect(spyFillStyle).toHaveBeenCalledWith("#00ff00");
expect(bar.getX()).toBe(2);
expect(bar.getY()).toBe(2);
});
it("should set progress and draw the progress bar", () => {
const bar = new ProgressBar(["#ff0000", "#00ff00"], ctx, 2, 2, 80, 10);
const spyFillRect = vi.spyOn(ctx, "fillRect");
bar.setProgress(0.5);
expect(bar.getProgress()).toBe(0.5);
expect(spyFillRect).toHaveBeenCalledWith(
2,
2,
Math.floor(0.5 * (80 - 2)),
8,
);
expect(ctx.fillStyle).toBe("#00ff00");
bar.setProgress(0.1);
expect(ctx.fillStyle).toBe("#ff0000");
});
it("should clamp progress between 0 and 1 on init", () => {
const bar = new ProgressBar(["#ff0000", "#00ff00"], ctx, 2, 2, 80, 10, -1);
expect(bar.getProgress()).toBe(0);
const bar2 = new ProgressBar(["#ff0000", "#00ff00"], ctx, 2, 2, 80, 10, 2);
expect(bar2.getProgress()).toBe(1);
});
it("should handle empty colors array gracefully", () => {
const bar = new ProgressBar([], ctx, 2, 2, 80, 10, 0.5);
expect(() => bar.setProgress(0.5)).not.toThrow();
expect(ctx.fillStyle).toBe("#808080");
});
});