// import React from 'react';
import {
  IStateProps,
  ICommentsSectionState,
  AllProps,
  CommentsSection,
  // mapDispatchToProps,
} from 'CommentSection';
// import { shallowWithIntl } from 'tests/utils/intl';
// import { setFeatures } from 'features';

describe('CommentSection', () => {
  const commentProps: IStateProps = {
    comments: [],
    users: [],
    threadId: '',
    // courseInfo: {
    //   courseCode: 'courseCode',
    //   courseNumber: 'courseNumber',
    //   termCode: 'termCode',
    //   title: '',
    //   subject: 'subject',
    //   termStart: '',
    //   totalEnrollment: '',
    //   enrollmentRatio: 0,
    //   registrationStatus: '',
    //   snapshots: [],
    //   sections: [],
    // },
  };

  const state: ICommentsSectionState = {
    users: [],
    comments: [],
    focused: false,
    newNotificaitonValue: '',
    userSearch: false,
  };

  let props;

  beforeAll(() => {
    props = { ...commentProps } as unknown as AllProps;
    props.setThreadId = jest.fn();
    props.createComment = jest.fn();
    props.fetchUsers = jest.fn();
    // setFeatures('COMMENTS', { USER_TAGGING: true, SEND_NOTIFICATIONS: true });
  });

  afterAll(() => {
    // setFeatures('COMMENTS', { USER_TAGGING: false, SEND_NOTIFICATIONS: false });
  });

  it('should render the component', () => {
    // const renderedEl = shallowWithIntl(<CommentsSection {...props} />);
    // expect(renderedEl).toBeDefined();
  });

  it('should create comment after hitting enter', () => {
    const firstEvent = {
      keyCode: 13, // enter
    };
    const comments = new CommentsSection(props);

    comments['checkEnter'](firstEvent);
    expect(props.createComment)
      .toHaveBeenCalledWith({
        comment_text: '',
        thread_id: 'courseCode_termCode',
        source_url: '/',
        thread_name: 'subject courseNumber',
      },
    );
  });

  it('should grab users after typing @', () => {
    const secondEvent = {
      target: {
        value: '@',
      },
    };
    const comments = new CommentsSection(props);
    comments.state = state;
    comments.setState = jest.fn();

    comments['updateComment'](secondEvent);
    expect(comments.setState)
      .toHaveBeenCalledWith({
        newNotificaitonValue: '@',
      },
    );
    expect(props.fetchUsers)
      .toHaveBeenCalled();
  });

  it('should update message value on change', () => {
    const firstEvent = {
      target: {
        value: 'something',
      },
    };
    const comments = new CommentsSection(props);
    comments.setState = jest.fn();

    comments['updateComment'](firstEvent);
    expect(comments.setState)
      .toHaveBeenCalledWith({
        newNotificaitonValue: 'something',
      },
    );

  });

  it('should handleBlur', () => {
    const comments = new CommentsSection(props);
    comments.setState = jest.fn();
    comments.handleBlur();

    expect(comments.setState).toBeCalledWith({ focused: false });
  });

  it('should scrollDown', () => {
    document.getElementById = jest.fn().mockReturnValue({ offsetTop: 1 });
    // shallowWithIntl(<div id="comment_section" />);
    const comments = new CommentsSection(props);
    comments.setState = jest.fn();
    comments.scrollDown();

    expect(comments.setState).toBeCalledWith({ focused: true });
  });

  it('should map dispatch actions to properties', () => {
    // const dispatch = jest.fn();

    // const dispatchProps = mapDispatchToProps(dispatch);

    // expect(dispatchProps.createComment).toBeDefined();
    // expect(dispatchProps.setThreadId).toBeDefined();
    // expect(dispatchProps.fetchUsers).toBeDefined();
    // expect(dispatchProps.fetchComments).toBeDefined();

    // dispatchProps.createComment({});
    // dispatchProps.setThreadId({});
    // dispatchProps.fetchUsers();
    // dispatchProps.fetchComments({ });

    // expect(dispatch).toHaveBeenCalledTimes(4);
  });
});
