<commit_before>/**
 * test for table view
 */
describe("tableview", function() {

  describe("headerview", function() {
    var view;
    var model = new cdb.admin.CartoDBTableMetadata({
        name: 'test'
    });
    beforeEach(function() {
      view = new cdb.admin.HeaderView({
        el: $('<div>'),
        column: ['name', 'type'],
        table: model
      });
    });

    it('should render', function() {
      view.render();
      expect(view.$('label > a').html().trim()).toEqual('name');
      expect(view.$('p > a').html()).toEqual('type');
    });

    it("when click on column name a menu should be opened", function() {
      runs(function() {
        view.render();
        view.$('.coloptions').trigger('click');
      });
      //WTF i need to wait this time to click to be triggered? <- in fact it probably doesn't have anything to do with time, but with the way the Browser UI thread choose what's going to execute next
      waits(400);
      runs(function() {
        expect(cdb.admin.HeaderView.colOptions.$el.css('display')).toEqual('block');
      });
    });

    it("when click on column type a menu should be opened", function() {
      runs(function() {
        view.render();
        view.$('.coltype').trigger('click');
      });
      waits(800);
      runs(function() {
        expect(cdb.admin.HeaderView.colTypeOptions.$el.css('display')).toEqual('block');
      });
    });


    it("when click on column type, being in a SQL view should not open anything", function() {
      runs(function() {
        view.render();
        var sqlView = new cdb.admin.SQLViewData(null, { sql: 'select * from a' });
        model.useSQLView(sqlView);
        view.$('.coltype').trigger('click');
      });
      waits(800);
      runs(function() {
        expect(cdb.admin.HeaderView.colTypeOptions.$el.css('display')).toEqual('none');
      });
    });
  });

  describe('TableView', function() {
    var tview;
    var model;
    var globalErrorDummy;
    beforeEach(function() {
      this.server = sinon.fakeServer.create();

      globalErrorDummy = {
        "showError": function(a,b,c) {
          this.params = {
            "first": a,
            "second": b,
            "third": c
          }
          return true;
        }
      }

      model = new cdb.admin.CartoDBTableMetadata({
        name: 'test',
        schema: [
          ['id', 'integer'],
          ['col1', 'integer'],
          ['col2', 'integer'],
          ['col3', 'integer'],
          ['the_geom', 'geometry']
        ]
      });

      tview = new cdb.admin.TableView({
        el: $('<table>'),
        dataModel: model.data(),
        model: model,
        row_header: true,
        globalError: globalErrorDummy
      });
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom': null},
        {'id': 2, 'col1': 4, 'col2': 5, 'col3': 6, 'the_geom': null}
      ]);
    });

    it('should render a table', function() {
      model.set({
        columns: [['test', 'integer']]
      });
      tview.render();
      expect(tview.$('thead').length).toEqual(1);
    });

    it("should edit cell", function() {
      spyOn(tview, '_getEditor');
      tview.render();
      tview.getCell(0, 0).trigger('dblclick');
      expect(tview._getEditor).toHaveBeenCalled();
    });


    it("should show the point info when the_Geom is a point", function() {
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom':
          '{"type":"Point", "coordinates": [1,1]}'}
      ]);
      tview.render();

      expect(tview.$('td .cell').eq(5).html()).toEqual("1, 1");

    })

    it("should be able to add an empty row", function() {
      var prevSize = tview._models[0].table.data().length;
      tview.addEmptyRow();
      this.server.requests[0].respond(200,{ "Content-Type": "application/json" },"");
      expect(prevSize+1).toEqual(tview._models[0].table.data().length);
    })<commit_msg>tests updated & added<commit_after>/**
 * test for table view
 */
describe("tableview", function() {

  describe("headerview", function() {
    var view;
    var model = new cdb.admin.CartoDBTableMetadata({
        name: 'test'
    });
    beforeEach(function() {
      view = new cdb.admin.HeaderView({
        el: $('<div>'),
        column: ['name', 'type'],
        table: model
      });
    });

    it('should render', function() {
      view.render();
      expect(view.$('label > a').html().trim()).toEqual('name');
      expect(view.$('p > a').html()).toEqual('type');
    });

    it("when click on column name a menu should be opened", function() {
      runs(function() {
        view.render();
        view.$('.coloptions').trigger('click');
      });
      //WTF i need to wait this time to click to be triggered? <- in fact it probably doesn't have anything to do with time, but with the way the Browser UI thread choose what's going to execute next
      waits(400);
      runs(function() {
        expect(cdb.admin.HeaderView.colOptions.$el.css('display')).toEqual('block');
      });
    });

    it("when click on column type a menu should be opened", function() {
      runs(function() {
        view.render();
        view.$('.coltype').trigger('click');
      });
      waits(800);
      runs(function() {
        expect(cdb.admin.HeaderView.colTypeOptions.$el.css('display')).toEqual('block');
      });
    });


    it("when click on column type, being in a SQL view should not open anything", function() {
      runs(function() {
        view.render();
        var sqlView = new cdb.admin.SQLViewData(null, { sql: 'select * from a' });
        model.useSQLView(sqlView);
        view.$('.coltype').trigger('click');
      });
      waits(800);
      runs(function() {
        expect(cdb.admin.HeaderView.colTypeOptions.$el.css('display')).toEqual('none');
      });
    });
  });

  describe('TableView', function() {
    var tview;
    var model;
    var globalErrorDummy;
    beforeEach(function() {
      this.server = sinon.fakeServer.create();

      globalErrorDummy = {
        "showError": function(a,b,c) {
          this.params = {
            "first": a,
            "second": b,
            "third": c
          }
          return true;
        }
      }

      model = new cdb.admin.CartoDBTableMetadata({
        name: 'test',
        schema: [
          ['id', 'integer'],
          ['col1', 'integer'],
          ['col2', 'integer'],
          ['col3', 'integer'],
          ['the_geom', 'geometry']
        ]
      });

      tview = new cdb.admin.TableView({
        el: $('<table>'),
        dataModel: model.data(),
        model: model,
        row_header: true,
        globalError: globalErrorDummy
      });
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom': null},
        {'id': 2, 'col1': 4, 'col2': 5, 'col3': 6, 'the_geom': null}
      ]);
    });

    it('should render a table', function() {
      model.set({
        columns: [['test', 'integer']]
      });
      tview.render();
      expect(tview.$('thead').length).toEqual(1);
    });

    it("should edit cell", function() {
      spyOn(tview, '_getEditor');
      tview.render();
      tview.getCell(0, 0).trigger('dblclick');
      expect(tview._getEditor).toHaveBeenCalled();
    });


    it("should show the type when the_Geom is a point", function() {
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom':
          '{"type":"Point", "coordinates": [1,1]}'}
      ]);
      model.set('geometry_types', ["st_point"]);
      tview.render();

      expect(tview.$('td .cell').eq(5).html()).toEqual("point");

    })

    it("should show the type when the_Geom is a line", function() {
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom':
          '{"type":"Point", "coordinates": [[1,1],[2,3],[6,6]]}'}
      ]);
      model.set('geometry_types', ["st_linestring"]);
      tview.render();

      expect(tview.$('td .cell').eq(5).html()).toEqual("line");

    })

    it("should show 'geojson' on the_Geom is  cell when we don't know the geometry type yet", function() {
      model.data().reset([
        {'id': 1, 'col1': 1, 'col2': 2, 'col3': 3, 'the_geom':
          '{"type":"Point", "coordinates": [[1,1],[2,3],[6,6]]}'}
      ]);
      model.table.set('geometry_types', ["st_linestring"]);
      tview.render();

      expect(tview.$('td .cell').eq(5).html()).toEqual("GeoJSON");

    })

    it("should be able to add an empty row", function() {
      var prevSize = tview._models[0].table.data().length;
      tview.addEmptyRow();
      this.server.requests[0].respond(200,{ "Content-Type": "application/json" },"");
      expect(prevSize+1).toEqual(tview._models[0].table.data().length);
    })
{'fraction_non_alphanumeric': 0.19338335607094134, 'fraction_numerical': 0.01386994088221919, 'mean_word_length': 2.3589156166475753, 'pattern_counts': {'":': 18, '<': 9, '<?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': '930683', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2777, 'n_words': 616}