<commit_before>///<reference path="../testReference.ts" />

describe("Dispatchers", () => {
  describe("Dispatcher", () => {
    const TEST_EVENT_NAME = "test";

    it("connects and disconnects correctly", () => {
      const dispatcher = new Plottable.Dispatcher();

      let callbackCalled = false;
      (<any> dispatcher)._eventToCallback[TEST_EVENT_NAME] = () => callbackCalled = true;

      let d3document = d3.select(document);
      (<any> dispatcher)._connect();
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isTrue(callbackCalled, "connected correctly (callback was called)");

      (<any> dispatcher)._connect();
      callbackCalled = false;
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isTrue(callbackCalled, "can't double-connect (callback only called once)");

      (<any> dispatcher)._disconnect();
      callbackCalled = false;
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isFalse(callbackCalled, "disconnected correctly (callback not called)");
    });

    it("won't disconnect if it still has listeners", () => {
      const dispatcher = new Plottable.Dispatcher();
<commit_msg>[Dispatcher Tests] Add InstrumentedDispatcher mock class to tests<commit_after>///<reference path="../testReference.ts" />

describe("Dispatchers", () => {
  describe("Dispatcher", () => {
    class InstrumentedDispatcher extends Plottable.Dispatcher {
      public static EVENT_NAME = "instrumented";

      constructor() {
        super();
        this._eventToCallback[InstrumentedDispatcher.EVENT_NAME] = () => this._callCallbacksForEvent(InstrumentedDispatcher.EVENT_NAME);
      }

      public addCallback(callback: Function) {
        this._addCallbackForEvent(InstrumentedDispatcher.EVENT_NAME, callback);
      }

      public removeCallback(callback: Function) {
        this._removeCallbackForEvent(InstrumentedDispatcher.EVENT_NAME, callback);
      }
    }

    const TEST_EVENT_NAME = "test";

    it("connects and disconnects correctly", () => {
      const dispatcher = new Plottable.Dispatcher();

      let callbackCalled = false;
      (<any> dispatcher)._eventToCallback[TEST_EVENT_NAME] = () => callbackCalled = true;

      let d3document = d3.select(document);
      (<any> dispatcher)._connect();
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isTrue(callbackCalled, "connected correctly (callback was called)");

      (<any> dispatcher)._connect();
      callbackCalled = false;
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isTrue(callbackCalled, "can't double-connect (callback only called once)");

      (<any> dispatcher)._disconnect();
      callbackCalled = false;
      TestMethods.triggerFakeUIEvent(TEST_EVENT_NAME, d3document);
      assert.isFalse(callbackCalled, "disconnected correctly (callback not called)");
    });

    it("won't disconnect if it still has listeners", () => {
      const dispatcher = new Plottable.Dispatcher();

{'fraction_non_alphanumeric': 0.12397507379468678, 'fraction_numerical': 0.0032797638570022957, 'mean_word_length': 3.959349593495935, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 24, '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': '4314914', 'n_tokens_mistral': 860, 'n_tokens_neox': 830, 'n_words': 171}