"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _immutable = require("immutable");

var _peopleList = _interopRequireDefault(require("../peopleList"));

var _constants = require("@instructure/quiz-common/lib/constants");

describe('PeopleList', function () {
  var onPermissionChange = sinon.stub();
  var onPersonRemove = sinon.stub();
  var props = {
    onPermissionChange: onPermissionChange,
    onPersonRemove: onPersonRemove,
    peopleToRemove: [],
    people: (0, _immutable.List)([(0, _immutable.Map)({
      id: '0',
      userUuid: '0',
      fullName: 'first fullName',
      avatar: 'http://avatars.com/avatar1',
      permission: 'canEdit'
    }), (0, _immutable.Map)({
      id: '1',
      userUuid: '1',
      fullName: 'second fullName',
      avatar: 'http://avatars.com/avatar2',
      permission: 'readOnly'
    })])
  };
  var testbed = createTestbed(_peopleList.default, props);
  afterEach(function () {
    onPermissionChange.resetHistory();
    onPersonRemove.resetHistory();
  });
  shouldRenderComponent(testbed, {}, _peopleList.default);
  it('should render Avatars for each person', function () {
    var shallowTestbed = testbed.renderShallowly();
    var avatars = shallowTestbed.find('Avatar');
    expect(avatars.length).to.equal(2);
    expect(avatars.at(0).props().src).to.equal(props.people.get(0).get('avatar'));
    expect(avatars.at(1).props().src).to.equal(props.people.get(1).get('avatar'));
    expect(avatars.at(0).props().name).to.equal(props.people.get(0).get('fullName'));
    expect(avatars.at(1).props().name).to.equal(props.people.get(1).get('fullName'));
  });
  it('should render the remove buttons', function () {
    var shallowTestbed = testbed.renderShallowly();
    var buttons = shallowTestbed.find('Button');
    expect(buttons.length).to.equal(2);
    expect(typeof buttons.at(0).props().onClick).to.equal('function');
    expect(typeof buttons.at(1).props().onClick).to.equal('function');
  });
  it('should NOT render the remove button when theres only one person', function () {
    var shallowTestbed = testbed.renderShallowly({
      people: (0, _immutable.List)([(0, _immutable.Map)({
        userUuid: '0',
        fullName: 'first fullName',
        avatar: 'http://avatars.com/avatar1',
        permission: _constants.CAN_EDIT
      })])
    });
    var buttons = shallowTestbed.find('Button');
    expect(buttons.length).to.equal(0);
  }); // re-enable this test once we're using the select for permissions

  xit('should render Selects for each person', function () {
    var shallowTestbed = testbed.renderShallowly();
    var selects = shallowTestbed.find('Select');
    expect(selects.length).to.equal(2);
    expect(selects.at(0).props().value).to.equal(props.people.get(0).get('permission'));
    expect(selects.at(1).props().value).to.equal(props.people.get(1).get('permission'));
  });
  it('should allow to remove people', function () {
    var shallowTestbed = testbed.renderShallowly();
    var removeButton = shallowTestbed.find('Button').at(0);
    removeButton.simulate('click');
    expect(onPersonRemove.firstCall.args).to.be.eql([props.people.get(0).get('id'), false]);
  });
  it('should have different SR text for remove button if already removed', function () {
    var shallowTestbed = testbed.renderShallowly({
      peopleToRemove: ['0']
    });
    var buttons = shallowTestbed.find('Button');
    var buttonTexts = [buttons.at(0).prop('children').props.children, buttons.at(1).prop('children').props.children];
    expect(buttonTexts).to.deep.equal(['Undo remove for first fullName', 'Remove second fullName']);
  });
});