import reducer from "../../../../store/reducers/processes/statusReducer";
import expect from "expect";
import {
  setStatuses,
  setStatusesError,
  changeStatusIsCheckedValue,
} from "../../../../store/actions/processes/statusAction";

describe("status reducer", () => {
  it("should return the initial state", () => {
    expect(reducer(undefined, {})).toEqual({
      statuses: [],
      errorMessage: "",
    });
  });

  it("should set the state error", () => {
    expect(reducer(undefined, setStatusesError("Error"))).toEqual({
      statuses: [],
      errorMessage: "Error",
    });
  });

  it("should set the state success", () => {
    expect(reducer(undefined, setStatuses(["option1", "option2"]))).toEqual({
      statuses: ["option1", "option2"],
      errorMessage: "",
    });
  });

  it("should not change status because there is no option with name which we send as argument", async () => {
    expect(
      reducer(
        {
          statuses: [{ name: "option1" }, { name: "option2" }],
          errorMessage: "",
        },
        changeStatusIsCheckedValue("option3")
      )
    ).toEqual({
      statuses: [{ name: "option1" }, { name: "option2" }],
      errorMessage: "",
    });
  });

  it("should not change status because there is option with name which we send as argument", async () => {
    expect(
      reducer(
        {
          statuses: [
            { name: "option1", isChecked: false },
            { name: "option2", isChecked: false },
          ],
          errorMessage: "",
        },
        changeStatusIsCheckedValue("option1")
      )
    ).toEqual({
      statuses: [
        { name: "option1", isChecked: true },
        { name: "option2", isChecked: false },
      ],
      errorMessage: "",
    });
  });
});
