<commit_before>describe('Component: table', function () {
  var $rootScope, $scope, $httpBackend, $compile, $controller;
  var element, controller, params, urlToCall, filters, createDirective, 
  field, elm, elementSelected, expected, completeJSON, sortingJSON, 
  paginationJSON, filtersJSON, tastyTable, tastyPagination, 
  tastyThead, paginationJSONCount25, tableCtrl;

  beforeEach(module('ngMock'));
  beforeEach(module('ngTasty.filter.cleanFieldName'));
  beforeEach(module('ngTasty.filter.range'));
  beforeEach(module('ngTasty.service.tastyUtil'));
  beforeEach(module('ngTasty.component.table'));
  beforeEach(module('mockedAPIResponse'));
  beforeEach(module('ngTasty.tpls.table.head'));
  beforeEach(module('ngTasty.tpls.table.pagination'));


  describe('configs', function () {
    beforeEach(inject(function ($rootScope, _$compile_) {
      $scope = $rootScope.$new();
      $compile = _$compile_;
    }));

    it('should return a throw message if the bind-resource is not set', function () {
      function errorFunctionWrapper() {
        element = angular.element('<div tasty-table></div>');
        $compile(element)($scope);
        $scope.$digest();
      }
      expected = 'AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute';
      expect(errorFunctionWrapper).toThrow(expected);
    });

    it('should return a throw message if the bind-resource set is undefined', function () {
      function errorFunctionWrapper() {
        element = angular.element('<div tasty-table bind-resource="getResource"></div>');
        $compile(element)($scope);
        $scope.$digest();
      }
      expected = 'AngularJS tastyTable directive: the bind-resource (getResource) is not an object';
      expect(errorFunctionWrapper).toThrow(expected);
    });
  });

  
  describe('bad bind-resource implementation', function () {
    beforeEach(inject(function ($rootScope, $compile) {
      $scope = $rootScope.$new();
      $scope.resource = {
        'header': [],
        'rows': [],
        'sortBy': 'name',
        'sortOrder': 'asc'
      };
      element = angular.element(''+
      '<div tasty-table bind-resource="resource" bind-filters="filters">'+
      '  <table>'+
      '    <thead tasty-thead></thead>'+
      '    <tbody>'+
      '    </tbody>'+
      '  </table>'+
      '  <div tasty-pagination></div>'+
      '</div>');
      $compile(element)($scope);
    }));

    it('should render the table without no errors', function () {
      $scope.$digest();
    });
  });


  describe('withs sorting', function () {

    beforeEach(inject(function ($rootScope, $compile, _sortingJSON_) {
      $scope = $rootScope.$new();
      $scope.resource = angular.copy(_sortingJSON_);
      $scope.resource.something = [
        { 'name': 'Ritual Coffee Roasters' }
      ];
      element = angular.element(''+
      '<table tasty-table bind-resource="resource" watch-resource="collection" '+
      '  bind-theme="theme">'+
      '  <thead tasty-thead></thead>'+
      '  <tbody>'+
      '    <tr ng-repeat="row in rows">'+
      '      <td>{{ row.name }}</td>'+
      '      <td>{{ row.star }}</td>'+
      '      <td>{{ row[\'sf-Location\'] }}</td>'+
      '    </tr>'+
      '  </tbody>'+
      '</table>');
      tastyTable = $compile(element)($scope);
      tastyThead = tastyTable.find('[tasty-thead=""]');
      $scope.$digest();
    }));

    it('should have these element.scope() value as default', function () {
      expect(element.scope().query).toEqual({
        'page': 'page',
        'count': 'count',
        'sortBy': 'sort-by',
        'sortOrder': 'sort-order',
      });
      expect(element.scope().url).toEqual('');
      expect(element.scope().header.columns[0]).toEqual({ 
        'key' : 'name', 
        'name' : 'Name',
        'style' : { 'width' : '50%' },
        'class': []
      });
      expect(element.scope().header.columns[1]).toEqual({ 
        'key' : 'star', 
        'name' : 'Star',
        'style' : { 'width' : '20%' },
        'class': [ 'text-right' ]
      });
      expect(element.scope().header.columns[2].key).toEqual('sf-Location');
      expect(element.scope().header.columns[2].name).toEqual('SF Location');
      expect(element.scope().header.columns[2].style).toEqual({ 'width' : '30%' });
      expect(element.scope().header.columns[2].class).toEqual([]);
      expect(element.scope().header.columns.length).toEqual(3);
      expect(element.scope().rows.length).toEqual(34);
      expect(element.scope().pagination.count).toEqual(5);
      expect(element.scope().pagination.page).toEqual(1);
      expect(element.scope().pagination.pages).toEqual(1);
      expect(element.scope().pagination.size).toEqual(0);
      expect(element.scope().params.sortBy).toEqual('name');
      expect(element.scope().params.sortOrder).toEqual('asc');
      expect(element.scope().params.page).toEqual(1);
      expect(element.scope().params.count).toEqual(undefined);
      expect(element.scope().params.thead).toEqual(true);
      expect(element.scope().theadDirective).toEqual(true);
      expect(element.scope().paginationDirective).toEqual(false);   
    });

    it('should return the right url after called buildUrl', function () {
      expect(element.scope().rows[0].name).toEqual('Andytown Coffee Roasters');
      expect(element.scope().rows.length).toEqual(34);
    });

    it('should have these isolateScope value as default', function () {
      expect(tastyThead.isolateScope().columns[0].active).toEqual(true);
      expect(tastyThead.isolateScope().columns[0].sortable).toEqual(true);
      expect(tastyThead.isolateScope().columns[0].style).toEqual({ width : '50%' });
      expect(tastyThead.isolateScope().columns[1].active).toEqual(false);
      expect(tastyThead.isolateScope().columns[1].sortable).toEqual(true);
      expect(tastyThead.isolateScope().columns[1].style).toEqual({ width : '20%' });
      expect(tastyThead.isolateScope().columns[2].active).toEqual(false);
      expect(tastyThead.isolateScope().columns[2].sortable).toEqual(true);
      expect(tastyThead.isolateScope().columns[2].style).toEqual( { width : '30%' });
    });

    it('should set params.sortBy when scope.sortBy is clicked', function () {
      field = {'key': 'name', 'name': 'Name', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(element.scope().params.sortBy).toEqual('name');
      expect($scope.resource.sortBy).toEqual('name');
      expect(tastyThead.isolateScope().columns[0].active).toEqual(true);
      field = {'key': 'star', 'name': 'Star', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(element.scope().params.sortBy).toEqual('star');
      expect($scope.resource.sortBy).toEqual('star');
      expect(tastyThead.isolateScope().columns[1].active).toEqual(true);
    });

    it('should sorting ascending and descending scope.header.sortBy when scope.sortBy is clicked', function () {
      field = {'key': 'star', 'name': 'star', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(tastyThead.isolateScope().header.sortBy).toEqual('star');
      expect(element.scope().rows[0].name).toEqual('Peet\'s');<commit_msg>Added test for #193<commit_after>describe('Component: table', function () {
  var $rootScope, $scope, $httpBackend, $compile, $controller;
  var element, controller, params, urlToCall, filters, createDirective, 
  field, elm, elementSelected, expected, completeJSON, sortingJSON, 
  paginationJSON, filtersJSON, tastyTable, tastyPagination, 
  tastyThead, paginationJSONCount25, tableCtrl;

  beforeEach(module('ngMock'));
  beforeEach(module('ngTasty.filter.cleanFieldName'));
  beforeEach(module('ngTasty.filter.range'));
  beforeEach(module('ngTasty.service.tastyUtil'));
  beforeEach(module('ngTasty.component.table'));
  beforeEach(module('mockedAPIResponse'));
  beforeEach(module('ngTasty.tpls.table.head'));
  beforeEach(module('ngTasty.tpls.table.pagination'));


  describe('configs', function () {
    beforeEach(inject(function ($rootScope, _$compile_) {
      $scope = $rootScope.$new();
      $compile = _$compile_;
    }));

    it('should return a throw message if the bind-resource is not set', function () {
      function errorFunctionWrapper() {
        element = angular.element('<div tasty-table></div>');
        $compile(element)($scope);
        $scope.$digest();
      }
      expected = 'AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute';
      expect(errorFunctionWrapper).toThrow(expected);
    });

    it('should return a throw message if the bind-resource set is undefined', function () {
      function errorFunctionWrapper() {
        element = angular.element('<div tasty-table bind-resource="getResource"></div>');
        $compile(element)($scope);
        $scope.$digest();
      }
      expected = 'AngularJS tastyTable directive: the bind-resource (getResource) is not an object';
      expect(errorFunctionWrapper).toThrow(expected);
    });
  });

  
  describe('bad bind-resource implementation', function () {
    beforeEach(inject(function ($rootScope, $compile) {
      $scope = $rootScope.$new();
      $scope.resource = {
        'header': [],
        'rows': [],
        'sortBy': 'name',
        'sortOrder': 'asc'
      };
      element = angular.element(''+
      '<div tasty-table bind-resource="resource" bind-filters="filters">'+
      '  <table>'+
      '    <thead tasty-thead></thead>'+
      '    <tbody>'+
      '    </tbody>'+
      '  </table>'+
      '  <div tasty-pagination></div>'+
      '</div>');
      $compile(element)($scope);
    }));

    it('should render the table without no errors', function () {
      $scope.$digest();
    });
  });


  describe('withs sorting', function () {

    beforeEach(inject(function ($rootScope, $compile, _sortingJSON_) {
      $scope = $rootScope.$new();
      $scope.resource = angular.copy(_sortingJSON_);
      $scope.resource.header[2].sortable = false; 
      $scope.resource.something = [
        { 'name': 'Ritual Coffee Roasters' }
      ];
      element = angular.element(''+
      '<table tasty-table bind-resource="resource" watch-resource="collection" '+
      '  bind-theme="theme">'+
      '  <thead tasty-thead></thead>'+
      '  <tbody>'+
      '    <tr ng-repeat="row in rows">'+
      '      <td>{{ row.name }}</td>'+
      '      <td>{{ row.star }}</td>'+
      '      <td>{{ row[\'sf-Location\'] }}</td>'+
      '    </tr>'+
      '  </tbody>'+
      '</table>');
      tastyTable = $compile(element)($scope);
      tastyThead = tastyTable.find('[tasty-thead=""]');
      $scope.$digest();
    }));

    it('should have these element.scope() value as default', function () {
      expect(element.scope().query).toEqual({
        'page': 'page',
        'count': 'count',
        'sortBy': 'sort-by',
        'sortOrder': 'sort-order',
      });
      expect(element.scope().url).toEqual('');
      expect(element.scope().header.columns[0]).toEqual({ 
        'key' : 'name', 
        'name' : 'Name',
        'style' : { 'width' : '50%' },
        'class': []
      });
      expect(element.scope().header.columns[1]).toEqual({ 
        'key' : 'star', 
        'name' : 'Star',
        'style' : { 'width' : '20%' },
        'class': [ 'text-right' ]
      });
      expect(element.scope().header.columns[2].key).toEqual('sf-Location');
      expect(element.scope().header.columns[2].name).toEqual('SF Location');
      expect(element.scope().header.columns[2].style).toEqual({ 'width' : '30%' });
      expect(element.scope().header.columns[2].class).toEqual([]);
      expect(element.scope().header.columns.length).toEqual(3);
      expect(element.scope().rows.length).toEqual(34);
      expect(element.scope().pagination.count).toEqual(5);
      expect(element.scope().pagination.page).toEqual(1);
      expect(element.scope().pagination.pages).toEqual(1);
      expect(element.scope().pagination.size).toEqual(0);
      expect(element.scope().params.sortBy).toEqual('name');
      expect(element.scope().params.sortOrder).toEqual('asc');
      expect(element.scope().params.page).toEqual(1);
      expect(element.scope().params.count).toEqual(undefined);
      expect(element.scope().params.thead).toEqual(true);
      expect(element.scope().theadDirective).toEqual(true);
      expect(element.scope().paginationDirective).toEqual(false);   
    });

    it('should return the right url after called buildUrl', function () {
      expect(element.scope().rows[0].name).toEqual('Andytown Coffee Roasters');
      expect(element.scope().rows.length).toEqual(34);
    });

    it('should have these isolateScope value as default', function () {
      expect(tastyThead.isolateScope().columns[0].active).toEqual(true);
      expect(tastyThead.isolateScope().columns[0].sortable).toEqual(true);
      expect(tastyThead.isolateScope().columns[0].style).toEqual({ width : '50%' });
      expect(tastyThead.isolateScope().columns[1].active).toEqual(false);
      expect(tastyThead.isolateScope().columns[1].sortable).toEqual(true);
      expect(tastyThead.isolateScope().columns[1].style).toEqual({ width : '20%' });
      expect(tastyThead.isolateScope().columns[2].active).toEqual(false);
      expect(tastyThead.isolateScope().columns[2].sortable).toEqual(false);
      expect(tastyThead.isolateScope().columns[2].style).toEqual( { width : '30%' });
    });

    it('should set params.sortBy when scope.sortBy is clicked', function () {
      field = {'key': 'name', 'name': 'Name', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(element.scope().params.sortBy).toEqual('name');
      expect($scope.resource.sortBy).toEqual('name');
      expect(tastyThead.isolateScope().columns[0].active).toEqual(true);
      field = {'key': 'star', 'name': 'Star', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(element.scope().params.sortBy).toEqual('star');
      expect($scope.resource.sortBy).toEqual('star');
      expect(tastyThead.isolateScope().columns[1].active).toEqual(true);
    });

    it('should set the sortable property when declared', function () {
      expect(element.scope().header.columns[0].sortable).toEqual(undefined);
      expect(element.scope().header.columns[1].sortable).toEqual(undefined);
      expect(element.scope().header.columns[2].sortable).toEqual(false);
    });

    it('should sorting ascending and descending scope.header.sortBy when scope.sortBy is clicked', function () {
      field = {'key': 'star', 'name': 'star', 'sortable': true};
      tastyThead.isolateScope().sortBy(field);
      $scope.$digest();
      expect(tastyThead.isolateScope().header.sortBy).toEqual('star');
      expect(element.scope().rows[0].name).toEqual('Peet\'s');
{'fraction_non_alphanumeric': 0.18776357185889284, 'fraction_numerical': 0.006225316286230672, 'mean_word_length': 3.4398216939078754, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, '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': '3930423', 'n_tokens_mistral': 4563, 'n_tokens_neox': 4519, 'n_words': 701}