<commit_before>/* eslint-env mocha */

import React from 'react';
import expect from 'expect';
import sinon from 'sinon';
import jsdom from 'mocha-jsdom';

import toggle from '../toggle';
import RefinementList from '../../../components/RefinementList';

describe('toggle()', () => {
  jsdom();

  var ReactDOM;
  var container;
  var widget;
  var results;
  var templateProps;
  var helper;

  beforeEach(() => {
    ReactDOM = {render: sinon.spy()};
    toggle.__Rewire__('ReactDOM', ReactDOM);

    container = document.createElement('div');
    templateProps = {
      transformData: undefined,
      templatesConfig: undefined,
      templates: require('../defaultTemplates'),
      useCustomCompileOptions: {header: false, input: false, footer: false}
    };
    widget = toggle({container, facetName: 'aFacetName', label: 'A label'});
    results = {
      hits: [],
      getFacetValues: sinon.stub().returns([{name: 'true', count: 2}, {name: 'false', count: 1}])
    };
    helper = {
      hasRefinements: sinon.stub().returns(false),
      addFacetRefinement: sinon.spy(),
      removeFacetRefinement: sinon.spy()
    };
  });

  it('configures hitsPerPage', () => {
    expect(widget.getConfiguration()).toEqual({facets: ['aFacetName']});
  });

  it('calls ReactDOM.render(<Toggle props />, container)', () => {
    widget.render({results, helper});

    var props = {
      cssClasses: {item: null, list: null},
      label: 'A label',
      templateProps,
      toggleRefinement: sinon.spy()
    };

    expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
    var a = <RefinementList {...props} />;
    a = a; // WIP
  });

  afterEach(() => {
    toggle.__ResetDependency__('ReactDOM');
  });
});
<commit_msg>test(toggle): first pass at testing toggle<commit_after>/* eslint-env mocha */

import React from 'react';
import expect from 'expect';
import sinon from 'sinon';
import jsdom from 'mocha-jsdom';

import toggle from '../toggle';
import RefinementList from '../../../components/RefinementList';

describe('toggle()', () => {
  jsdom();

  var ReactDOM;
  var container;
  var widget;
  var results;
  var templateProps;
  var helper;

  beforeEach(() => {
    ReactDOM = {render: sinon.spy()};
    toggle.__Rewire__('ReactDOM', ReactDOM);

    container = document.createElement('div');
    templateProps = {
      templatesConfig: undefined,
      templates: require('../defaultTemplates'),
      useCustomCompileOptions: {header: false, input: false, footer: false}
    };
    widget = toggle({container, facetName: 'aFacetName', label: 'A label'});
    results = {
      hits: [],
      getFacetValues: sinon.stub().returns([{name: 'true', count: 2}, {name: 'false', count: 1}])
    };
    helper = {
      hasRefinements: sinon.stub().returns(false),
      addFacetRefinement: sinon.spy(),
      removeFacetRefinement: sinon.spy()
    };
  });

  it('configures hitsPerPage', () => {
    expect(widget.getConfiguration()).toEqual({facets: ['aFacetName']});
  });

  it('calls ReactDOM.render(<Toggle props />, container)', () => {
    widget.render({results, helper});

    var props = {
      cssClasses: {item: null, list: null},
      label: 'A label',
      templateProps,
      toggleRefinement: sinon.spy()
    };
    props.transformData = ReactDOM.render.firstCall.args[0].props.transformData;
    props.toggleRefinement = ReactDOM.render.firstCall.args[0].props.toggleRefinement;

    expect(ReactDOM.render.calledOnce).toBe(true, 'ReactDOM.render called once');
    expect(ReactDOM.render.firstCall.args[0]).toEqual(<RefinementList {...props} />);
    expect(ReactDOM.render.firstCall.args[1]).toEqual(container);
  });

  afterEach(() => {
    toggle.__ResetDependency__('ReactDOM');
  });
});

{'fraction_non_alphanumeric': 0.17003725385843535, 'fraction_numerical': 0.0021287919105907396, 'mean_word_length': 3.556363636363636, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1354477', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1174, 'n_words': 251}