import { fromJS } from 'immutable';
import creativesContainerReducer from '../reducer';
import {
  DEFAULT_ACTION,
  SHOW_CONTANER_LOADER,
  HIDE_CONTAINER_LOADER,
  STORE_LOYALTY_TAG_PROPS,
} from '../constants';

describe('creativesContainerReducer', () => {
  const initialState = fromJS({ containerLoader: true });

  describe('Reducer', () => {
    it.concurrent('should handle DEFAULT_ACTION', () => {
      const state = fromJS({ containerLoader: true });
      const action = { type: DEFAULT_ACTION };
      expect(creativesContainerReducer(state, action)).toEqual(state);
    });

    it.concurrent('should handle SHOW_CONTANER_LOADER', () => {
      const state = fromJS({ containerLoader: false });
      const action = { type: SHOW_CONTANER_LOADER };
      const expectedResult = state.set('containerLoader', true);
      expect(creativesContainerReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent('should handle HIDE_CONTAINER_LOADER', () => {
      const state = fromJS({ containerLoader: true });
      const action = { type: HIDE_CONTAINER_LOADER };
      const expectedResult = state.set('containerLoader', false);
      expect(creativesContainerReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent('should handle STORE_LOYALTY_TAG_PROPS', () => {
      const state = fromJS({ containerLoader: true });
      const loyaltyProps = { tagId: '123', tagName: 'Test Tag' };
      const action = {
        type: STORE_LOYALTY_TAG_PROPS,
        props: loyaltyProps,
      };
      const expectedResult = state.set('loyaltyTagProps', loyaltyProps);
      expect(creativesContainerReducer(state, action)).toEqual(expectedResult);
    });

    it.concurrent('should handle default action', () => {
      const state = fromJS({ containerLoader: true });
      const action = { type: 'unknown_action' };
      expect(creativesContainerReducer(state, action)).toEqual(state);
    });

    it.concurrent('should return initial state when state is undefined', () => {
      const action = { type: 'unknown_action' };
      expect(creativesContainerReducer(undefined, action)).toEqual(initialState);
    });

    it.concurrent('should handle null action', () => {
      const state = fromJS({ containerLoader: true });
      expect(creativesContainerReducer(state, null)).toEqual(state);
    });

    it.concurrent('should handle undefined action', () => {
      const state = fromJS({ containerLoader: true });
      expect(creativesContainerReducer(state, undefined)).toEqual(state);
    });

    it.concurrent('should handle action without type property', () => {
      const state = fromJS({ containerLoader: true });
      const action = { payload: 'some data' };
      expect(creativesContainerReducer(state, action)).toEqual(state);
    });
  });
});
