text: import reducer, {initialState, CallRecord} from './reducer';
  import {constructCallObject} from './helpers';
  import {
    ANSWERED_INCOMING_CALL,
    DISMISS_INCOMING_CALL,
    CHECKING_WEB_RTC_SUPPORT,
    CONNECT_CALL,
    REMOVE_CALL,
    STORE_CALL,
    UPDATE_CALL_STATUS,
    UPDATE_STATUS,
    UPDATE_WEBRTC_SUPPORT
  } from './actions';
  
  let call;
  
  describe('redux-module-media reducer', () => {
    beforeEach(() => {
      call = {
        hangup: jest.fn(() => Promise.resolve()),
        acknowledge: jest.fn(() => Promise.resolve()),
        reject: jest.fn(() => Promise.resolve()),
        answer: jest.fn(() => Promise.resolve()),
        once: jest.fn(),
        on: jest.fn((eventName, callback) => Promise.resolve({eventName, callback})),
        off: jest.fn(),
        locus: {
          url: 'https://locusUrl',
          fullState: {
            lastActive: 'Sun Feb 18 2018 18:21:05 GMT'
          }
        },
        direction: '',
        joined: '',
        joinedOnThisDevice: '',
        status: '',
        receivingAudio: '',
        sendingAudio: '',
        sendingVideo: '',
        remoteMediaStream: '',
        localMediaStream: '',
        remoteAudioMuted: '',
        remoteVideoMuted: '',
        remoteAudioStream: '',
        remoteVideoStream: ''
      };
    });
  
    it('should return an initial state', () => {
      expect(reducer(undefined, {}))
        .toMatchSnapshot();
    });
  
    it('should handle CHECKING_WEB_RTC_SUPPORT', () => {
      expect(reducer(initialState, {
        type: CHECKING_WEB_RTC_SUPPORT
      })).toMatchSnapshot();
    });
  
    it('should handle UPDATE_WEBRTC_SUPPORT', () => {
      expect(reducer(initialState, {
        type: UPDATE_WEBRTC_SUPPORT,
        payload: {
          supported: true
        }
      })).toMatchSnapshot();
    });
  
    it('should handle UPDATE_STATUS', () => {
      expect(reducer(initialState, {
        type: UPDATE_STATUS,
        payload: {
          status: {
            isListening: true
          }
        }
      })).toMatchSnapshot();
    });
  
    it('should handle STORE_CALL', () => {
      const url = 'http://abc-123.gov';
      expect(reducer(initialState, {
        type: STORE_CALL,
        payload: {
          call: {
            locus: {
              fullState: {
                lastActive: '2018-02-13T14:46:59.874Z'
              },
              url
            },
            mock: true
          },
          callState: {
            mockState: true
          },
          locusUrl: 'http://abc-123.gov'
        }
      })).toMatchSnapshot();
    });
  
    it('should handle UPDATE_CALL_STATUS', () => {
      const url = 'http://abc-123.gov';
      const callRecord = new CallRecord({id: url});
      const updatedState = initialState.setIn(['byId', url], callRecord);
      expect(reducer(updatedState, {
        type: UPDATE_CALL_STATUS,
        payload: {
          call: {
            isReceivingVideo: true,
            isReceivingAudio: true
          },
          id: url
        }
      })).toMatchSnapshot();
    });
  
    it('should handle CONNECT_CALL', () => {
      const url = 'http://abc-123.gov';
      const callRecord = new CallRecord({id: url});
      const updatedState = initialState.setIn(['byId', url], callRecord);
  
      expect(reducer(updatedState, {
        type: CONNECT_CALL,
        payload: {
          call: constructCallObject(call),
          id: url
        }
      })).toMatchSnapshot();
    });
  
    it('should handle REMOVE_CALL', () => {
      const url = 'http://abc-123.gov';
      const callRecord = new CallRecord({id: url});
      const updatedState = initialState.setIn(['byId', url], callRecord);
  
      expect(reducer(updatedState, {
        type: REMOVE_CALL,
        payload: {
          id: url
        }
      })).toMatchSnapshot();
    });
  
    it('should handle DISMISS_INCOMING_CALL', () => {
      const id = 'http://abc-123.gov';
      const callRecord = new CallRecord({id, isIncoming: true});
      const updatedState = initialState.setIn(['byId', id], callRecord);
  
      expect(reducer(updatedState, {
        type: DISMISS_INCOMING_CALL,
        payload: {
          callId: id
        }
      })).toMatchSnapshot();
    });
  
    it('should handle ANSWERED_INCOMING_CALL', () => {
      const id = 'http://abc-123.gov';
      const callRecord = new CallRecord({id, isIncoming: true});
      const updatedState = initialState.setIn(['byId', id], callRecord);
  
      expect(reducer(updatedState, {
        type: ANSWERED_INCOMING_CALL,
        payload: {
          callId: id
        }
      })).toMatchSnapshot();
    });
  });
  