import reducer from "../../../../store/reducers/pattern/patternsReducer";
import expect from "expect";
import {
  setPatterns,
  setPatternsError,
  setFilteredPatterns,
  setFilteredPatternsError,
} from "../../../../store/actions/patterns/patternsActions";
import { mockState } from "../../../../mockState";

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

  it("should set the state error when setPatternsError is called", () => {
    expect(reducer(undefined, setPatternsError("Error"))).toEqual({
      patterns: [],
      errorMessage: "Error",
    });
  });

  it("should set the state success when setPatterns is called", () => {
    expect(
      reducer(undefined, setPatterns(mockState.patterns.patterns))
    ).toEqual({
      patterns: mockState.patterns.patterns,
      errorMessage: "",
    });
  });

  it("should set the state error when setFilteredPatternsError is called", () => {
    expect(reducer(undefined, setFilteredPatternsError("Error"))).toEqual({
      patterns: [],
      errorMessage: "Error",
    });
  });

  it("should set the state success when setFilteredPatterns is called", () => {
    expect(
      reducer(undefined, setFilteredPatterns(mockState.patterns.patterns))
    ).toEqual({
      patterns: mockState.patterns.patterns,
      errorMessage: "",
    });
  });
});
