From 234d4aaaa20375875f90b8ae6bd996b9d57e0472 Mon Sep 17 00:00:00 2001 From: Florian FERBACH Date: Fri, 29 Sep 2017 17:30:13 +0200 Subject: [PATCH] Update filters on view initialization --- .../Crud/list/ListLayoutController.js | 4 ++ .../Crud/list/ListLayoutControllerSpec.js | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/javascripts/ng-admin/Crud/list/ListLayoutController.js b/src/javascripts/ng-admin/Crud/list/ListLayoutController.js index 03886599..8edd3714 100644 --- a/src/javascripts/ng-admin/Crud/list/ListLayoutController.js +++ b/src/javascripts/ng-admin/Crud/list/ListLayoutController.js @@ -53,6 +53,10 @@ export default class ListLayoutController { $scope.selection = []; } + if(this.hasFilters){ + this.updateFilters(); + } + $scope.$on('$destroy', this.destroy.bind(this)); } diff --git a/src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js b/src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js index 0c55e1d5..b6e7b4a3 100644 --- a/src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js +++ b/src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js @@ -1,6 +1,42 @@ /*global describe,it,expect,beforeEach*/ +import ListLayoutController, {getCurrentSearchParam} from '../../../../ng-admin/Crud/list/ListLayoutController' + describe('ListLayoutController', function () { - var getCurrentSearchParam = require('../../../../ng-admin/Crud/list/ListLayoutController').getCurrentSearchParam; + describe('constructor', () => { + it('should update filters if initialized with any', () => { + spyOn(ListLayoutController.prototype, 'updateFilters'); + spyOn(ListLayoutController, 'getCurrentSearchParam') + .and.returnValue({}); + + const $scope = { + $watch: () => {}, + $on: () => {}, + }; + + const $location = { + path: () => '/my_entity', + search: () => '', + }; + + const view = { + getEntity: () => 'my_entity', + batchActions: () => [], + actions: () => [], + filters: () => [{ + my_column: 17, + pinned: () => true, + }], + }; + + const listLayoutController = new ListLayoutController( + $scope, null, null, $location, null, view, null + ); + + expect(ListLayoutController.prototype.updateFilters) + .toHaveBeenCalled(); + }); + }); + describe('getCurrentSearchParam', function () { it('should return search url parameter mapped by filter', function () {