summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-03-13 11:38:14 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-03-13 11:38:14 +0000
commit6f9148c804cfd0e62ac330e146727776a7f2d37c (patch)
tree74dfe73f2da671fc954dec05bec273c457aa696b
parentdfee47e066193599a29c4326ace3f7e97efece2d (diff)
parentef67677422c110073c2dc4ca9cc8e8b30c2e2559 (diff)
downloadgitlab-ce-6f9148c804cfd0e62ac330e146727776a7f2d37c.tar.gz
Merge branch '20450-fix-ujs-actions-part-3-step2' into 20450-fix-ujs-actions-part-3-step3
* 20450-fix-ujs-actions-part-3-step2: Adds confirmation message to async button component Fix broken tests Fix broken specs
-rw-r--r--app/assets/javascripts/vue_pipelines_index/components/async_button.js15
-rw-r--r--app/assets/javascripts/vue_shared/components/pipelines_table_row.js7
-rw-r--r--spec/features/merge_requests/created_from_fork_spec.rb2
-rw-r--r--spec/features/projects/pipelines/pipelines_spec.rb31
-rw-r--r--spec/javascripts/vue_pipelines_index/async_button_spec.js24
5 files changed, 61 insertions, 18 deletions
diff --git a/app/assets/javascripts/vue_pipelines_index/components/async_button.js b/app/assets/javascripts/vue_pipelines_index/components/async_button.js
index 639f87de0cc..aaebf29d8ae 100644
--- a/app/assets/javascripts/vue_pipelines_index/components/async_button.js
+++ b/app/assets/javascripts/vue_pipelines_index/components/async_button.js
@@ -1,4 +1,4 @@
-/* eslint-disable no-new */
+/* eslint-disable no-new, no-alert */
/* global Flash */
import '~/flash';
import eventHub from '../event_hub';
@@ -29,6 +29,11 @@ export default {
type: String,
required: true,
},
+
+ confirmActionMessage: {
+ type: String,
+ required: false,
+ },
},
data() {
@@ -49,6 +54,14 @@ export default {
methods: {
onClick() {
+ if (this.confirmActionMessage && confirm(this.confirmActionMessage)) {
+ this.makeRequest();
+ } else if (!this.confirmActionMessage) {
+ this.makeRequest();
+ }
+ },
+
+ makeRequest() {
this.isLoading = true;
this.service.postAction(this.endpoint)
diff --git a/app/assets/javascripts/vue_shared/components/pipelines_table_row.js b/app/assets/javascripts/vue_shared/components/pipelines_table_row.js
index 779894e78bd..12838a8f5df 100644
--- a/app/assets/javascripts/vue_shared/components/pipelines_table_row.js
+++ b/app/assets/javascripts/vue_shared/components/pipelines_table_row.js
@@ -215,7 +215,7 @@ require('./commit');
v-if="pipeline.flags.retryable"
:service="service"
:endpoint="pipeline.retry_path"
- css-class="btn-default btn-retry"
+ css-class="btn-default btn-retry js-pipelines-retry-button"
title="Retry"
icon="repeat" />
@@ -223,9 +223,10 @@ require('./commit');
v-if="pipeline.flags.cancelable"
:service="service"
:endpoint="pipeline.cancel_path"
- css-class="btn-remove"
+ css-class="btn-remove js-pipelines-cancel-button"
title="Cancel"
- icon="remove" />
+ icon="remove"
+ confirm-action-message="Are you sure you want to cancel this pipeline?" />
</div>
</td>
</tr>
diff --git a/spec/features/merge_requests/created_from_fork_spec.rb b/spec/features/merge_requests/created_from_fork_spec.rb
index 73c5ef31edc..435fd9c75b5 100644
--- a/spec/features/merge_requests/created_from_fork_spec.rb
+++ b/spec/features/merge_requests/created_from_fork_spec.rb
@@ -61,7 +61,7 @@ feature 'Merge request created from fork' do
expect(page).to have_content pipeline.id
end
- expect(page.find('a.btn-remove')[:href])
+ expect(page.find('button.btn-remove')[:href])
.to include fork_project.path_with_namespace
end
end
diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb
index 22bf1bfbdf0..48af02840fd 100644
--- a/spec/features/projects/pipelines/pipelines_spec.rb
+++ b/spec/features/projects/pipelines/pipelines_spec.rb
@@ -99,15 +99,18 @@ describe 'Pipelines', :feature, :js do
end
it 'indicates that pipeline can be canceled' do
- expect(page).to have_link('Cancel')
+ expect(page).to have_selector('.js-pipelines-cancel-button')
expect(page).to have_selector('.ci-running')
end
context 'when canceling' do
- before { click_link('Cancel') }
+ before do
+ find('.js-pipelines-cancel-button').click
+ wait_for_vue_resource
+ end
it 'indicated that pipelines was canceled' do
- expect(page).not_to have_link('Cancel')
+ expect(page).not_to have_selector('.js-pipelines-cancel-button')
expect(page).to have_selector('.ci-canceled')
end
end
@@ -126,15 +129,19 @@ describe 'Pipelines', :feature, :js do
end
it 'indicates that pipeline can be retried' do
- expect(page).to have_link('Retry')
+ expect(page).to have_selector('.js-pipelines-retry-button')
expect(page).to have_selector('.ci-failed')
end
context 'when retrying' do
- before { click_link('Retry') }
+ before do
+ find('.js-pipelines-retry-button').click
+ wait_for_vue_resource
+ end
it 'shows running pipeline that is not retryable' do
- expect(page).not_to have_link('Retry')
+
+ expect(page).not_to have_selector('.js-pipelines-retry-button')
expect(page).to have_selector('.ci-running')
end
end
@@ -176,13 +183,13 @@ describe 'Pipelines', :feature, :js do
it 'has link to the manual action' do
find('.js-pipeline-dropdown-manual-actions').click
- expect(page).to have_link('manual build')
+ expect(page).to have_button('manual build')
end
context 'when manual action was played' do
before do
find('.js-pipeline-dropdown-manual-actions').click
- click_link('manual build')
+ click_button('manual build')
end
it 'enqueues manual action job' do
@@ -203,7 +210,7 @@ describe 'Pipelines', :feature, :js do
before { visit_project_pipelines }
it 'is cancelable' do
- expect(page).to have_link('Cancel')
+ expect(page).to have_selector('.js-pipelines-cancel-button')
end
it 'has pipeline running' do
@@ -211,10 +218,10 @@ describe 'Pipelines', :feature, :js do
end
context 'when canceling' do
- before { click_link('Cancel') }
+ before { find('.js-pipelines-cancel-button').trigger('click') }
it 'indicates that pipeline was canceled' do
- expect(page).not_to have_link('Cancel')
+ expect(page).not_to have_selector('.js-pipelines-cancel-button')
expect(page).to have_selector('.ci-canceled')
end
end
@@ -233,7 +240,7 @@ describe 'Pipelines', :feature, :js do
end
it 'is not retryable' do
- expect(page).not_to have_link('Retry')
+ expect(page).not_to have_selector('.js-pipelines-retry-button')
end
it 'has failed pipeline' do
diff --git a/spec/javascripts/vue_pipelines_index/async_button_spec.js b/spec/javascripts/vue_pipelines_index/async_button_spec.js
index 47e78fed3f9..bc8e504c413 100644
--- a/spec/javascripts/vue_pipelines_index/async_button_spec.js
+++ b/spec/javascripts/vue_pipelines_index/async_button_spec.js
@@ -9,7 +9,6 @@ describe('Pipelines Async Button', () => {
beforeEach(() => {
AsyncButtonComponent = Vue.extend(asyncButtonComp);
- spyOn(window, 'confirm').and.returnValue(true);
spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());
component = new AsyncButtonComponent({
@@ -68,4 +67,27 @@ describe('Pipelines Async Button', () => {
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);
+ 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,
+ },
+ confirmActionMessage: 'bar',
+ },
+ }).$mount();
+
+ component.$el.click();
+ expect(spy).toHaveBeenCalledWith('/foo');
+ });
+ });
});