|
| 1 | +import {calculateBaseStepDuration, calculateStepDuration, linear, calculateMovementTimesteps} from "./mouse-movement.function"; |
| 2 | + |
| 3 | +describe("MovementType", () => { |
| 4 | + describe("baseStepDuration", () => { |
| 5 | + it("should calculate the base step duration in nanoseconds", () => { |
| 6 | + // GIVEN |
| 7 | + const speedInPixelsPerSecond = 1000; |
| 8 | + const expectedBaseStepDuration = 1_000_000; |
| 9 | + |
| 10 | + // WHEN |
| 11 | + const result = calculateBaseStepDuration(speedInPixelsPerSecond); |
| 12 | + |
| 13 | + // THEN |
| 14 | + expect(result).toBe(expectedBaseStepDuration); |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + describe("stepDuration", () => { |
| 19 | + it("should call easing function with current progress to calculate current step duration", () => { |
| 20 | + // GIVEN |
| 21 | + const baseStepDuraton = 1_000_000; |
| 22 | + const currentProgress = 1.0; |
| 23 | + const easingFunction = jest.fn(() => 0); |
| 24 | + |
| 25 | + // WHEN |
| 26 | + const result = calculateStepDuration(currentProgress, baseStepDuraton, easingFunction); |
| 27 | + |
| 28 | + // THEN |
| 29 | + expect(result).toBe(baseStepDuraton); |
| 30 | + expect(easingFunction).toBeCalledTimes(1); |
| 31 | + expect(easingFunction).toBeCalledWith(currentProgress); |
| 32 | + }) |
| 33 | + }); |
| 34 | + |
| 35 | + describe('linear', () => { |
| 36 | + it("should return a set of linear timesteps, 1000000 nanosecond per step.", () => { |
| 37 | + const expected = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000]; |
| 38 | + expect(calculateMovementTimesteps(6, 1000, linear)).toEqual(expected); |
| 39 | + }); |
| 40 | + |
| 41 | + it("should should return a set of linear timesteps, 2000000 nanoseconds per step.", () => { |
| 42 | + const expected = [2000000, 2000000, 2000000, 2000000, 2000000, 2000000]; |
| 43 | + expect(calculateMovementTimesteps(6, 500, linear)).toEqual(expected); |
| 44 | + }); |
| 45 | + }); |
| 46 | +}) |
| 47 | +; |
0 commit comments