import { getPosition } from "../utils";
import { IExerciseItem } from "../types";

const exercises: IExerciseItem[] = [
  { exercise: "exercise1", duration: 1, offset: 0 },
  { exercise: "exercise2", duration: 2, offset: 1 },
  { exercise: "exercise3", duration: 3, offset: 3 },
  { exercise: "exercise4", duration: 4, offset: 6 }
];

describe("finds the right position in the exercise.", () => {
  it("can handle negative numbers.", () => {
    const result = getPosition(exercises, -10);
    expect(result).toEqual({
      previousExercise: null,
      currentExercise: exercises[0],
      nextExercise: exercises[1],
      exerciseTime: 0
    });
  });
  it("can find the low first exercise.", () => {
    const result = getPosition(exercises, 0);
    expect(result).toEqual({
      previousExercise: null,
      currentExercise: exercises[0],
      nextExercise: exercises[1],
      exerciseTime: 0
    });
  });
  it("can find the high first exercise.", () => {
    const result = getPosition(exercises, 0.99);
    expect(result).toEqual({
      previousExercise: null,
      currentExercise: exercises[0],
      nextExercise: exercises[1],
      exerciseTime: 0.99
    });
  });
  it("can find the low second exercise.", () => {
    const result = getPosition(exercises, 1);
    expect(result).toEqual({
      previousExercise: exercises[0],
      currentExercise: exercises[1],
      nextExercise: exercises[2],
      exerciseTime: 0
    });
  });
  it("can find the high second exercise.", () => {
    const result = getPosition(exercises, 2.99);
    expect(result).toEqual({
      previousExercise: exercises[0],
      currentExercise: exercises[1],
      nextExercise: exercises[2],
      exerciseTime: 2.99 - 1
    });
  });
  it("can find the low third exercise.", () => {
    const result = getPosition(exercises, 3);
    expect(result).toEqual({
      previousExercise: exercises[1],
      currentExercise: exercises[2],
      nextExercise: exercises[3],
      exerciseTime: 0
    });
  });
  it("can find the high third exercise.", () => {
    const result = getPosition(exercises, 5.99);
    expect(result).toEqual({
      previousExercise: exercises[1],
      currentExercise: exercises[2],
      nextExercise: exercises[3],
      exerciseTime: 5.99 - 3
    });
  });
  it("can find the low fourth exercise.", () => {
    const result = getPosition(exercises, 6);
    expect(result).toEqual({
      previousExercise: exercises[2],
      currentExercise: exercises[3],
      nextExercise: null,
      exerciseTime: 0
    });
  });
  it("can find the high fourth exercise.", () => {
    const result = getPosition(exercises, 9.99);
    expect(result).toEqual({
      previousExercise: exercises[2],
      currentExercise: exercises[3],
      nextExercise: null,
      exerciseTime: 9.99 - 6
    });
  });
  it("can find the fourth exercise.", () => {
    const result = getPosition(exercises, 10);
    expect(result).toEqual({
      previousExercise: null,
      currentExercise: null,
      nextExercise: null,
      exerciseTime: 0
    });
  });
});
