Commit a4041051 authored by wortschi's avatar wortschi

Replace window.confirm with GlModa in pipeline manual actions

This replaces the window.confirm dialog with
a GlModal when performaning a manual
action on a pipeline.

Changelog: changed
parent f79034e5
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlDropdown, GlDropdownItem, GlIcon, GlTooltipDirective } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlIcon, GlTooltipDirective } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import { s__, __, sprintf } from '~/locale'; import { s__, __, sprintf } from '~/locale';
import GlCountdown from '~/vue_shared/components/gl_countdown.vue'; import GlCountdown from '~/vue_shared/components/gl_countdown.vue';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
...@@ -28,7 +29,7 @@ export default { ...@@ -28,7 +29,7 @@ export default {
}; };
}, },
methods: { methods: {
onClickAction(action) { async onClickAction(action) {
if (action.scheduled_at) { if (action.scheduled_at) {
const confirmationMessage = sprintf( const confirmationMessage = sprintf(
s__( s__(
...@@ -36,9 +37,10 @@ export default { ...@@ -36,9 +37,10 @@ export default {
), ),
{ jobName: action.name }, { jobName: action.name },
); );
// https://gitlab.com/gitlab-org/gitlab-foss/issues/52156
// eslint-disable-next-line no-alert const confirmed = await confirmAction(confirmationMessage);
if (!window.confirm(confirmationMessage)) {
if (!confirmed) {
return; return;
} }
} }
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Pipelines', :js do RSpec.describe 'Pipelines', :js do
include ProjectForksHelper include ProjectForksHelper
include Spec::Support::Helpers::ModalHelpers
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -436,7 +437,9 @@ RSpec.describe 'Pipelines', :js do ...@@ -436,7 +437,9 @@ RSpec.describe 'Pipelines', :js do
context 'when user played a delayed job immediately' do context 'when user played a delayed job immediately' do
before do before do
find('[data-testid="pipelines-manual-actions-dropdown"]').click find('[data-testid="pipelines-manual-actions-dropdown"]').click
page.accept_confirm { click_button('delayed job 1') } accept_gl_confirm do
click_button 'delayed job 1'
end
wait_for_requests wait_for_requests
end end
......
...@@ -6,10 +6,16 @@ import waitForPromises from 'helpers/wait_for_promises'; ...@@ -6,10 +6,16 @@ import waitForPromises from 'helpers/wait_for_promises';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import PipelinesManualActions from '~/pipelines/components/pipelines_list/pipelines_manual_actions.vue'; import PipelinesManualActions from '~/pipelines/components/pipelines_list/pipelines_manual_actions.vue';
import GlCountdown from '~/vue_shared/components/gl_countdown.vue'; import GlCountdown from '~/vue_shared/components/gl_countdown.vue';
jest.mock('~/flash'); jest.mock('~/flash');
jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal', () => {
return {
confirmAction: jest.fn(),
};
});
describe('Pipelines Actions dropdown', () => { describe('Pipelines Actions dropdown', () => {
let wrapper; let wrapper;
...@@ -36,6 +42,7 @@ describe('Pipelines Actions dropdown', () => { ...@@ -36,6 +42,7 @@ describe('Pipelines Actions dropdown', () => {
wrapper = null; wrapper = null;
mock.restore(); mock.restore();
confirmAction.mockReset();
}); });
describe('manual actions', () => { describe('manual actions', () => {
...@@ -112,11 +119,11 @@ describe('Pipelines Actions dropdown', () => { ...@@ -112,11 +119,11 @@ describe('Pipelines Actions dropdown', () => {
it('makes post request after confirming', async () => { it('makes post request after confirming', async () => {
mock.onPost(scheduledJobAction.path).reply(200); mock.onPost(scheduledJobAction.path).reply(200);
jest.spyOn(window, 'confirm').mockReturnValue(true); confirmAction.mockResolvedValueOnce(true);
findAllDropdownItems().at(0).vm.$emit('click'); findAllDropdownItems().at(0).vm.$emit('click');
expect(window.confirm).toHaveBeenCalled(); expect(confirmAction).toHaveBeenCalled();
await waitForPromises(); await waitForPromises();
...@@ -125,11 +132,11 @@ describe('Pipelines Actions dropdown', () => { ...@@ -125,11 +132,11 @@ describe('Pipelines Actions dropdown', () => {
it('does not make post request if confirmation is cancelled', async () => { it('does not make post request if confirmation is cancelled', async () => {
mock.onPost(scheduledJobAction.path).reply(200); mock.onPost(scheduledJobAction.path).reply(200);
jest.spyOn(window, 'confirm').mockReturnValue(false); confirmAction.mockResolvedValueOnce(false);
findAllDropdownItems().at(0).vm.$emit('click'); findAllDropdownItems().at(0).vm.$emit('click');
expect(window.confirm).toHaveBeenCalled(); expect(confirmAction).toHaveBeenCalled();
await waitForPromises(); await waitForPromises();
......
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