<commit_before>import { BaseComponent, BaseController } from '../src/ascesis';

describe('Single component functionality', (done) => {

  let component;

  customElements.define('my-test-component', BaseComponent);

  before((done) => {
    customElements.whenDefined('my-test-component').then(() => {
      component = document.createElement('my-test-component');
      done();
    });
  });

  it('html function works correctly', () => {
    const fixture = `
      <div class="foo" data-test="bar">
        <div>
          <span>test</span>
        </div>
      </div>
      <div>
        test 2
      </div>
    `;
    component.html(fixture);
    assert.equal(component.innerHTML, fixture);
  });

  it('toggles debug class correctly', () => {
    component.toggleHighlight();
    assert.equal(component.classList.contains('component-highlighted'), true);
    component.toggleHighlight();
    assert.equal(component.classList.contains('component-highlighted'), false);
  });

  it('triggers events correctly', () => {
    let handler = chai.spy(() => {});
    component.addEventListener('test-event', handler);
    component.trigger('test-event');
    expect(handler).to.have.been.called.once;
  });

  it('passes event data correctly', () => {
    let data;
    let handler = chai.spy(({eventData}) => { data = eventData });
    component.addEventListener('test-event', handler);
    component.trigger('test-event', { foo: 'bar' });
    assert.deepEqual(data, { foo: 'bar' });
  });

});


describe('Complex functionality', (done) => {

  class RootController extends BaseController {}
  class ChildController extends BaseController {}
  class ComponentOne extends BaseComponent {}
  class ComponentTwo extends BaseComponent {}
  class ComponentThree extends BaseComponent {}

  customElements.define('root-controller', RootController);
  customElements.define('child-controller', ChildController);
  customElements.define('component-one', ComponentOne);
  customElements.define('component-two', ComponentTwo);
  customElements.define('component-three', ComponentThree);

  let container = document.createElement('div');

  before((done) => {
    let promises = [
      'root-controller',
      'child-controller',
      'component-one',
      'component-two',
      'component-three'
    ].map((component_name) => {
      return customElements.whenDefined(component_name);
    ));
    Promise.all(promises).then(done);
  });
<commit_msg>add more tests<commit_after>import { BaseComponent, BaseController } from '../src/ascesis';

describe('Single component functionality', (done) => {

  let component;

  customElements.define('my-test-component', BaseComponent);

  before((done) => {
    customElements.whenDefined('my-test-component').then(() => {
      component = document.createElement('my-test-component');
      done();
    });
  });

  it('html function works correctly', () => {
    const fixture = `
      <div class="foo" data-test="bar">
        <div>
          <span>test</span>
        </div>
      </div>
      <div>
        test 2
      </div>
    `;
    component.html(fixture);
    assert.equal(component.innerHTML, fixture);
  });

  it('toggles debug class correctly', () => {
    component.toggleHighlight();
    assert.equal(component.classList.contains('component-highlighted'), true);
    component.toggleHighlight();
    assert.equal(component.classList.contains('component-highlighted'), false);
  });

  it('triggers events correctly', () => {
    let handler = chai.spy(() => {});
    component.addEventListener('test-event', handler);
    component.trigger('test-event');
    expect(handler).to.have.been.called.once;
  });

  it('passes event data correctly', () => {
    let data;
    let handler = chai.spy(({eventData}) => { data = eventData });
    component.addEventListener('test-event', handler);
    component.trigger('test-event', { foo: 'bar' });
    assert.deepEqual(data, { foo: 'bar' });
  });

});


describe('Complex functionality', (done) => {

  class RootController extends BaseController {}
  class ChildController extends BaseController {}
  class ComponentOne extends BaseComponent {}
  class ComponentTwo extends BaseComponent {}
  class ComponentThree extends BaseComponent {}


  let components_map = {
    'root-controller': RootController,
    'child-controller': ChildController,
    'component-one': ComponentOne,
    'component-two': ComponentTwo,
    'component-three': ComponentThree,
  };

  Object.keys(components_map).forEach((component_name) => {
    customElements.define(component_name, components_map[component_name]);
  });

  let container = document.createElement('div');

  document.body.appendChild(container);

  container.innerHTML = `
    <root-controller>
      <component-one>
      </component-one>
      <component-one>
      </component-one>
      <child-controller>
        <component-two>
        </component-two>
        <component-three>
        </component-three>
      </child-controller>
    </root-controller>
  `;

  let components_elements = Object.keys(components_map)
                                  .reduce((acc, component_name) => {
    return Object.assign(acc, {
      [component_name]: container.querySelectorAll(component_name)
    });
  }, {});

  before((done) => {
    let promises = Object.keys(components_map).map((component_name) => {
      return customElements.whenDefined(component_name);
    });
    Promise.all(promises).then(() => {
      done();
    });
  });


  it('creates child components correctly', () => {
    let root_child_components = components_elements['root-controller'][0].childComponents;
    assert.equal(root_child_components.length, 3);
    assert.equal(root_child_components[0], components_elements['component-one'][0]);
    assert.equal(root_child_components[1], components_elements['component-one'][1]);
    assert.equal(root_child_components[2], components_elements['child-controller'][0]);
    let child_controller_child_components = components_elements['child-controller'][0].childComponents;
    assert.equal(child_controller_child_components.length, 2);
    assert.equal(child_controller_child_components[0], components_elements['component-two'][0]);
    assert.equal(child_controller_child_components[1], components_elements['component-three'][0]);
  });


{'fraction_non_alphanumeric': 0.1555661274976213, 'fraction_numerical': 0.002537266095781795, 'mean_word_length': 3.770801815431165, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3716492', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1741, 'n_words': 300}