Skip to content

Commit

Permalink
Merge pull request #8937 from sairina/pdf-probs
Browse files Browse the repository at this point in the history
PDF renderer completion fixes
  • Loading branch information
rtibbles committed Dec 16, 2021
2 parents 6bf8953 + 259722c commit 16614a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ describe('useProgressTracking composable', () => {
expect(get(progress_delta)).toEqual(0.1);
expect(client).not.toHaveBeenCalled();
});
it('should increment progress_delta if progress is updated twice', async () => {
const { updateContentSession, progress_delta } = await initStore();
await updateContentSession({ progress: 0.6 });
await updateContentSession({ progress: 0.7 });
expect(get(progress_delta)).toEqual(0.2);
expect(client).not.toHaveBeenCalled();
});
it('should update progress and store progress_delta if progress is updated over threshold', async () => {
const { updateContentSession, progress } = await initStore();
await updateContentSession({ progress: 1 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function useProgressTracking(store) {
store = store || getCurrentInstance().proxy.$store;
const complete = ref(null);
const progress_state = ref(null);
const progress_delta = ref(null);
const progress_delta = ref(0);
const time_spent = ref(null);
const time_spent_delta = ref(null);
const session_id = ref(null);
Expand Down Expand Up @@ -350,7 +350,9 @@ export default function useProgressTracking(store) {
progress = _zeroToOne(progress);
progress = threeDecimalPlaceRoundup(progress);
if (get(progress_state) < progress) {
set(progress_delta, threeDecimalPlaceRoundup(progress - get(progress_state)));
const newProgressDelta =
get(progress_delta) + threeDecimalPlaceRoundup(progress - get(progress_state));
set(progress_delta, newProgressDelta);
set(progress_state, progress);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@
}
this.$emit('startTracking');
this.updateContentStateInterval = setInterval(this.updateProgress, 30000);
// Even if user does not pause while scrolling on first page, we store that as visited
this.storeVisitedPage(1);
});
},
beforeDestroy() {
Expand Down Expand Up @@ -323,8 +325,9 @@
// TODO: there is a miscalculation that causes a wrong position change on scale
this.savePosition(this.calculatePosition());
// determine how many pages user has viewed/visited
let currentPage = parseInt(this.currentLocation * this.totalPages) + 1;
// determine how many pages user has viewed/visited; fix edge case of 2 pages
let currentPage =
this.totalPages === 2 ? 2 : parseInt(this.currentLocation * this.totalPages) + 1;
this.storeVisitedPage(currentPage);
this.updateProgress();
this.updateContentState();
Expand Down

0 comments on commit 16614a8

Please sign in to comment.