<commit_before>describe('reportDataController', function () {
  beforeEach(module('ManageIQ.report_data'));

  var $controller, $httpBackend, $scope;

  var report_data = getJSONFixture('report_data_response.json');

  var initObject = {
    modelName: 'manageiq%2Fproviders%2Finfra_manager%2Fvms',
    activeTree: 'vandt_tree',
    gtlType: 'grid',
    currId: '',
    sortColIdx: '0',
    sortDir: 'DESC',
    isExplorer: false,
    showUrl: 'some_url/show',
  }

  beforeEach(inject(function($injector) {
     $scope = $injector.get('$rootScope').$new();
     $httpBackend = $injector.get('$httpBackend');
     var injectedCtrl = $injector.get('$controller');
     $controller = injectedCtrl('reportDataController', {$scope: $scope});
   }));

  describe('receive data', function() {
    beforeEach(function() {
      $controller.MiQEndpointsService.rootPoint = '/mock_root';
      $httpBackend
        .whenGET("/mock_root/report_data?active_tree=vandt_tree&model=manageiq%252Fproviders%252Finfra_manager%252Fvms")
        .respond(report_data);
      $httpBackend
        .whenGET("/mock_root/report_data?active_tree=vandt_tree&model=manageiq%2Fproviders%2Finfra_manager%2Fvms")
        .respond(report_data);
    });

    it('Should set default values by init Object', function() {
      $controller.initObjects(initObject);
      expect($controller.gtlType).toBe(initObject.gtlType);
      expect($controller.settings.isLoading).toBeTruthy();
      expect(angular.equals($controller.initObject, initObject)).toBeTruthy();
    });


    it('should get data', function(done) {
      var settings = {isLoading: true};
      var result = $controller
          .getData(initObject.modelName, initObject.activeTree, initObject.currId, initObject.isExplorer, settings);
      result.then(function(data) {
        expect(angular.equals($controller.gtlData.cols, report_data.data.head)).toBeTruthy();
        expect(angular.equals($controller.gtlData.rows, report_data.data.rows)).toBeTruthy();
        expect(angular.equals($controller.settings, report_data.settings)).toBeTruthy();
        expect(angular.equals($controller.perPage.value, report_data.settings.perpage)).toBeTruthy();
        expect(angular.equals($controller.perPage.text, report_data.settings.perpage)).toBeTruthy();
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });

    it('should init controller', function(done) {
      var result = $controller.initController(initObject);
      result.then(function() {
        expect($controller.settings.isLoading).toBeFalsy();
        expect(report_data.settings.sort_dir === "ASC").toBe($controller.settings.sortBy.isAscending);
        expect($controller.settings.sortBy.sortObject.col_idx).toBe(report_data.settings.sort_col);
        expect($controller.perPage.enabled).toBeTruthy();
        expect($controller.perPage.hidden).toBeFalsy();
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });
  });

  describe('common functions', function() {
    beforeEach(function(done) {
      $controller.MiQEndpointsService.rootPoint = '/mock_root';
      $httpBackend
        .whenGET("/mock_root/report_data?active_tree=vandt_tree&model=manageiq%2Fproviders%2Finfra_manager%2Fvms")
        .respond(report_data);
      $httpBackend
        .whenGET("/mock_root/report_data?active_tree=vandt_tree&explorer=true&model=manageiq%2Fproviders%2Finfra_manager%2Fvms")
        .respond(report_data);
      $controller.initController(initObject).then(function() {
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });

    it('should set correct sort', function() {
      var indexOfItem = 4;
      var isAscending = true;
      $controller.setSort(indexOfItem, isAscending);
      expect(
        angular.equals($controller.settings.sortBy.sortObject, $controller.gtlData.cols[indexOfItem])
      ).toBeTruthy();
      expect($controller.settings.sortBy.isAscending).toBe(isAscending);
    });

    it('should call fetch of new items after changing sort', function() {
      var indexOfItem = 5;
      var isAscending = false;
      spyOn($controller, 'initController');
      $controller.onSort(indexOfItem, isAscending);
      expect(
        angular.equals($controller.settings.sortBy.sortObject, $controller.gtlData.cols[indexOfItem])<commit_msg>ReportDataController spec (js) - fix to check for POST to report_data<commit_after>describe('reportDataController', function () {
  beforeEach(module('ManageIQ.report_data'));

  var $controller, $httpBackend, $scope;

  var report_data = getJSONFixture('report_data_response.json');

  var initObject = {
    modelName: 'manageiq/providers/infra_manager/vms',
    activeTree: 'vandt_tree',
    gtlType: 'grid',
    currId: '',
    sortColIdx: '0',
    sortDir: 'DESC',
    isExplorer: false,
    showUrl: 'some_url/show',
  }

  beforeEach(inject(function($injector) {
     $scope = $injector.get('$rootScope').$new();
     $httpBackend = $injector.get('$httpBackend');
     var injectedCtrl = $injector.get('$controller');
     $controller = injectedCtrl('reportDataController', {$scope: $scope});
   }));

  describe('receive data', function() {
    beforeEach(function() {
      $controller.MiQEndpointsService.rootPoint = '/mock_root';
      $httpBackend
        .whenPOST('/mock_root/report_data', {
          active_tree: 'vandt_tree',
          model: 'manageiq/providers/infra_manager/vms',
        })
        .respond(report_data);
    });

    it('Should set default values by init Object', function() {
      $controller.initObjects(initObject);
      expect($controller.gtlType).toBe(initObject.gtlType);
      expect($controller.settings.isLoading).toBeTruthy();
      expect(angular.equals($controller.initObject, initObject)).toBeTruthy();
    });

    it('should get data', function(done) {
      var settings = {isLoading: true};
      var result = $controller
          .getData(initObject.modelName, initObject.activeTree, initObject.currId, initObject.isExplorer, settings);
      result.then(function(data) {
        expect(angular.equals($controller.gtlData.cols, report_data.data.head)).toBeTruthy();
        expect(angular.equals($controller.gtlData.rows, report_data.data.rows)).toBeTruthy();
        expect(angular.equals($controller.settings, report_data.settings)).toBeTruthy();
        expect(angular.equals($controller.perPage.value, report_data.settings.perpage)).toBeTruthy();
        expect(angular.equals($controller.perPage.text, report_data.settings.perpage)).toBeTruthy();
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });

    it('should init controller', function(done) {
      var result = $controller.initController(initObject);
      result.then(function() {
        expect($controller.settings.isLoading).toBeFalsy();
        expect(report_data.settings.sort_dir === "ASC").toBe($controller.settings.sortBy.isAscending);
        expect($controller.settings.sortBy.sortObject.col_idx).toBe(report_data.settings.sort_col);
        expect($controller.perPage.enabled).toBeTruthy();
        expect($controller.perPage.hidden).toBeFalsy();
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });
  });

  describe('common functions', function() {
    beforeEach(function(done) {
      $controller.MiQEndpointsService.rootPoint = '/mock_root';
      $httpBackend
        .whenPOST('/mock_root/report_data', {
          active_tree: 'vandt_tree',
          model: 'manageiq/providers/infra_manager/vms',
        })
        .respond(report_data);
      $controller.initController(initObject).then(function() {
        done();
      });
      $httpBackend.flush();
      $scope.$apply();
    });

    it('should set correct sort', function() {
      var indexOfItem = 4;
      var isAscending = true;
      $controller.setSort(indexOfItem, isAscending);
      expect(
        angular.equals($controller.settings.sortBy.sortObject, $controller.gtlData.cols[indexOfItem])
      ).toBeTruthy();
      expect($controller.settings.sortBy.isAscending).toBe(isAscending);
    });

    it('should call fetch of new items after changing sort', function() {
      var indexOfItem = 5;
      var isAscending = false;
      spyOn($controller, 'initController');
      $controller.onSort(indexOfItem, isAscending);
      expect(
        angular.equals($controller.settings.sortBy.sortObject, $controller.gtlData.cols[indexOfItem])
{'fraction_non_alphanumeric': 0.14525469802623803, 'fraction_numerical': 0.0031911121616830162, 'mean_word_length': 3.7115812917594653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2012301', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2529, 'n_words': 346}