<commit_before>
import * as React from "react"; // tslint:disable-line
const EventEmitter = require("events"); // tslint:disable-line
import { shallow } from "enzyme";

import Swatch from "../Swatch";

describe("Swatch", function() {
  it("should render the name of the swatch", () => {
    const SpiedChannel = new EventEmitter();

    const markup = shallow(
      <Swatch value="bar" name="foo" channel={SpiedChannel} />
    ).html();

    expect(markup.match(/foo/gmi).length).toBe(1);
  });

  it("should render the value of the swatch and set it to be the background", () => {
    const SpiedChannel = new EventEmitter();

    const markup = shallow(
      <Swatch value="bar" name="foo" channel={SpiedChannel} />
    ).html();

    expect(markup.match(/background:bar/gmi).length).toBe(1);
    expect(markup.match(/bar/gmi).length).toBe(2);
  });

});<commit_msg>added tests for swatch component<commit_after>
import * as React from "react"; // tslint:disable-line
const EventEmitter = require("events"); // tslint:disable-line
import { shallow } from "enzyme";
import Swatch from "../Swatch";
// import ReactTestUtils from "react-addons-test-utils";
const TestUtils = require("react-addons-test-utils");

describe("Swatch", function() {
  it("should exist", () => {
    const SpiedChannel = new EventEmitter();
    const swatch = shallow(<Swatch value="bar" name="foo" channel={SpiedChannel} />);

    expect(swatch).toBeDefined();
  });

  it("should render the name of the swatch", () => {
    const SpiedChannel = new EventEmitter();

    const markup = shallow(
      <Swatch value="bar" name="foo" channel={SpiedChannel} />
    ).html();

    expect(markup.match(/foo/gmi).length).toBe(1);
  });

  it("should render the value of the swatch and set it to be the background", () => {
    const SpiedChannel = new EventEmitter();

    const markup = shallow(
      <Swatch value="bar" name="foo" channel={SpiedChannel} />
    ).html();

    expect(markup.match(/background:bar/gmi).length).toBe(1);
    expect(markup.match(/bar/gmi).length).toBe(2);
  });

  it("should emit message on click", () => {
    const SpiedChannel = new EventEmitter();
    const swatch = TestUtils.renderIntoDocument(<Swatch value="#e6e6e6" name="Gray" channel={SpiedChannel} />);

    const spy = jest.fn();
    SpiedChannel.on('background', spy);

    TestUtils.Simulate.click(
      TestUtils.scryRenderedDOMComponentsWithTag(swatch, "div")[0]
    );

    expect(spy).toBeCalledWith("#e6e6e6");
  });
});
{'fraction_non_alphanumeric': 0.1686698717948718, 'fraction_numerical': 0.005208333333333333, 'mean_word_length': 3.9250493096646943, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '6634867', 'n_tokens_mistral': 797, 'n_tokens_neox': 778, 'n_words': 186}