Skip to content

Commit 56cf2a5

Browse files
author
Andrea Barbasso
committed
[DURACOM-387] fix scripts dropdown not loading new elements while zoomed in or out
1 parent 11fdc4a commit 56cf2a5

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/app/process-page/form/scripts-select/scripts-select.component.spec.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,86 @@ describe('ScriptsSelectComponent', () => {
109109
const validationError = fixture.debugElement.query(By.css('.validation-error'));
110110
expect(validationError).toBeFalsy();
111111
}));
112+
113+
it('should load more scripts when scrolled to the bottom', fakeAsync(() => {
114+
spyOn(component, 'loadScripts');
115+
const event = {
116+
target: {
117+
scrollTop: 100,
118+
clientHeight: 200,
119+
scrollHeight: 300,
120+
},
121+
};
122+
123+
component.onScroll(event);
124+
tick();
125+
126+
expect(component.loadScripts).toHaveBeenCalled();
127+
}));
128+
129+
it('should load more scripts when scrolled almost to the bottom', fakeAsync(() => {
130+
spyOn(component, 'loadScripts');
131+
const event = {
132+
target: {
133+
scrollTop: 99,
134+
clientHeight: 200,
135+
scrollHeight: 300,
136+
},
137+
};
138+
139+
component.onScroll(event);
140+
tick();
141+
142+
expect(component.loadScripts).toHaveBeenCalled();
143+
}));
144+
145+
it('should not load more scripts if already loading', fakeAsync(() => {
146+
spyOn(component, 'loadScripts');
147+
component.isLoading$.next(true);
148+
const event = {
149+
target: {
150+
scrollTop: 100,
151+
clientHeight: 200,
152+
scrollHeight: 300,
153+
},
154+
};
155+
156+
component.onScroll(event);
157+
tick();
158+
159+
expect(component.loadScripts).not.toHaveBeenCalled();
160+
}));
161+
162+
it('should not load more scripts if it is the last page', fakeAsync(() => {
163+
spyOn(component, 'loadScripts');
164+
(component as any)._isLastPage = true;
165+
const event = {
166+
target: {
167+
scrollTop: 100,
168+
clientHeight: 200,
169+
scrollHeight: 300,
170+
},
171+
};
172+
173+
component.onScroll(event);
174+
tick();
175+
176+
expect(component.loadScripts).not.toHaveBeenCalled();
177+
}));
178+
179+
it('should not load more scripts if not scrolled to the bottom', fakeAsync(() => {
180+
spyOn(component, 'loadScripts');
181+
const event = {
182+
target: {
183+
scrollTop: 50,
184+
clientHeight: 200,
185+
scrollHeight: 300,
186+
},
187+
};
188+
189+
component.onScroll(event);
190+
tick();
191+
192+
expect(component.loadScripts).not.toHaveBeenCalled();
193+
}));
112194
});

src/app/process-page/form/scripts-select/scripts-select.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export class ScriptsSelectComponent implements OnInit, OnDestroy {
131131
* @param event The scroll event
132132
*/
133133
onScroll(event: any) {
134-
if (event.target.scrollTop + event.target.clientHeight >= event.target.scrollHeight) {
134+
// offset to fix issues with zooming in or out in the browser
135+
const offset = 5;
136+
if (event.target.scrollTop + event.target.clientHeight + offset >= event.target.scrollHeight) {
135137
if (!this.isLoading$.value && !this._isLastPage) {
136138
this.scriptOptions.currentPage++;
137139
this.loadScripts();

0 commit comments

Comments
 (0)