Commit 939beeb6 authored by Justin Boyson's avatar Justin Boyson Committed by Martin Wortschack

Add check for window focus before polling

parent dccaf488
...@@ -212,6 +212,8 @@ export default { ...@@ -212,6 +212,8 @@ export default {
return new MRWidgetService(this.getServiceEndpoints(store)); return new MRWidgetService(this.getServiceEndpoints(store));
}, },
checkStatus(cb, isRebased) { checkStatus(cb, isRebased) {
if (document.visibilityState !== 'visible') return Promise.resolve();
return this.service return this.service
.checkStatus() .checkStatus()
.then(({ data }) => { .then(({ data }) => {
......
...@@ -259,16 +259,40 @@ describe('mrWidgetOptions', () => { ...@@ -259,16 +259,40 @@ describe('mrWidgetOptions', () => {
describe('methods', () => { describe('methods', () => {
describe('checkStatus', () => { describe('checkStatus', () => {
it('should tell service to check status', () => { let cb;
let isCbExecuted;
beforeEach(() => {
jest.spyOn(vm.service, 'checkStatus').mockReturnValue(returnPromise(mockData)); jest.spyOn(vm.service, 'checkStatus').mockReturnValue(returnPromise(mockData));
jest.spyOn(vm.mr, 'setData').mockImplementation(() => {}); jest.spyOn(vm.mr, 'setData').mockImplementation(() => {});
jest.spyOn(vm, 'handleNotification').mockImplementation(() => {}); jest.spyOn(vm, 'handleNotification').mockImplementation(() => {});
let isCbExecuted = false; isCbExecuted = false;
const cb = () => { cb = () => {
isCbExecuted = true; isCbExecuted = true;
}; };
});
it('should not tell service to check status if document is not visible', () => {
Object.defineProperty(document, 'visibilityState', {
value: 'hidden',
configurable: true,
});
vm.checkStatus(cb);
return vm.$nextTick().then(() => {
expect(vm.service.checkStatus).not.toHaveBeenCalled();
expect(vm.mr.setData).not.toHaveBeenCalled();
expect(vm.handleNotification).not.toHaveBeenCalled();
expect(isCbExecuted).toBeFalsy();
Object.defineProperty(document, 'visibilityState', {
value: 'visible',
configurable: true,
});
});
});
it('should tell service to check status if document is visible', () => {
vm.checkStatus(cb); vm.checkStatus(cb);
return vm.$nextTick().then(() => { return vm.$nextTick().then(() => {
......
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