diff options
Diffstat (limited to 'spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js')
-rw-r--r-- | spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js b/spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js index dd1d62cd4ed..8de99fd3c96 100644 --- a/spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js +++ b/spec/javascripts/vue_mr_widget/components/states/mr_widget_failed_to_merge_spec.js @@ -4,21 +4,39 @@ import eventHub from '~/vue_merge_request_widget/event_hub'; import mountComponent from 'spec/helpers/vue_mount_component_helper'; describe('MRWidgetFailedToMerge', () => { + const dummyIntervalId = 1337; let Component; + let mr; let vm; beforeEach(() => { Component = Vue.extend(failedToMergeComponent); spyOn(eventHub, '$emit'); - vm = mountComponent(Component, { mr: { - mergeError: 'Merge error happened.', - } }); + spyOn(window, 'setInterval').and.returnValue(dummyIntervalId); + spyOn(window, 'clearInterval').and.stub(); + mr = { + mergeError: 'Merge error happened', + }; + vm = mountComponent(Component, { + mr, + }); }); afterEach(() => { vm.$destroy(); }); + it('sets interval to refresh', () => { + expect(window.setInterval).toHaveBeenCalledWith(vm.updateTimer, 1000); + expect(vm.intervalId).toBe(dummyIntervalId); + }); + + it('clears interval when destroying ', () => { + vm.$destroy(); + + expect(window.clearInterval).toHaveBeenCalledWith(dummyIntervalId); + }); + describe('computed', () => { describe('timerText', () => { it('should return correct timer text', () => { @@ -28,6 +46,19 @@ describe('MRWidgetFailedToMerge', () => { expect(vm.timerText).toEqual('Refreshing in a second to show the updated status...'); }); }); + + describe('mergeError', () => { + it('removes forced line breaks', done => { + mr.mergeError = 'contains<br />line breaks<br />'; + + Vue.nextTick() + .then(() => { + expect(vm.mergeError).toBe('contains line breaks'); + }) + .then(done) + .catch(done.fail); + }); + }); }); describe('created', () => { @@ -65,11 +96,13 @@ describe('MRWidgetFailedToMerge', () => { }); describe('while it is refreshing', () => { - it('renders Refresing now', (done) => { + it('renders Refresing now', done => { vm.isRefreshing = true; Vue.nextTick(() => { - expect(vm.$el.querySelector('.js-refresh-label').textContent.trim()).toEqual('Refreshing now'); + expect(vm.$el.querySelector('.js-refresh-label').textContent.trim()).toEqual( + 'Refreshing now', + ); done(); }); }); @@ -78,11 +111,15 @@ describe('MRWidgetFailedToMerge', () => { describe('while it is not regresing', () => { it('renders warning icon and disabled merge button', () => { expect(vm.$el.querySelector('.js-ci-status-icon-warning')).not.toBeNull(); - expect(vm.$el.querySelector('.js-disabled-merge-button').getAttribute('disabled')).toEqual('disabled'); + expect(vm.$el.querySelector('.js-disabled-merge-button').getAttribute('disabled')).toEqual( + 'disabled', + ); }); it('renders given error', () => { - expect(vm.$el.querySelector('.has-error-message').textContent.trim()).toEqual('Merge error happened..'); + expect(vm.$el.querySelector('.has-error-message').textContent.trim()).toEqual( + 'Merge error happened.', + ); }); it('renders refresh button', () => { @@ -90,13 +127,13 @@ describe('MRWidgetFailedToMerge', () => { }); it('renders remaining time', () => { - expect( - vm.$el.querySelector('.has-custom-error').textContent.trim(), - ).toEqual('Refreshing in 10 seconds to show the updated status...'); + expect(vm.$el.querySelector('.has-custom-error').textContent.trim()).toEqual( + 'Refreshing in 10 seconds to show the updated status...', + ); }); }); - it('should just generic merge failed message if merge_error is not available', (done) => { + it('should just generic merge failed message if merge_error is not available', done => { vm.mr.mergeError = null; Vue.nextTick(() => { @@ -106,7 +143,7 @@ describe('MRWidgetFailedToMerge', () => { }); }); - it('should show refresh label when refresh requested', (done) => { + it('should show refresh label when refresh requested', done => { vm.refresh(); Vue.nextTick(() => { expect(vm.$el.innerText).not.toContain('Merge failed. Refreshing'); |