$applyAsync() with relocate() on catalog. Replaced $$postDigest() #1072
This commit is contained in:
parent
8fa7abe191
commit
7f96eae312
|
@ -10,7 +10,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch() {
|
onSearch() {
|
||||||
this.$scope.$$postDigest(() => {
|
this.$scope.$applyAsync(() => {
|
||||||
this.$scope.treeview.refresh();
|
this.$scope.treeview.refresh();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Controller {
|
||||||
where: {itemFk: this.$stateParams.id}
|
where: {itemFk: this.$stateParams.id}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$scope.$$postDigest(() => {
|
this.$scope.$applyAsync(() => {
|
||||||
if (this.$stateParams.warehouseFk)
|
if (this.$stateParams.warehouseFk)
|
||||||
this.warehouseFk = this.$stateParams.warehouseFk;
|
this.warehouseFk = this.$stateParams.warehouseFk;
|
||||||
else if (value)
|
else if (value)
|
||||||
|
|
|
@ -69,23 +69,23 @@ describe('Item', () => {
|
||||||
|
|
||||||
describe('set item()', () => {
|
describe('set item()', () => {
|
||||||
it(`should set warehouseFk property based on itemType warehouseFk`, () => {
|
it(`should set warehouseFk property based on itemType warehouseFk`, () => {
|
||||||
spyOn(controller.$scope, '$$postDigest').and.callThrough();
|
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
||||||
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
||||||
|
|
||||||
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
|
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
$scope.$digest();
|
$scope.$apply();
|
||||||
|
|
||||||
expect(controller.warehouseFk).toEqual(1);
|
expect(controller.warehouseFk).toEqual(1);
|
||||||
expect(controller.item.id).toEqual(1);
|
expect(controller.item.id).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should set warehouseFk property based on url query warehouseFk`, () => {
|
it(`should set warehouseFk property based on url query warehouseFk`, () => {
|
||||||
spyOn(controller.$scope, '$$postDigest').and.callThrough();
|
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
||||||
controller.$stateParams.warehouseFk = 4;
|
controller.$stateParams.warehouseFk = 4;
|
||||||
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
||||||
|
|
||||||
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
|
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
$scope.$digest();
|
$scope.$apply();
|
||||||
|
|
||||||
expect(controller.warehouseFk).toEqual(4);
|
expect(controller.warehouseFk).toEqual(4);
|
||||||
expect(controller.item.id).toEqual(1);
|
expect(controller.item.id).toEqual(1);
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Controller {
|
||||||
|
|
||||||
this._order = value;
|
this._order = value;
|
||||||
|
|
||||||
this.$scope.$$postDigest(() => {
|
this.$scope.$applyAsync(() => {
|
||||||
let category;
|
let category;
|
||||||
let type;
|
let type;
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,12 @@ describe('Order', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let $state;
|
let $state;
|
||||||
let controller;
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
beforeEach(ngModule('order'));
|
beforeEach(ngModule('order'));
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(($componentController, _$state_, $rootScope) => {
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.model = crudModel;
|
$scope.model = crudModel;
|
||||||
$scope.search = {};
|
$scope.search = {};
|
||||||
|
@ -27,12 +29,14 @@ describe('Order', () => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('order() setter', () => {
|
describe('order() setter', () => {
|
||||||
it(`should call scope $$postDigest() method and apply filters from state params`, () => {
|
it(`should call scope $applyAsync() method and apply filters from state params`, () => {
|
||||||
spyOn(controller.$scope, '$$postDigest').and.callThrough();
|
$httpBackend.expect('GET', `/item/api/ItemCategories/1/itemTypes`).respond();
|
||||||
|
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
||||||
controller.order = {id: 4};
|
controller.order = {id: 4};
|
||||||
|
|
||||||
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
|
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
$scope.$digest();
|
$scope.$apply();
|
||||||
|
|
||||||
|
|
||||||
expect(controller.category).toEqual({id: 1, value: 'My Category'});
|
expect(controller.category).toEqual({id: 1, value: 'My Category'});
|
||||||
expect(controller.type).toEqual({id: 1, value: 'My type'});
|
expect(controller.type).toEqual({id: 1, value: 'My type'});
|
||||||
|
@ -96,28 +100,38 @@ describe('Order', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('applyFilters()', () => {
|
describe('applyFilters()', () => {
|
||||||
it(`should set type property to null, call updateStateParams() method and not call applyFilters()`, () => {
|
it(`should call model applyFilter() method with a new filter`, () => {
|
||||||
spyOn(controller.catalog.$scope.model, 'applyFilter');
|
let model = controller.catalog.$scope.model;
|
||||||
controller.order = {id: 4};
|
spyOn(model, 'applyFilter');
|
||||||
$scope.$digest();
|
controller._category = {id: 1, value: 'My Category'};
|
||||||
|
controller._type = {id: 1, value: 'My type'};
|
||||||
|
controller._order = {id: 4};
|
||||||
|
|
||||||
controller.applyFilters();
|
controller.applyFilters();
|
||||||
|
|
||||||
expect(controller.catalog.$scope.model.applyFilter).toHaveBeenCalledWith(
|
expect(model.applyFilter).toHaveBeenCalledWith(
|
||||||
{where: {categoryFk: 1, typeFk: 1}},
|
{where: {categoryFk: 1, typeFk: 1}},
|
||||||
{orderFk: 4, orderBy: controller.catalog.getOrderBy(), tags: []});
|
{orderFk: 4, orderBy: controller.catalog.getOrderBy(), tags: []});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('remove()', () => {
|
describe('remove()', () => {
|
||||||
it(`should remove a filter from tags property and then call applyFilters()`, () => {
|
it(`should remove a tag from tags property`, () => {
|
||||||
spyOn(controller, 'applyFilters');
|
|
||||||
controller.order = {id: 4};
|
|
||||||
controller.tags = [{tagFk: 1, value: 'Blue'}, {tagFk: 2, value: '70'}];
|
controller.tags = [{tagFk: 1, value: 'Blue'}, {tagFk: 2, value: '70'}];
|
||||||
$scope.$digest();
|
|
||||||
controller.remove(0);
|
controller.remove(0);
|
||||||
|
|
||||||
expect(controller.tags.length).toEqual(1);
|
expect(controller.tags.length).toEqual(1);
|
||||||
expect(controller.tags[0].tagFk).toEqual(2);
|
expect(controller.tags[0].tagFk).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should remove a tag from tags property and call applyFilters() if there's no more tags`, () => {
|
||||||
|
spyOn(controller, 'applyFilters');
|
||||||
|
controller._category = {id: 1, value: 'My Category'};
|
||||||
|
controller._type = {id: 1, value: 'My type'};
|
||||||
|
controller.tags = [{tagFk: 1, value: 'Blue'}];
|
||||||
|
controller.remove(0);
|
||||||
|
|
||||||
|
expect(controller.tags.length).toEqual(0);
|
||||||
expect(controller.applyFilters).toHaveBeenCalledWith();
|
expect(controller.applyFilters).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -125,10 +139,10 @@ describe('Order', () => {
|
||||||
describe('updateStateParams()', () => {
|
describe('updateStateParams()', () => {
|
||||||
it(`should call state go() method passing category and type state params`, () => {
|
it(`should call state go() method passing category and type state params`, () => {
|
||||||
spyOn(controller.$state, 'go');
|
spyOn(controller.$state, 'go');
|
||||||
controller.order = {id: 4};
|
controller._category = {id: 1, value: 'My Category'};
|
||||||
$scope.$digest();
|
controller._type = {id: 1, value: 'My type'};
|
||||||
|
|
||||||
let result = {category: '{"id":1,"value":"My Category"}', type: '{"id":1,"value":"My type"}'};
|
let result = {category: '{"id":1,"value":"My Category"}', type: '{"id":1,"value":"My type"}'};
|
||||||
|
controller.updateStateParams();
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result);
|
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result);
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,6 +35,9 @@ class Controller {
|
||||||
};
|
};
|
||||||
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
|
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
|
||||||
this.tags = response.data;
|
this.tags = response.data;
|
||||||
|
this.$.$applyAsync(() => {
|
||||||
|
this.$.popover.relocate();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
show(event, item) {
|
show(event, item) {
|
||||||
|
@ -42,8 +45,8 @@ class Controller {
|
||||||
this.prices = this.item.prices;
|
this.prices = this.item.prices;
|
||||||
this.getTags();
|
this.getTags();
|
||||||
this.$.popover.parent = event.target;
|
this.$.popover.parent = event.target;
|
||||||
this.$.popover.relocate();
|
|
||||||
this.$.popover.show();
|
this.$.popover.show();
|
||||||
|
this.$.popover.relocate();
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
this.item = {};
|
this.item = {};
|
||||||
|
|
Loading…
Reference in New Issue