Commit 5dd1f8c1 authored by Savas Vedova's avatar Savas Vedova

Fix polling on vuln details page

Changelog: fixed
EE: true
parent 8ef76585
...@@ -71,6 +71,7 @@ export default { ...@@ -71,6 +71,7 @@ export default {
this.discussionsLoading = false; this.discussionsLoading = false;
this.notifyHeaderForStateChangeIfRequired(); this.notifyHeaderForStateChangeIfRequired();
this.startPolling(); this.startPolling();
this.bindVisibilityListener();
}, },
error() { error() {
this.showGraphQLError(); this.showGraphQLError();
...@@ -114,6 +115,7 @@ export default { ...@@ -114,6 +115,7 @@ export default {
}, },
beforeDestroy() { beforeDestroy() {
this.stopPolling(); this.stopPolling();
this.unbindVisibilityListener();
}, },
updated() { updated() {
this.$nextTick(() => { this.$nextTick(() => {
...@@ -129,6 +131,17 @@ export default { ...@@ -129,6 +131,17 @@ export default {
if (!Visibility.hidden()) { if (!Visibility.hidden()) {
this.pollInterval = setInterval(this.fetchDiscussions, TEN_SECONDS); this.pollInterval = setInterval(this.fetchDiscussions, TEN_SECONDS);
} }
},
stopPolling() {
if (typeof this.pollInterval !== 'undefined') {
clearInterval(this.pollInterval);
this.pollInterval = undefined;
}
},
bindVisibilityListener() {
if (this.visibilityListener) {
return;
}
this.visibilityListener = Visibility.change(() => { this.visibilityListener = Visibility.change(() => {
if (Visibility.hidden()) { if (Visibility.hidden()) {
...@@ -138,12 +151,7 @@ export default { ...@@ -138,12 +151,7 @@ export default {
} }
}); });
}, },
stopPolling() { unbindVisibilityListener() {
if (typeof this.pollInterval !== 'undefined') {
clearInterval(this.pollInterval);
this.pollInterval = undefined;
}
if (typeof this.visibilityListener !== 'undefined') { if (typeof this.visibilityListener !== 'undefined') {
Visibility.unbind(this.visibilityListener); Visibility.unbind(this.visibilityListener);
this.visibilityListener = undefined; this.visibilityListener = undefined;
......
...@@ -174,6 +174,23 @@ describe('Vulnerability Footer', () => { ...@@ -174,6 +174,23 @@ describe('Vulnerability Footer', () => {
expect(visibilityUnbindSpy).toHaveBeenCalled(); expect(visibilityUnbindSpy).toHaveBeenCalled();
}); });
it('does not remove the listener when the visibility changes', async () => {
const clearIntervalSpy = jest.spyOn(window, 'clearInterval');
const visibilityUnbindSpy = jest.spyOn(Visibility, 'unbind');
const visibilityHiddenSpy = jest
.spyOn(Visibility, 'hidden')
.mockImplementationOnce(() => false) // This is called in startPolling
.mockImplementationOnce(() => true); // This is called in visibilityChangeListener
const visibilityChangeSpy = jest
.spyOn(Visibility, 'change')
.mockImplementation((callback) => callback());
await createWrapperAndFetchDiscussions({ discussions: [] });
expect(visibilityHiddenSpy).toHaveBeenCalled();
expect(visibilityChangeSpy).toHaveBeenCalled();
expect(clearIntervalSpy).toHaveBeenCalled();
expect(visibilityUnbindSpy).not.toHaveBeenCalled();
});
it('emits the vulnerability-state-change event when the system note is new', async () => { it('emits the vulnerability-state-change event when the system note is new', async () => {
const eventName = 'vulnerability-state-change'; const eventName = 'vulnerability-state-change';
const queryHandler = discussionsHandler({ discussions: [discussion1] }); // first call const queryHandler = discussionsHandler({ discussions: [discussion1] }); // first call
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment