import { fromJS, Map as ImmutableMap } from 'immutable';
import {
  GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
  GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
  GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
  REQUEST,
  SUCCESS,
  FAILURE,
  GET_LIQUID_TAGS_SUCCESS,
  GET_LIQUID_TAGS_FAILURE,
  GET_LIQUID_TAGS_REQUEST,
  GET_SCHEMA_FOR_ENTITY_SUCCESS,
  SET_INJECTED_TAGS,
} from '../constants';
import reducer from '../reducer';
import initialState from '../../../initialState';
import {
  expectedStateGetLiquidTagsRequest,
  expectedStateGetLiquidTagsFailure,
  expectedStateGetLiquidTagsSuccess,
  expectedStateGetSchemaForEntitySuccessTAG,
  expectedStateGetSchemaForEntitySuccess,
} from '../mockData';
import { loadItem } from '../../../services/localStorageApi';


describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
  const mockedInitialState = fromJS(initialState.cap);
  it.concurrent('should handle GET_SUPPORT_VIDEOS_CONFIG_REQUEST', () => {
    const action = {
      type: GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual({
      ...mockedInitialState.toJS(),
      demoVideoAndLinkJSON: {},
      demoVideoAndLinkJSONStatus: REQUEST,
    });
  });

  it.concurrent('it handles the GET_SUPPORT_VIDEOS_CONFIG_SUCCESS action', () => {
    const result = {
      is_active: true,
      _id: "12345",
      json_config: [
        { data: 'Test data' },
      ],
    };
    const action = {
      type: GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
      result,
      GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual({
      ...mockedInitialState.toJS(),
      demoVideoAndLinkJSON: result,
      demoVideoAndLinkJSONStatus: SUCCESS,
    });
  });

  it.concurrent('should handle GET_SUPPORT_VIDEOS_CONFIG_FAILURE', () => {
    const error = 'Error';
    const action = {
      type: GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
      error,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual({
      ...mockedInitialState.toJS(),
      demoVideoAndLinkJSONError: error,
      demoVideoAndLinkJSONStatus: FAILURE,
    });
  });
  it.concurrent('handles the GET_LIQUID_TAGS_REQUEST action', () => {
    const action = {
      type: GET_LIQUID_TAGS_REQUEST,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetLiquidTagsRequest);
  });

  it.concurrent('handles the GET_LIQUID_TAGS_FAILURE action', () => {
    const action = {
      type: GET_LIQUID_TAGS_FAILURE,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetLiquidTagsFailure);
  });

  it.concurrent('handles the GET_LIQUID_TAGS_SUCCESS action', () => {
    const action = {
      type: GET_LIQUID_TAGS_SUCCESS,
    };
    expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetLiquidTagsSuccess);
  });

  it.concurrent('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action with action type as TAG', () => {
    const action = {
      type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
      data: { metaEntities: { standard: { random: "32" } } },
      entityType: "TAG",
    };

    expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccessTAG);
  });

  it.concurrent('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action', () => {
    const action = {
      type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
      data: { metaEntities: { standard: { random: "32" } } },
    };

    expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccess);
  });
  it.concurrent('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action', () => {
    const action = {
      type: SET_INJECTED_TAGS,
      data: {},
    };

    expect(reducer(mockedInitialState, action).toJS())?.fetchingSchema?.toEqual(true);
  });
});
