diff options
Diffstat (limited to 'spec/frontend/vue_mr_widget')
-rw-r--r-- | spec/frontend/vue_mr_widget/mr_widget_options_spec.js | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/spec/frontend/vue_mr_widget/mr_widget_options_spec.js b/spec/frontend/vue_mr_widget/mr_widget_options_spec.js index 5edf41b1ec6..ef95cb1b8f2 100644 --- a/spec/frontend/vue_mr_widget/mr_widget_options_spec.js +++ b/spec/frontend/vue_mr_widget/mr_widget_options_spec.js @@ -259,16 +259,40 @@ describe('mrWidgetOptions', () => { describe('methods', () => { 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.mr, 'setData').mockImplementation(() => {}); jest.spyOn(vm, 'handleNotification').mockImplementation(() => {}); - let isCbExecuted = false; - const cb = () => { + isCbExecuted = false; + cb = () => { 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); return vm.$nextTick().then(() => { |