From 469e6f8076d3ac2d3ec54c4f8387d8ec58846e8e Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Sep 2018 13:34:11 +0200 Subject: [PATCH] fixed itemDiary warehouseFk select #671 --- client/item/src/diary/index.html | 2 +- client/item/src/diary/index.js | 24 +++++++++++------------- client/item/src/diary/index.spec.js | 11 ++++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/client/item/src/diary/index.html b/client/item/src/diary/index.html index cdc389b557..6458699e90 100644 --- a/client/item/src/diary/index.html +++ b/client/item/src/diary/index.html @@ -1,7 +1,7 @@ diff --git a/client/item/src/diary/index.js b/client/item/src/diary/index.js index 826211c277..e6ace87396 100644 --- a/client/item/src/diary/index.js +++ b/client/item/src/diary/index.js @@ -10,12 +10,11 @@ class Controller { this.$window = $window; this.$translate = $translate; } -/* - $postLink() { - if (this.item) - this.filterBuilder(); + + get item() { + return this._item; } - */ + set item(value) { this._item = value; @@ -23,14 +22,12 @@ class Controller { where: {itemFk: this.$stateParams.id} }; - if (this.$stateParams.warehouseFk) - this.warehouseFk = this.$stateParams.warehouseFk; - else if (value) - this.warehouseFk = value.itemType.warehouseFk; - } - - get item() { - return this._item; + this.$scope.$$postDigest(() => { + if (this.$stateParams.warehouseFk) + this.warehouseFk = this.$stateParams.warehouseFk; + else if (value) + this.warehouseFk = value.itemType.warehouseFk; + }); } set warehouseFk(value) { @@ -41,6 +38,7 @@ class Controller { }); this.filter.where.warehouseFk = value; + this.$scope.model.refresh(); } get warehouseFk() { diff --git a/client/item/src/diary/index.spec.js b/client/item/src/diary/index.spec.js index 4e17653ad3..72c90c90f6 100644 --- a/client/item/src/diary/index.spec.js +++ b/client/item/src/diary/index.spec.js @@ -1,4 +1,5 @@ import './index.js'; +import {crudModel} from '../../../helpers/crudModelHelper'; describe('Item', () => { describe('Component vnItemDiary', () => { @@ -20,7 +21,7 @@ describe('Item', () => { $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); $scope = $rootScope.$new(); controller = $componentController('vnItemDiary', {$scope: $scope, $stateParams}); - controller.$scope.model = {}; + controller.$scope.model = crudModel; })); describe('isToday()', () => { @@ -75,16 +76,24 @@ describe('Item', () => { describe('set item()', () => { it(`should set warehouseFk property based on itemType warehouseFk`, () => { + spyOn(controller.$scope, '$$postDigest').and.callThrough(); controller.item = {id: 1, itemType: {warehouseFk: 1}}; + expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function)); + $scope.$digest(); + expect(controller.warehouseFk).toEqual(1); expect(controller.item.id).toEqual(1); }); it(`should set warehouseFk property based on url query warehouseFk`, () => { + spyOn(controller.$scope, '$$postDigest').and.callThrough(); controller.$stateParams.warehouseFk = 4; controller.item = {id: 1, itemType: {warehouseFk: 1}}; + expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function)); + $scope.$digest(); + expect(controller.warehouseFk).toEqual(4); expect(controller.item.id).toEqual(1); });