<commit_before>/* Copyright (C) 2017 Canonical Ltd. */
'use strict';

const Clipboard = require('clipboard');
const React = require('react');
const ReactDOM = require('react-dom');

const CopyToClipboard = require('./copy-to-clipboard');
const SvgIcon = require('../svg-icon/svg-icon');

const jsTestUtils = require('../../utils/component-test-utils');
const testUtils = require('react-dom/test-utils');

describe('CopyToClipboard', function() {
  it('renders with a default value', function() {
    var output = jsTestUtils.shallowRender(
      <CopyToClipboard />);
    var className = output.props.className;
    var expected = (
      <div className={className}>
        <input className={className + '__input'}
          readOnly="true"
          ref="input"
          type="text"
          value="" />
        <button className={className + '__btn'}
          ref="btn">
          <SvgIcon
            name="copy-to-clipboard-16"
            size="16" />
        </button>
      </div>
    );
    expect(output).toEqualJSX(expected);
  });

  it('renders a user-provided value properly', function() {
    var value = 'foobar';
    var output = testUtils.renderIntoDocument(
      <CopyToClipboard value={value} />);
    assert.equal(output.refs.input.value, value,
      'Value is not set properly for input');
  });

  // XXX: can't stub out internal methods.
  xit('initializes the Clipboard widget', function() {
    var component = testUtils.renderIntoDocument(
      <CopyToClipboard />);
    var node = ReactDOM.findDOMNode(component).querySelector('button');
    assert.deepEqual(Clipboard.getCall(0).args[0], node,
      'Clipboard was not initialized with expected node');
  });
});<commit_msg>Update copy to clipboard tests to use enzyme.<commit_after>/* Copyright (C) 2017 Canonical Ltd. */
'use strict';

const Clipboard = require('clipboard');
const React = require('react');
const ReactDOM = require('react-dom');
const enzyme = require('enzyme');

const CopyToClipboard = require('./copy-to-clipboard');
const SvgIcon = require('../svg-icon/svg-icon');

const testUtils = require('react-dom/test-utils');

describe('CopyToClipboard', function() {

  const renderComponent = (options = {}) => {
    return enzyme.shallow(
      <CopyToClipboard
        className={options.className}
        value={options.value} />,
      // Don't call componentDidMount as it requires nodes that don't exist in
      // the shallow renderer.
      { disableLifecycleMethods: true });
  };

  it('renders with a default value', function() {
    const wrapper = renderComponent();
    var expected = (
      <div className="copy-to-clipboard">
        <input className="copy-to-clipboard__input"
          readOnly="true"
          ref="input"
          type="text"
          value="" />
        <button className="copy-to-clipboard__btn"
          ref="btn">
          <SvgIcon
            name="copy-to-clipboard-16"
            size="16" />
        </button>
      </div>
    );
    assert.compareJSX(wrapper, expected);
  });

  it('can render with a provided className', function() {
    const wrapper = renderComponent({ className: 'class-name' });
    assert.equal(wrapper.prop('className'), 'class-name');
    assert.equal(wrapper.find('input').prop('className'), 'class-name__input');
    assert.equal(wrapper.find('button').prop('className'), 'class-name__btn');
  });

  it('renders a user-provided value properly', function() {
    var value = 'foobar';
    const wrapper = renderComponent({ value });
    assert.equal(wrapper.find('input').prop('value'), value,
      'Value is not set properly for input');
  });

  // XXX: can't stub out internal methods.
  xit('initializes the Clipboard widget', function() {
    var component = testUtils.renderIntoDocument(
      <CopyToClipboard />);
    var node = ReactDOM.findDOMNode(component).querySelector('button');
    assert.deepEqual(Clipboard.getCall(0).args[0], node,
      'Clipboard was not initialized with expected node');
  });
});
{'fraction_non_alphanumeric': 0.1520979020979021, 'fraction_numerical': 0.004995004995004995, 'mean_word_length': 3.19811320754717, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, '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': '2147339', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1130, 'n_words': 273}