<commit_before>define([
  'extensions/views/graph/graph',
  'extensions/collections/collection',
  'd3',
  'extensions/models/model'
],
function (Graph, Collection, d3, Model) {

  describe("Graph", function() {



    it("keeps a reference to d3 library", function() {
      spyOn(Graph.prototype, "prepareGraphArea");
      var view = new Graph({
        collection: {
          on: jasmine.createSpy()
        },
        model: new Model()
      });
      expect(view.d3).toBe(d3);
    });


    var style;
    function withGraphStyle(graphStyle) {
      style = $('<style type="text/css">figure.graph { margin: 0 } figure.graph svg {' + graphStyle + '}</style>').appendTo($('body'));
    }
    afterEach(function() {
      if (style) {
        style.remove();
        style = null;
      }
    });
      
    
    describe("initialize", function() {
      
      var collection, TestGraph, testComponent1, testComponent2;
      beforeEach(function() {
        collection = new Collection();
        testComponent1 = jasmine.createSpy();
        testComponent2 = jasmine.createSpy();
        TestGraph = Graph.extend({
          components: [
            {
              view: testComponent1,
              options: {
                foo: 'bar'
              }
            },
            {
              view: testComponent2,
              options: {
                foo: 'baz',
                a: 'c'
              }
            }
          ],
          getDefaultComponentOptions: function () {
            return {
              a: 'b'
            }
          }
        });
        spyOn(TestGraph.prototype, "render");
        spyOn(TestGraph.prototype, "prepareGraphArea");
      });
      
      it("re-renders when collection resets", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('reset');
        expect(graph.render).toHaveBeenCalled();
      });

      it("re-renders when collection syncs", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('sync');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("re-renders when item is added to collection", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('add');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("re-renders when items is removed from collection", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('remove');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("prepare graph area", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        expect(graph.prepareGraphArea).toHaveBeenCalled();
      });
      
      it("initialises components", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        expect(testComponent1).toHaveBeenCalledWith({
          a: 'b',    // default option
          foo: 'bar' // component option
        });
        expect(testComponent2).toHaveBeenCalledWith({
          a: 'c',    // overridden default option
          foo: 'baz' // component option
        });
        expect(graph.componentInstances[0] instanceof testComponent1).toBe(true);
        expect(graph.componentInstances[1] instanceof testComponent2).toBe(true);
      });
    });
    
    describe("prepareGraphArea", function() {
      
      var graph, el;
      beforeEach(function() {
        el = $('<div id="jasmine-playground"></div>').appendTo($('body'));
        
        var TestGraph = Graph.extend();
        graph = new TestGraph({
          el: el,
          collection: new Collection(),
          model: new Model()
        });
      });
      
      afterEach(function() {
        el.remove();
      });

      it("creates element to measure size of inner graph area", function () {
        expect(graph.el.find('.inner').length).toEqual(1);
      });

      it("creates empty SVG element", function () {
        var svg = graph.el.find('svg');
        expect(svg.length).toEqual(1);
      });
      
      it("creates wrapper element", function() {
        var wrapper = graph.el.find('svg g.wrapper');
        expect(wrapper.length).toEqual(1);
      });
    });

    describe("pxToValue", function () {
      var pxToValue = Graph.prototype.pxToValue;

      it("extracts number from valid CSS px values", function () {
        expect(pxToValue('1px')).toEqual(1);
        expect(pxToValue('1.0px')).toEqual(1);
        expect(pxToValue('0.5px')).toEqual(0.5);
        expect(pxToValue('100px')).toEqual(100);
      });

      it("returns null when it is not a valid CSS px value", function () {
        expect(pxToValue(100)).toEqual(null);
        expect(pxToValue(1)).toEqual(null);
        expect(pxToValue('1p')).toEqual(null);
        expect(pxToValue(null)).toEqual(null);
        expect(pxToValue(undefined)).toEqual(null);
        expect(pxToValue(true)).toEqual(null);
        expect(pxToValue(false)).toEqual(null);
      });
    });
    
    describe("resize", function () {<commit_msg>Tests for line labels config<commit_after>define([
  'extensions/views/graph/graph',
  'extensions/collections/collection',
  'd3',
  'extensions/models/model'
],
function (Graph, Collection, d3, Model) {

  describe("Graph", function() {



    it("keeps a reference to d3 library", function() {
      spyOn(Graph.prototype, "prepareGraphArea");
      var view = new Graph({
        collection: {
          on: jasmine.createSpy()
        },
        model: new Model()
      });
      expect(view.d3).toBe(d3);
    });


    var style;
    function withGraphStyle(graphStyle) {
      style = $('<style type="text/css">figure.graph { margin: 0 } figure.graph svg {' + graphStyle + '}</style>').appendTo($('body'));
    }
    afterEach(function() {
      if (style) {
        style.remove();
        style = null;
      }
    });
      
    
    describe("initialize", function() {
      
      var collection, TestGraph, testComponent1, testComponent2;
      beforeEach(function() {
        collection = new Collection();
        testComponent1 = jasmine.createSpy();
        testComponent2 = jasmine.createSpy();
        TestGraph = Graph.extend({
          components: [
            {
              view: testComponent1,
              options: {
                foo: 'bar'
              }
            },
            {
              view: testComponent2,
              options: {
                foo: 'baz',
                a: 'c'
              }
            }
          ],
          getDefaultComponentOptions: function () {
            return {
              a: 'b'
            }
          }
        });
        spyOn(TestGraph.prototype, "render");
        spyOn(TestGraph.prototype, "prepareGraphArea");
      });
      
      it("re-renders when collection resets", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('reset');
        expect(graph.render).toHaveBeenCalled();
      });

      it("re-renders when collection syncs", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('sync');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("re-renders when item is added to collection", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('add');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("re-renders when items is removed from collection", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        collection.trigger('remove');
        expect(graph.render).toHaveBeenCalled();
      });
      
      it("prepare graph area", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        expect(graph.prepareGraphArea).toHaveBeenCalled();
      });
      
      it("initialises components", function() {
        var graph = new TestGraph({
          collection: collection,
          model: new Model()
        });
        expect(testComponent1).toHaveBeenCalledWith({
          a: 'b',    // default option
          foo: 'bar' // component option
        });
        expect(testComponent2).toHaveBeenCalledWith({
          a: 'c',    // overridden default option
          foo: 'baz' // component option
        });
        expect(graph.componentInstances[0] instanceof testComponent1).toBe(true);
        expect(graph.componentInstances[1] instanceof testComponent2).toBe(true);
      });
    });
    
    describe("prepareGraphArea", function() {
      
      var graph, el, TestGraph;
      beforeEach(function() {
        el = $('<div id="jasmine-playground"></div>').appendTo($('body'));
        
        TestGraph = Graph.extend();
        graph = new TestGraph({
          el: el,
          collection: new Collection(),
          model: new Model()
        });
      });
      
      afterEach(function() {
        el.remove();
      });

      it("creates element to measure size of inner graph area", function () {
        expect(graph.el.find('.inner').length).toEqual(1);
      });

      it("creates empty SVG element", function () {
        var svg = graph.el.find('svg');
        expect(svg.length).toEqual(1);
      });
      
      it("creates wrapper element", function() {
        var wrapper = graph.el.find('svg g.wrapper');
        expect(wrapper.length).toEqual(1);
      });

      describe("when the models 'show-line-labels' attribute is not falsy", function (){
        it("creates a figure with the class graph", function (){
          expect(graph.el.find('figure.graph').length).toEqual(1);
          expect(graph.el.find('figure.graph.graph-with-labels').length).toEqual(0);
        });
      });
      describe("when the models 'show-line-labels' attribute is not falsy", function (){
        it("creates a figure with the class graph graph-with-labels", function (){
          model = new Model();
          model.set({'show-line-labels': true});
          graph = new TestGraph({
            el: el,
            collection: new Collection(),
            model: model
          });
          expect(graph.el.find('figure.graph.graph-with-labels').length).toEqual(1);
        });
      });
    });

    describe("pxToValue", function () {
      var pxToValue = Graph.prototype.pxToValue;

      it("extracts number from valid CSS px values", function () {
        expect(pxToValue('1px')).toEqual(1);
        expect(pxToValue('1.0px')).toEqual(1);
        expect(pxToValue('0.5px')).toEqual(0.5);
        expect(pxToValue('100px')).toEqual(100);
      });

      it("returns null when it is not a valid CSS px value", function () {
        expect(pxToValue(100)).toEqual(null);
        expect(pxToValue(1)).toEqual(null);
        expect(pxToValue('1p')).toEqual(null);
        expect(pxToValue(null)).toEqual(null);
        expect(pxToValue(undefined)).toEqual(null);
        expect(pxToValue(true)).toEqual(null);
        expect(pxToValue(false)).toEqual(null);
      });
    });
    
    describe("resize", function () {
{'fraction_non_alphanumeric': 0.14214805305947797, 'fraction_numerical': 0.007274283269148481, 'mean_word_length': 1.9599797365754812, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4885099', 'n_tokens_mistral': 3180, 'n_tokens_neox': 3185, 'n_words': 663}