From a856b15519b7039320bcc0cefc7e8f93ef910167 Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Thu, 24 Dec 2015 19:54:48 -0800 Subject: [PATCH] Discovered two bugs and created two unit test before start fixing the issue #186 --- src/component/table.js | 4 +++ src/component/test/table-server-side.spec.js | 29 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/component/table.js b/src/component/table.js index 504fbf3f..6b67422d 100644 --- a/src/component/table.js +++ b/src/component/table.js @@ -378,7 +378,10 @@ angular.module('ngTasty.component.table', [ $scope.params.page = $scope.init.filterBase; } } + $scope.url = buildUrl($scope.params, $scope.filters); + console.log('url : ' + updateFrom, $scope.url, $scope.params); + if ($scope.reload) { $scope.reload = function () { $scope.resourceCallback($scope.url, angular.copy($scope.params)) @@ -414,6 +417,7 @@ angular.module('ngTasty.component.table', [ } $scope.$watchCollection('params', function watchParams (newValue, oldValue){ if (newValue !== oldValue) { + console.log('params', newValue, oldValue) // Run update resuorce only if we are on // the second cycle or more of `params` if (paramsInitialCycle === false) { diff --git a/src/component/test/table-server-side.spec.js b/src/component/test/table-server-side.spec.js index e1a0b524..670f01be 100644 --- a/src/component/test/table-server-side.spec.js +++ b/src/component/test/table-server-side.spec.js @@ -916,5 +916,34 @@ describe('Component: table server side', function () { $scope.$digest(); expect(element.scope().params.page).toEqual(2); }); + + it('should not change the params object if changed filter values', function () { + $scope.filterBy = { + 'name': 'mill', + 'sf-location': '' + }; + $scope.$digest(); + }); + + it('should return paramsObj with filter value', function () { + $scope.filterBy = { + 'name': 'mill', + 'sf-location': '' + }; + $scope.$digest(); + $scope.reloadCallback(); + urlToCall = 'api.json?sort-by=name&sort-order=dsc&page=1&count=20&name=mill'; + $httpBackend.whenGET(urlToCall).respond(completeJSON); + $httpBackend.flush(); + $scope.$digest(); + expect($scope.paramsUrl).toEqual('sort-by=name&sort-order=dsc&page=1&count=20&name=mill'); + expect($scope.paramsObj.sortBy).toEqual('name'); + expect($scope.paramsObj.sortOrder).toEqual('dsc'); + expect($scope.paramsObj.page).toEqual(4); + expect($scope.paramsObj.count).toEqual(20); + expect($scope.paramsObj.thead).toEqual(true); + expect($scope.paramsObj.pagination).toEqual(true); + expect($scope.paramsObj.filters.name).toEqual('mill'); + }); }); }); \ No newline at end of file