import { fromJS } from "immutable";
import inAppReducer from "../reducer";
import * as actions from "../actions";
import * as types from "../constants";
// import { editData } from "./mockData";


describe("zalo reducer", () => {
  describe("Reducer : INAPP_TEMPLATE_CREATE_REQUEST", () => {
    it.concurrent("should handle INAPP_TEMPLATE_CREATE_REQUEST action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const expectedResult = state
        .set("createTemplateInProgress", true)
        .set("createTemplateError", false)
        .set("createTemplateErrorMessage", "");
      expect(inAppReducer(state, actions.createInAppTemplate({}))).toEqual(expectedResult);
    });

    it.concurrent("should handle INAPP_TEMPLATE_CREATE_SUCCESS action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const action = {
        type: types.INAPP_TEMPLATE_CREATE_SUCCESS,
        data: 'data',
      };
      const expectedResult = state
        .set("createTemplateInProgress", false)
        .set("createTemplateError", false)
        .set("createTemplateErrorMessage", undefined)
        .set('response', 'data');
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle INAPP_TEMPLATE_CREATE_FAILURE action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const action = {
        type: types.INAPP_TEMPLATE_CREATE_FAILURE,
        errorMsg: 'error',
      };
      const expectedResult = state
        .set("createTemplateInProgress", false)
        .set('createTemplateError', true)
        .set('createTemplateErrorMessage', fromJS(action.errorMsg));
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
  });
  describe("Reducer : INAPP_EDIT_TEMPLATE_REQUEST", () => {
    it.concurrent("should handle INAPP_EDIT_TEMPLATE_REQUEST action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const expectedResult = state
        .set("editTemplateInProgress", true)
        .set("editTemplateError", false)
        .set("editTemplateErrorMessage", "");
      expect(inAppReducer(state, actions.editTemplate({}))).toEqual(
        expectedResult
      );
    });
    it.concurrent("should handle INAPP_EDIT_TEMPLATE_SUCCESS action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const action = {
        type: types.INAPP_EDIT_TEMPLATE_SUCCESS,
        data: 'data',
        statusCode: 200,
      };
      const expectedResult = state
        .set("editTemplateInProgress", false)
        .set("editTemplateError", false)
        .set("editTemplateErrorMessage", undefined)
        .set('editResponse', 'data');
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle INAPP_EDIT_TEMPLATE_FAILURE action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const action = {
        type: types.INAPP_EDIT_TEMPLATE_FAILURE,
        errorMsg: 'error',
      };
      const expectedResult = state
        .set("editTemplateInProgress", false)
        .set('editTemplateError', true)
        .set('editTemplateErrorMessage', fromJS(action.errorMsg));
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent("should handle default action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
      });
      const action = {
        type: "deafult_action",
      };
      const expectedResult = state;
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
  });
  describe("Reducer : GET_TEMPLATE_DETAILS_REQUEST", () => {
    it.concurrent("should handle GET_TEMPLATE_DETAILS_REQUEST action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        getTemplateDetailsInProgress: true,
      });
      const expectedResult = state;
      expect(inAppReducer(state, actions.getTemplateDetails({}))).toEqual(
        expectedResult
      );
    });
    it.concurrent("should handle INAPP_EDIT_TEMPLATE_SUCCESS action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        getTemplateDetailsInProgress: false,
        templateDetails: 'data',
      });
      const action = {
        type: types.GET_INAPP_TEMPLATE_DETAILS_SUCCESS,
        data: 'data',
        statusCode: 200,
      };
      const expectedResult = state;
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle GET_TEMPLATE_DETAILS_FAILURE action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        getTemplateDetailsInProgress: false,
      });
      const action = {
        type: types.GET_INAPP_TEMPLATE_DETAILS_FAILURE,
        errorMsg: 'error',
      };
      const expectedResult = state;
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle CLEAR_CREATE_RESPONSE_REQUEST action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        response: {},
      });
      const action = {
        type: types.CLEAR_CREATE_RESPONSE_REQUEST,
      };
      const expectedResult = state.set("response", {});
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle RESET_EDIT_TEMPLATE action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        templateDetails: {},
      });
      const action = {
        type: types.RESET_EDIT_TEMPLATE,
      };
      const expectedResult = state.set("templateDetails", {});
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
  });
  describe("Reducer : UPLOAD_INAPP_ASSET_REQUEST", () => {
    it.concurrent("should handle UPLOAD_INAPP_ASSET_REQUEST action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        uploadAssetSuccess: false,
        assetUploading: true,
      });
      const expectedResult = state;
      expect(inAppReducer(state, actions.uploadInAppAsset({}))).toEqual(
        expectedResult
      );
    });
    it.concurrent("should handle UPLOAD_INAPP_ASSET_SUCCESS action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        getTemplateDetailsInProgress: false,
        assetUploading: false,
        uploadAssetSuccess: false,
      });
      const action = {
        type: types.UPLOAD_INAPP_ASSET_SUCCESS,
        data: 'data',
        statusCode: 200,
      };
      const expectedResult = state
        .set("getTemplateDetailsInProgress", false)
        .set('assetUploading', false)
        .set('uploadAssetSuccess', true)
        .set('uploadedAssetData', 'data');
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle UPLOAD_INAPP_ASSET_FAILURE action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        uploadAssetSuccess: false,
        assetUploading: false,
      });
      const action = {
        type: types.UPLOAD_INAPP_ASSET_FAILURE,
        errorMsg: 'error',
      };
      const expectedResult = state
        .set("assetUploading", false)
        .set('uploadAssetSuccess', false);
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle CLEAR_INAPP_ASSET action", () => {
      const state = fromJS({
        uploadedAssetData: {},
        createTemplateInProgress: false,
        editTemplateInProgress: false,
        assetUploading: false,
        uploadAssetSuccess: false,
      });
      const action = {
        type: types.CLEAR_INAPP_ASSET,
        errorMsg: 'error',
        data: 'data',
      };
      const expectedResult = state
        .set("assetUploading", false)
        .delete('uploadedAssetData', {})
        .set('uploadAssetSuccess', false);
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
  });
  describe("Reducer : GET_BEE_POPUP_BUILDER_TOKEN_REQUEST", () => {
    it.concurrent("should handle GET_BEE_POPUP_BUILDER_TOKEN_REQUEST action", () => {
      const state = fromJS({
        beePopupBuilderTokenFetching: false,
      });
      const expectedResult = state.set("beePopupBuilderTokenFetching", true);
      expect(inAppReducer(state, actions.getBeePopupBuilderToken({}))).toEqual(expectedResult);
    });
    it.concurrent("should handle GET_BEE_POPUP_BUILDER_TOKEN_SUCCESS action", () => {
      const state = fromJS({
        beePopupBuilderTokenFetching: false,
        beePopupBuilderToken: 'data',
      });
      const action = {
        type: types.GET_BEE_POPUP_BUILDER_TOKEN_SUCCESS,
        data: 'data',
      };
      const expectedResult = state.set("beePopupBuilderTokenFetching", false).set("beePopupBuilderToken", 'data');
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
    it.concurrent("should handle GET_BEE_POPUP_BUILDER_TOKEN_FAILURE action", () => {
      const state = fromJS({
        beePopupBuilderTokenFetching: false,
        beePopupBuilderTokenError: true,
        beePopupBuilderTokenErrorMessage: 'error',
      });
      const action = {
        type: types.GET_BEE_POPUP_BUILDER_TOKEN_FAILURE,
        error: 'error',
      };
      const expectedResult = state.set("beePopupBuilderTokenFetching", false).set("beePopupBuilderTokenError", true).set("beePopupBuilderTokenErrorMessage", fromJS('error'));
      expect(inAppReducer(state, action)).toEqual(expectedResult);
    });
  });
});
