import ProgressIndicatorReducer from "../ProgressIndicatorReducer";

describe("progress indicator reducer", () => {
  it("should return the initial state", () => {
    expect(ProgressIndicatorReducer()).toStrictEqual({
      count: 0,
      timestamp: 0,
      percentComplete: 0,
    });
  });

  it("should handle START_PROGRESS", () => {
    expect(
      ProgressIndicatorReducer(undefined, {
        type: "START_PROGRESS",
      }),
    ).toStrictEqual({
      count: 1,
      timestamp: 0,
      percentComplete: 0,
    });
  });

  it("should handle FINISH_PROGRESS", () => {
    expect(
      ProgressIndicatorReducer(
        {
          count: 1,
          timestamp: 0,
          percentComplete: 0,
        },
        {
          type: "FINISH_PROGRESS",
        },
      ),
    ).toStrictEqual(
      expect.objectContaining({
        count: 0,
        percentComplete: 0,
      }),
    );
  });

  it("should handle RESET_PROGRESS", () => {
    expect(
      ProgressIndicatorReducer(
        {
          count: 1,
          timestamp: 0,
          percentComplete: 0,
        },
        {
          type: "RESET_PROGRESS",
        },
      ),
    ).toStrictEqual({
      count: 0,
      timestamp: 0,
      percentComplete: 0,
    });
  });

  it("should handle UPDATE_PROGRESS", () => {
    expect(
      ProgressIndicatorReducer(
        {
          count: 1,
          timestamp: 0,
          percentComplete: 0,
        },
        {
          type: "UPDATE_PROGRESS",
          payload: { percentComplete: 40 },
        },
      ),
    ).toStrictEqual({
      count: 1,
      timestamp: 0,
      percentComplete: 40,
    });
  });
});
