From 968ecab9b22c2fa1e0be23a339ef0c75381d66cd Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 24 Mar 2022 10:28:28 +0100 Subject: [PATCH] fix(item_diary): apply async scroll --- modules/item/front/diary/index.js | 10 ++++++---- modules/item/front/diary/index.spec.js | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index bf04fabe95..6d912ebe8a 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -52,10 +52,12 @@ class Controller extends Section { } scrollToLine(lineFk) { - const hashFk = this.lineFk || lineFk; - const hash = `vnItemDiary-${hashFk}`; - this.$location.hash(hash); - this.$anchorScroll(); + this.$.$applyAsync(() => { + const hashFk = this.lineFk || lineFk; + const hash = `vnItemDiary-${hashFk}`; + this.$location.hash(hash); + this.$anchorScroll(); + }); } showDescriptor(event, sale) { diff --git a/modules/item/front/diary/index.spec.js b/modules/item/front/diary/index.spec.js index 9889149781..ad86e3c0ac 100644 --- a/modules/item/front/diary/index.spec.js +++ b/modules/item/front/diary/index.spec.js @@ -43,19 +43,27 @@ describe('Item', () => { describe('scrollToLine ()', () => { it('should assign $location then call anchorScroll using controller value', () => { + jest.spyOn(controller.$, '$applyAsync'); jest.spyOn(controller, '$anchorScroll'); controller.lineFk = 1; controller.scrollToLine('invalidValue'); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + $scope.$apply(); + expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`); expect(controller.$anchorScroll).toHaveBeenCalledWith(); }); it('should assign $location then call anchorScroll using received value', () => { + jest.spyOn(controller.$, '$applyAsync'); jest.spyOn(controller, '$anchorScroll'); controller.lineFk = undefined; controller.scrollToLine(1); + expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); + $scope.$apply(); + expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`); expect(controller.$anchorScroll).toHaveBeenCalledWith(); });