import reducer from "../../../store/reducers/technology/technologiesReducer";
import expect from "expect";
import {
  changeIsCheckedValue,
  resetIsCheckedValue,
  setTechnologies,
  setTechnologiesError,
} from "../../../store/actions/technologies/technologiesActions";

describe("technologies reducer", () => {
  it("should set techologies", () => {
    expect(reducer(undefined, setTechnologies(["tech1", "tech2"]))).toEqual({
      technologies: ["tech1", "tech2"],
      errorMessage: "",
    });
  });

  it("should set error", () => {
    expect(reducer(undefined, setTechnologiesError("Error"))).toEqual({
      technologies: [],
      errorMessage: "Error",
    });
  });

  it("should check tech", () => {
    expect(
      reducer(
        {
          technologies: [
            { id: 1, name: "T1", isChecked: false },
            { id: 2, name: "T2", isChecked: false },
          ],
          errorMessage: "",
        },
        changeIsCheckedValue("T1")
      )
    ).toEqual({
      technologies: [
        { id: 1, name: "T1", isChecked: true },
        { id: 2, name: "T2", isChecked: false },
      ],
      errorMessage: "",
    });
  });

  it("should reset checked techs", () => {
    expect(
      reducer(
        {
          technologies: [
            { id: 1, name: "T1", isChecked: true },
            { id: 2, name: "T2", isChecked: true },
          ],
          errorMessage: "",
        },
        resetIsCheckedValue("T1")
      )
    ).toEqual({
      technologies: [
        { id: 1, name: "T1", isChecked: false },
        { id: 2, name: "T2", isChecked: false },
      ],
      errorMessage: "",
    });
  });
});
