{"size": 2453, "ext": "js", "max_stars_repo_path": "client/src/components/ChatroomList.test.js", "max_stars_repo_name": "HajoAhoMantila/chatr", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/components/ChatroomList.test.js", "max_issues_repo_name": "HajoAhoMantila/chatr", "max_issues_repo_issues_event_min_datetime": "2018-01-18T22:46:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-13T08:01:09.000Z", "max_forks_repo_path": "client/src/components/ChatroomList.test.js", "max_forks_repo_name": "HajoAhoMantila/chatr", "max_forks_repo_forks_event_min_datetime": "2018-02-21T09:10:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-21T09:10:40.000Z"}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 37.1666666667, "max_line_length": 90, "alphanum_fraction": 0.6750917244}
import { Set } from 'immutable';
import Adapter from 'enzyme-adapter-react-16/build/index';
import { configure, shallow, mount } from 'enzyme';
import React from 'react';
import ChatroomList from './ChatroomList';

configure({ adapter: new Adapter() });

describe('<ChatroomList />', () => {
  it('Renders the chat room list', () => {
    const wrapper = shallow(<ChatroomList
      currentRoom="Kitchen"
      roomNames={new Set(['LivingRoom', 'Kitchen', 'Bathroom'])}
      joinRoomCallback={jest.fn()}
    />);

    expect(wrapper.find('.roomname-selected')).toHaveLength(1);
    expect(wrapper.find('.roomname-selected').text()).toEqual('Kitchen');
    expect(wrapper.find('.roomname')).toHaveLength(2);
    expect(wrapper.find('.roomname').at(0).text()).toEqual('LivingRoom');
    expect(wrapper.find('.roomname').at(1).text()).toEqual('Bathroom');
  });

  it('Calls callback and clears input field when new chat room name is submitted', () => {
    const createAndJoinRoomCallback = jest.fn();
    const wrapper = mount(<ChatroomList
      currentRoom="LivingRoom"
      roomNames={new Set(['LivingRoom', 'Kitchen', 'Bathroom'])}
      joinRoomCallback={createAndJoinRoomCallback}
    />);

    const newRoomName = 'ShinyNewRoom';
    wrapper.find('#newchatroom-input-text').instance().value = newRoomName;
    wrapper.find('#newchatroom-input-text').simulate('submit');

    expect(wrapper.find('#newchatroom-input-text').instance().value).toEqual('');
    expect(createAndJoinRoomCallback).toBeCalledWith(newRoomName);
  });

  it('Does not call callback when empty room name is submitted', () => {
    const createAndJoinRoomCallback = jest.fn();
    const wrapper = mount(<ChatroomList
      currentRoom="LivingRoom"
      roomNames={new Set(['LivingRoom', 'Kitchen', 'Bathroom'])}
      joinRoomCallback={createAndJoinRoomCallback}
    />);

    wrapper.find('#newchatroom-input-text').instance().value = '';
    wrapper.find('#newchatroom-input-text').simulate('submit');

    expect(createAndJoinRoomCallback).not.toBeCalled();
  });

  it('Calls callback when room name is clicked', () => {
    const joinRoomCallback = jest.fn();
    const wrapper = mount(<ChatroomList
      currentRoom="LivingRoom"
      roomNames={new Set(['LivingRoom', 'Kitchen', 'Bathroom'])}
      joinRoomCallback={joinRoomCallback}
    />);

    wrapper.find('#room-Kitchen').simulate('click');
    expect(joinRoomCallback).toBeCalledWith('Kitchen');
  });
});
