<commit_before>import Map from '../../../../src/ol/Map.js';
import Control from '../../../../src/ol/control/Control.js';

describe('ol.control.Control', function() {
  let map, control;

  beforeEach(function() {
    map = new Map({
      target: document.createElement('div')
    });
    const element = document.createElement('div');
    control = new Control({element: element});
    control.setMap(map);
  });

  afterEach(function() {
    disposeMap(map);
    map = null;
    control = null;
  });

  describe('dispose', function() {
    it('removes the control element from its parent', function() {
      control.dispose();
      expect(control.element.parentNode).to.be(null);
    });
  });
});

describe('ol.control.Control\'s target', function() {
  describe('target as string or element', function() {
    it('transforms target from string to element', function() {
      const target = document.createElement('div');
      target.id = 'mycontrol';
      document.body.appendChild(target);
      const ctrl = new Control({target: 'mycontrol'});
      expect(ctrl.target_.id).to.equal('mycontrol');
      ctrl.dispose();
      target.parentNode.removeChild(target);
    });
    it('accepts element for target', function() {
      const target = document.createElement('div');
      target.id = 'mycontrol';
      document.body.appendChild(target);
      const ctrl = new Control({target: target});
      expect(ctrl.target_.id).to.equal('mycontrol');
      ctrl.dispose();
      target.parentNode.removeChild(target);
    });
    it('ignores non-existing target id', function() {
      const ctrl = new Control({target: 'doesnotexist'});
      expect(ctrl.target_).to.equal(null);
      ctrl.dispose();
    });
  });
});<commit_msg>Add regression test for event target on Control<commit_after>import Map from '../../../../src/ol/Map.js';
import Control from '../../../../src/ol/control/Control.js';

describe('ol.control.Control', function() {
  let map, control;

  beforeEach(function() {
    map = new Map({
      target: document.createElement('div')
    });
    const element = document.createElement('div');
    control = new Control({element: element});
    control.setMap(map);
  });

  afterEach(function() {
    disposeMap(map);
    map = null;
    control = null;
  });

  describe('dispose', function() {
    it('removes the control element from its parent', function() {
      control.dispose();
      expect(control.element.parentNode).to.be(null);
    });
  });
});

describe('ol.control.Control\'s target', function() {
  describe('target as string or element', function() {
    it('transforms target from string to element', function() {
      const target = document.createElement('div');
      target.id = 'mycontrol';
      document.body.appendChild(target);
      const ctrl = new Control({target: 'mycontrol'});
      expect(ctrl.target_.id).to.equal('mycontrol');
      ctrl.dispose();
      target.parentNode.removeChild(target);
    });
    it('accepts element for target', function() {
      const target = document.createElement('div');
      target.id = 'mycontrol';
      document.body.appendChild(target);
      const ctrl = new Control({target: target});
      expect(ctrl.target_.id).to.equal('mycontrol');
      ctrl.dispose();
      target.parentNode.removeChild(target);
    });
    it('ignores non-existing target id', function() {
      const ctrl = new Control({target: 'doesnotexist'});
      expect(ctrl.target_).to.equal(null);
      ctrl.dispose();
    });
  });
});

describe('ol.control.Control\'s event target', function() {
  it('is the Control when the Control uses the default target', function() {
    const ctrl = new Control({element: document.createElement('div')});
    ctrl.on('test-event', function(e) {
      expect(e.target).to.be(ctrl);
    });
    ctrl.dispatchEvent('test-event');
    ctrl.dispose();
  });
  it('is the Control when the Control has a custom target', function() {
    const ctrl = new Control({
      element: document.createElement('div'),
      target: document.createElement('div')
    });
    ctrl.on('test-event', function(e) {
      expect(e.target).to.be(ctrl);
    });
    ctrl.dispatchEvent('test-event');
    ctrl.dispose();
  });
});
{'fraction_non_alphanumeric': 0.17375886524822695, 'fraction_numerical': 0.0, 'mean_word_length': 3.226773226773227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1440680', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1207, 'n_words': 268}