diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-06-21 07:47:41 +0000 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2017-06-21 07:47:41 +0000 |
commit | 5213bf2bf713f1647c05821d42afea90d93a57b6 (patch) | |
tree | 4224004367013ba02b5bba24bdfcda3bb03ae4e8 /spec/javascripts/pipelines/async_button_spec.js | |
parent | 1578ee93475c0ebb62399403d971e99aa45e7276 (diff) | |
download | gitlab-ce-revert-1578ee93.tar.gz |
Revert "Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce"revert-1578ee93
This reverts commit 1578ee93475c0ebb62399403d971e99aa45e7276
Diffstat (limited to 'spec/javascripts/pipelines/async_button_spec.js')
-rw-r--r-- | spec/javascripts/pipelines/async_button_spec.js | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/spec/javascripts/pipelines/async_button_spec.js b/spec/javascripts/pipelines/async_button_spec.js index 48620898357..28c9c7ab282 100644 --- a/spec/javascripts/pipelines/async_button_spec.js +++ b/spec/javascripts/pipelines/async_button_spec.js @@ -1,20 +1,25 @@ import Vue from 'vue'; import asyncButtonComp from '~/pipelines/components/async_button.vue'; -import eventHub from '~/pipelines/event_hub'; describe('Pipelines Async Button', () => { let component; + let spy; let AsyncButtonComponent; beforeEach(() => { AsyncButtonComponent = Vue.extend(asyncButtonComp); + spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve()); + component = new AsyncButtonComponent({ propsData: { endpoint: '/foo', title: 'Foo', icon: 'fa fa-foo', cssClass: 'bar', + service: { + postAction: spy, + }, }, }).$mount(); }); @@ -28,7 +33,7 @@ describe('Pipelines Async Button', () => { }); it('should render the provided title', () => { - expect(component.$el.getAttribute('data-original-title')).toContain('Foo'); + expect(component.$el.getAttribute('title')).toContain('Foo'); expect(component.$el.getAttribute('aria-label')).toContain('Foo'); }); @@ -36,12 +41,37 @@ describe('Pipelines Async Button', () => { expect(component.$el.getAttribute('class')).toContain('bar'); }); + it('should call the service when it is clicked with the provided endpoint', () => { + component.$el.click(); + expect(spy).toHaveBeenCalledWith('/foo'); + }); + + it('should hide loading if request fails', () => { + spy = jasmine.createSpy('spy').and.returnValue(Promise.reject()); + + component = new AsyncButtonComponent({ + propsData: { + endpoint: '/foo', + title: 'Foo', + icon: 'fa fa-foo', + cssClass: 'bar', + dataAttributes: { + 'data-foo': 'foo', + }, + service: { + postAction: spy, + }, + }, + }).$mount(); + + component.$el.click(); + expect(component.$el.querySelector('.fa-spinner')).toBe(null); + }); + describe('With confirm dialog', () => { it('should call the service when confimation is positive', () => { spyOn(window, 'confirm').and.returnValue(true); - eventHub.$on('postAction', (endpoint) => { - expect(endpoint).toEqual('/foo'); - }); + spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve()); component = new AsyncButtonComponent({ propsData: { @@ -49,11 +79,15 @@ describe('Pipelines Async Button', () => { title: 'Foo', icon: 'fa fa-foo', cssClass: 'bar', + service: { + postAction: spy, + }, confirmActionMessage: 'bar', }, }).$mount(); component.$el.click(); + expect(spy).toHaveBeenCalledWith('/foo'); }); }); }); |