import { ActionTypes } from '../AppConstants';
import { fakeImageData, fakeVideoData, rawProfilesData } from './stubData';

jest.dontMock('../stores/ComposerStore');

describe('ComposerStore', () => {
  const actionAddImage = {
    action: {
      actionType: ActionTypes.COMPOSER_ADD_DRAFT_IMAGE,
      id: 'instagram',
      image: fakeImageData,
    },
  };

  const actionAddVideo = {
    action: {
      actionType: ActionTypes.COMPOSER_ADD_DRAFT_VIDEO,
      id: 'instagram',
      video: fakeVideoData,
    },
  };

  const actionUpdateInstaState = {
    action: {
      actionType: ActionTypes.COMPOSER_UPDATE_INSTAGRAM_STATE,
    },
  };

  const actionEnableInstagramDraft = {
    action: {
      actionType: ActionTypes.COMPOSER_ENABLE,
      id: 'instagram',
    },
  };

  const actionAddProfiles = {
    action: {
      actionType: ActionTypes.COMPOSER_CREATE_PROFILES,
      profilesData: rawProfilesData,
    },
  };

  const actionSelectProfile = {
    action: {
      actionType: ActionTypes.COMPOSER_SELECT_PROFILE,
      id: '5a81d9ae63fbc389007b23c6',
    },
  };

  let AppDispatcher;
  let ComposerStore;

  beforeEach(() => {
    // need to recreate the dispatcher & store here each time
    AppDispatcher = require('../dispatcher'); //eslint-disable-line
    ComposerStore = require('../stores/ComposerStore'); //eslint-disable-line
  });

  it('adds instagramFeedback when profile is selected', () => {
    AppDispatcher.dispatch(actionAddProfiles);
    AppDispatcher.dispatch(actionSelectProfile);
    AppDispatcher.dispatch(actionEnableInstagramDraft);
    AppDispatcher.dispatch(actionAddVideo);
    AppDispatcher.dispatch(actionUpdateInstaState);
    const draft = ComposerStore.default.getDraft('instagram');
    expect(draft.instagramFeedback.length).toEqual(1);
  });

  it('adds instagramFeedback for galleries', () => {
    AppDispatcher.dispatch(actionAddProfiles);
    AppDispatcher.dispatch(actionSelectProfile);
    AppDispatcher.dispatch(actionEnableInstagramDraft);
    AppDispatcher.dispatch(actionAddImage);
    AppDispatcher.dispatch(actionAddImage);
    AppDispatcher.dispatch(actionUpdateInstaState);
    const draft = ComposerStore.default.getDraft('instagram');
    expect(draft.instagramFeedback[0].message).toEqual('Due to Instagram limitations, we can\'t post galleries on your behalf. You will receive a reminder to post manually when the time comes!');
  });

  it('sets draft postDirectToInstagram to false when video is added', () => {
    AppDispatcher.dispatch(actionAddProfiles);
    AppDispatcher.dispatch(actionSelectProfile);
    AppDispatcher.dispatch(actionEnableInstagramDraft);
    AppDispatcher.dispatch(actionAddVideo);
    AppDispatcher.dispatch(actionUpdateInstaState);
    const draft = ComposerStore.default.getDraft('instagram');
    expect(draft.postDirectToInstagram).toBeFalsy();
  });
});
