Skip to content

Commit eb8b125

Browse files
authored
Merge pull request #1366 from marmelab/fix-pinned-filter-initialization
[RFR] Update filters on view initialization
2 parents 3828607 + 234d4aa commit eb8b125

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/javascripts/ng-admin/Crud/list/ListLayoutController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export default class ListLayoutController {
5353
$scope.selection = [];
5454
}
5555

56+
if(this.hasFilters){
57+
this.updateFilters();
58+
}
59+
5660
$scope.$on('$destroy', this.destroy.bind(this));
5761
}
5862

src/javascripts/test/unit/Crud/list/ListLayoutControllerSpec.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
/*global describe,it,expect,beforeEach*/
2+
import ListLayoutController, {getCurrentSearchParam} from '../../../../ng-admin/Crud/list/ListLayoutController'
3+
24
describe('ListLayoutController', function () {
3-
var getCurrentSearchParam = require('../../../../ng-admin/Crud/list/ListLayoutController').getCurrentSearchParam;
5+
describe('constructor', () => {
6+
it('should update filters if initialized with any', () => {
7+
spyOn(ListLayoutController.prototype, 'updateFilters');
8+
spyOn(ListLayoutController, 'getCurrentSearchParam')
9+
.and.returnValue({});
10+
11+
const $scope = {
12+
$watch: () => {},
13+
$on: () => {},
14+
};
15+
16+
const $location = {
17+
path: () => '/my_entity',
18+
search: () => '',
19+
};
20+
21+
const view = {
22+
getEntity: () => 'my_entity',
23+
batchActions: () => [],
24+
actions: () => [],
25+
filters: () => [{
26+
my_column: 17,
27+
pinned: () => true,
28+
}],
29+
};
30+
31+
const listLayoutController = new ListLayoutController(
32+
$scope, null, null, $location, null, view, null
33+
);
34+
35+
expect(ListLayoutController.prototype.updateFilters)
36+
.toHaveBeenCalled();
37+
});
38+
});
39+
440

541
describe('getCurrentSearchParam', function () {
642
it('should return search url parameter mapped by filter', function () {

0 commit comments

Comments
 (0)