<commit_before>import React from 'react';
import assert from 'assert';
import { mount, shallow } from 'enzyme';
import sinon from 'sinon';
import { CollectionCollaborators, RoleCreator, RoleRow } from './collaborators';

let resolveMock;

const asyncMock = () => {
  return new Promise(function (resolve) {
    resolveMock = resolve;
  });
};

const roleSet = {
  id: '1',
  get: asyncMock,
  roles: ['viewer'],
  links: {
    owner: { id: '1' }
  }
};

const roleSets = [
  roleSet,
  {
    id: '2',
    get: asyncMock,
    roles: ['contributor', 'collaborator'],
    links: {
      owner: { id: '2' }
    }
  }
];

const owner = {
  display_name: 'testUser',
  id: '3'
};

describe('<CollectionCollaborators />', function() {
  let wrapper;
  let addUserSpy;
  let deleteUserSpy;

  before(function() {
    addUserSpy = sinon.spy(RoleCreator.prototype, 'handleSubmit');
    deleteUserSpy = sinon.spy(RoleRow.prototype, 'confirmDelete');
    const stub = sinon.stub(CollectionCollaborators.prototype, 'componentDidMount');
    wrapper = mount(<CollectionCollaborators owner={owner}/>);
    wrapper.setState({ hasSettingsRole: true, roleSets });
    stub.restore();
  });

  it('should render without crashing', function() {
    assert.equal(wrapper, wrapper);
  });

  it('shows three settings options', function() {
    assert.equal(wrapper.find('dl').children().length, 3);
  });

  it('will show a button to remove each user', function() {
    const rowCount = wrapper.find('RoleRow').find('button').length;
    assert.equal(rowCount, 2);
  });

  it('will bold the font of an active role', function() {
    const firstRow = wrapper.find('RoleRow').first();
    assert.equal(firstRow.find('strong').last().text(), 'Viewer');
  });

  it('will allow three roles to be added to a user', function() {
    const creationRoleRows = wrapper.find('RoleCreator').find('dt').length;
    assert.equal(creationRoleRows, 3);
  });

  it('should call this.handleSubmit() when adding a user', function() {
    const addUserButton = wrapper.find('RoleCreator').find('button');
    addUserButton.simulate('click');
    sinon.assert.calledOnce(addUserSpy);
  });

  it('will call this.confirmDelete() when removing a user', function() {
    const removeUserButton = wrapper.find('RoleRow').first().find('button');
    removeUserButton.simulate('click');
    sinon.assert.calledOnce(deleteUserSpy);
  });
});
<commit_msg>Updated tests so they pass<commit_after>import React from 'react';
import assert from 'assert';
import { mount, shallow } from 'enzyme';
import sinon from 'sinon';
import { CollectionCollaborators, RoleCreator, RoleRow } from './collaborators';

let resolveMock;

const asyncMock = () => {
  return new Promise(function (resolve) {
    resolveMock = resolve;
  });
};

const getMetaMock = () => {
  return {
    count: 25,
    page: 1,
    page_count: 2
  };
};

const roleSet = {
  id: '1',
  get: asyncMock,
  getMeta: getMetaMock,
  roles: ['viewer'],
  links: {
    owner: { id: '1' }
  }
};

const roleSets = [
  roleSet,
  {
    id: '2',
    get: asyncMock,
    roles: ['contributor', 'collaborator'],
    links: {
      owner: { id: '2' }
    }
  }
];

const owner = {
  display_name: 'testUser',
  id: '3'
};

describe('<CollectionCollaborators />', function() {
  let wrapper;
  let addUserSpy;
  let deleteUserSpy;

  before(function() {
    addUserSpy = sinon.spy(RoleCreator.prototype, 'handleSubmit');
    deleteUserSpy = sinon.spy(RoleRow.prototype, 'confirmDelete');
    const stub = sinon.stub(CollectionCollaborators.prototype, 'componentDidMount');
    wrapper = mount(<CollectionCollaborators owner={owner} />, { context: { router: {} } });
    wrapper.setState({ hasSettingsRole: true, roleSets });
    stub.restore();
  });

  it('should render without crashing', function() {
    assert.equal(wrapper, wrapper);
  });

  it('shows three settings options', function() {
    assert.equal(wrapper.find('dl').children().length, 3);
  });

  it('will show a button to remove each user', function() {
    const rowCount = wrapper.find('RoleRow').find('button').length;
    assert.equal(rowCount, 2);
  });

  it('will bold the font of an active role', function() {
    const firstRow = wrapper.find('RoleRow').first();
    assert.equal(firstRow.find('strong').last().text(), 'Viewer');
  });

  it('will allow three roles to be added to a user', function() {
    const creationRoleRows = wrapper.find('RoleCreator').find('dt').length;
    assert.equal(creationRoleRows, 3);
  });

  it('should call this.handleSubmit() when adding a user', function() {
    const addUserButton = wrapper.find('RoleCreator').find('button');
    addUserButton.simulate('click');
    sinon.assert.calledOnce(addUserSpy);
  });

  it('will call this.confirmDelete() when removing a user', function() {
    const removeUserButton = wrapper.find('RoleRow').first().find('button');
    removeUserButton.simulate('click');
    sinon.assert.calledOnce(deleteUserSpy);
  });
});

{'fraction_non_alphanumeric': 0.16301507537688442, 'fraction_numerical': 0.004020100502512563, 'mean_word_length': 4.026262626262627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4894869', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1558, 'n_words': 369}