Skip to content

Commit

Permalink
Discovered two bugs and created two unit test before start fixing the…
Browse files Browse the repository at this point in the history
… issue #186
  • Loading branch information
Zizzamia committed Dec 25, 2015
1 parent 2cdd16d commit a856b15
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/component/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions src/component/test/table-server-side.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit a856b15

Please sign in to comment.