<commit_before>describe("Tests for horizon-graph module", function() {
  var module, sandbox, contextFake, windowSvc;

  beforeEach(function() {
    sandbox = sinon.sandbox.create();
    windowSvc = {
      openRadiatorForHost: function(host) {},
      sendGraphToRadiator: function(host) {},
      openTerminalToHost: function(user, host) {},
      getHashVariable: function() {},
      variableStateInHash: function() {},
      setHash: function() {}
    };
    cubism = {
      context: function() { return this; },
      step: function() { return this; },
      size: function() { return this; },
      start: function() { return this; },
      on: function() { return this; },
      horizon: function() { return this; }
    };
    d3 = {
      json: function() { return this; },
      selectAll: function() { return this; },
      call: function() { return this; },
      select: function() { return this; },
      attr: function() { return this; },
      resize: function() { return this; },
      remove: function() { return this; }
    };
    jquery = {
      attr: function() {}
    };
    store = {
      readConfiguration: function(id) {
        return {
          metric: "cpu",
          host: "test-host",
          instanceTag: 'test-instance',
          stop: 10,
          step: 1
        }
      },
      storeConfiguration: function() {}
    };
    cubismGraphs = {
      createMetrics: function() {},
      resetCubismContext: function() {},
      onFocus: function() {},
      removeHorizonGraph: function() {}
    }
    contextFake = new Box.TestServiceProvider({
      'window': windowSvc,
      'cubism-graphs' : cubismGraphs,
      'configuration-store': store,
      'cubism': cubism,
      'd3': d3,
      'jQuery': jquery
    });
    contextFake.getConfig = sandbox.stub().returns({
      'chart': {
        'metric': 'cpu'
      }
    });
    module = Box.Application.getModuleForTest('horizon-graph', contextFake);
    module.init();
  });

  afterEach(function() {
    localStorage.clear();
    module.destroy();
    sandbox.verifyAndRestore();
  });

  it('Clicking an element with "start-terminal" type should open the shell window', function() {
    sandbox.mock(windowSvc).expects('openTerminalToHost').once().withExactArgs("@admin", "test");
    var target = $(' <svg data-type="start-terminal" data-host="test"></svg>')[0];
    var event = $.Event('click', {
      target: target
    });
    module.onclick(event, target, 'start-terminal');
  });

  it('Clicking an element with "to-radiator"" type should open the radiator window', function() {
    sandbox.mock(windowSvc).expects('sendGraphToRadiator').once().withExactArgs("newradiator", {
      metric: "cpu",
      host: "test-host",
      instanceTag: 'test-instance',
      stop: 10,
      step: 1<commit_msg>provide mock chart to test<commit_after>describe("Tests for horizon-graph module", function() {
  var module, sandbox, contextFake, windowSvc;

  beforeEach(function() {
    sandbox = sinon.sandbox.create();
    windowSvc = {
      openRadiatorForHost: function(host) {},
      sendGraphToRadiator: function(host) {},
      openTerminalToHost: function(user, host) {},
      getHashVariable: function() {},
      variableStateInHash: function() {},
      setHash: function() {}
    };
    cubism = {
      context: function() { return this; },
      step: function() { return this; },
      size: function() { return this; },
      start: function() { return this; },
      on: function() { return this; },
      horizon: function() { return this; }
    };
    d3 = {
      json: function() { return this; },
      selectAll: function() { return this; },
      call: function() { return this; },
      select: function() { return this; },
      attr: function() { return this; },
      resize: function() { return this; },
      remove: function() { return this; }
    };
    jquery = {
      attr: function() {}
    };
    mockChart = {
      metric: "cpu",
      host: "test-host",
      instanceTag: 'test-instance',
      stop: 10,
      step: 1
    };
    store = {
      readConfiguration: function() { return mockChart; },
      storeConfiguration: function() {}
    };
    cubismGraphs = {
      createMetrics: function() {},
      resetCubismContext: function() {},
      onFocus: function() {},
      removeHorizonGraph: function() {}
    };
    contextFake = new Box.TestServiceProvider({
      'window': windowSvc,
      'cubism-graphs' : cubismGraphs,
      'configuration-store': store,
      'cubism': cubism,
      'd3': d3,
      'jQuery': jquery
    });
    contextFake.getConfig = sandbox.stub().returns({ 'chart': mockChart });
    module = Box.Application.getModuleForTest('horizon-graph', contextFake);
    module.init();
  });

  afterEach(function() {
    localStorage.clear();
    module.destroy();
    sandbox.verifyAndRestore();
  });

  it('Clicking an element with "start-terminal" type should open the shell window', function() {
    sandbox.mock(windowSvc).expects('openTerminalToHost').once().withExactArgs("@admin", "test");
    var target = $(' <svg data-type="start-terminal" data-host="test"></svg>')[0];
    var event = $.Event('click', {
      target: target
    });
    module.onclick(event, target, 'start-terminal');
  });

  it('Clicking an element with "to-radiator"" type should open the radiator window', function() {
    sandbox.mock(windowSvc).expects('sendGraphToRadiator').once().withExactArgs("newradiator", {
      metric: "cpu",
      host: "test-host",
      instanceTag: 'test-instance',
      stop: 10,
      step: 1
{'fraction_non_alphanumeric': 0.1584140653031934, 'fraction_numerical': 0.003588087549336204, 'mean_word_length': 2.810663021189337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1117557', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1652, 'n_words': 378}