import { fromJS } from "immutable";
import zaloReducer from "../reducer";
import * as actions from "../actions";
import {
  ZALO_TEMPLATE_INFO_SUCCESS,
  ZALO_TEMPLATE_INFO_ERROR,
  ZALO_TEMPLATE_PREVIEW_INFO,
  ZALO_TEMPLATE_PREVIEW_RESET,
  ZALO_TEMPLATE_INFO_RESET,
  REQUEST,
  SUCCESS,
  ERROR,
} from "../constants";
import { editData } from "./mockData";

describe("zalo reducer", () => {
  describe("Reducer : ZALO_TEMPLATE_INFO_REQUEST", () => {
    it.concurrent("should handle ZALO_TEMPLATE_INFO_REQUEST action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const expectedResult = state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplateInfoValue", "")
        .set("zaloTemplateInfoError", null);
      expect(zaloReducer(state, actions.getTemplateInfoById({}))).toEqual(expectedResult);
    });

    it.concurrent("should handle ZALO_TEMPLATE_INFO_SUCCESS action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: ZALO_TEMPLATE_INFO_SUCCESS,
        result: editData.zaloTemplateInfoValue,
      };
      const expectedResult = state
        .set("zaloTemplateInfoStatus", SUCCESS)
        .set("zaloTemplateInfoValue", action.result)
        .set("zaloTemplateInfoError", null);
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle ZALO_TEMPLATE_INFO_ERROR action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: ZALO_TEMPLATE_INFO_ERROR,
        error: {},
      };
      const expectedResult = state
        .set("zaloTemplateInfoStatus", ERROR)
        .set("zaloTemplateInfoError", action.error);
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle ZALO_TEMPLATE_PREVIEW_INFO action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: ZALO_TEMPLATE_PREVIEW_INFO,
        result: editData.zaloTemplateInfoValue,
      };
      const expectedResult = state
        .set("zaloTemplateInfoStatus", SUCCESS)
        .set("zaloTemplatePreviewData", action.result)
        .set("zaloTemplateInfoError", null);
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle ZALO_TEMPLATE_PREVIEW_RESET action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: ZALO_TEMPLATE_PREVIEW_RESET,
      };
      const expectedResult = state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplatePreviewData", "")
        .set("zaloTemplateInfoError", null);
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle ZALO_TEMPLATE_INFO_RESET action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: ZALO_TEMPLATE_INFO_RESET,
      };
      const expectedResult = state
        .set("zaloTemplateInfoStatus", REQUEST)
        .set("zaloTemplateInfoValue", "")
        .set("zaloTemplateInfoError", null);
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle default action", () => {
      const state = fromJS({
        zaloTemplateInfoStatus: "",
        zaloTemplateInfoValue: "",
        zaloTemplateInfoError: "",
      });
      const action = {
        type: "deafult_action",
      };
      const expectedResult = state;
      expect(zaloReducer(state, action)).toEqual(expectedResult);
    });
  });
});
