import reducer from "../../../store/reducers/technology/addAddTechnologiesReducer";
import expect from "expect";
import {
  changeIsCheckedAddAdValue,
  resetIsCheckedAddAdValue,
  setTechnologiesAddAd,
  setTechnologiesAddAdError,
} from "../../../store/actions/addAdTechnologies/addAdTechnologiesActions";

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

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

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

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