fix(item_diary): apply async scroll
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-03-24 10:28:28 +01:00
parent b8910e38ea
commit 968ecab9b2
2 changed files with 14 additions and 4 deletions

View File

@ -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) {

View File

@ -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();
});