Commit 40b809b8 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch...

Merge branch '229679-migrate-data-toggle-modal-to-glmodal-for-revert-cherry-picking-commits-3' into 'master'

[MR Page] Migrate to GlModal for revert MR

See merge request gitlab-org/gitlab!52019
parents 71479a3f 5a67bac8
...@@ -7,6 +7,7 @@ import initSortDiscussions from '../notes/sort_discussions'; ...@@ -7,6 +7,7 @@ import initSortDiscussions from '../notes/sort_discussions';
import MergeRequest from '../merge_request'; import MergeRequest from '../merge_request';
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack'; import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
import initNotesApp from './init_notes'; import initNotesApp from './init_notes';
import initRevertCommitModal from '~/projects/commit/init_revert_commit_modal';
export default function initMrNotes() { export default function initMrNotes() {
resetServiceWorkersPublicPath(); resetServiceWorkersPublicPath();
...@@ -19,6 +20,10 @@ export default function initMrNotes() { ...@@ -19,6 +20,10 @@ export default function initMrNotes() {
initNotesApp(); initNotesApp();
document.addEventListener('merged:UpdateActions', () => {
initRevertCommitModal();
});
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el: '#js-vue-discussion-counter', el: '#js-vue-discussion-counter',
......
...@@ -7,6 +7,8 @@ import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; ...@@ -7,6 +7,8 @@ import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import MrWidgetAuthorTime from '../mr_widget_author_time.vue'; import MrWidgetAuthorTime from '../mr_widget_author_time.vue';
import statusIcon from '../mr_widget_status_icon.vue'; import statusIcon from '../mr_widget_status_icon.vue';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
import modalEventHub from '~/projects/commit/event_hub';
import { OPEN_REVERT_MODAL } from '~/projects/commit/constants';
export default { export default {
name: 'MRWidgetMerged', name: 'MRWidgetMerged',
...@@ -77,6 +79,9 @@ export default { ...@@ -77,6 +79,9 @@ export default {
return s__('mrWidget|Cherry-pick'); return s__('mrWidget|Cherry-pick');
}, },
}, },
mounted() {
document.dispatchEvent(new CustomEvent('merged:UpdateActions'));
},
methods: { methods: {
removeSourceBranch() { removeSourceBranch() {
this.isMakingRequest = true; this.isMakingRequest = true;
...@@ -98,6 +103,9 @@ export default { ...@@ -98,6 +103,9 @@ export default {
Flash(__('Something went wrong. Please try again.')); Flash(__('Something went wrong. Please try again.'));
}); });
}, },
openRevertModal() {
modalEventHub.$emit(OPEN_REVERT_MODAL);
},
}, },
}; };
</script> </script>
...@@ -119,9 +127,7 @@ export default { ...@@ -119,9 +127,7 @@ export default {
size="small" size="small"
category="secondary" category="secondary"
variant="warning" variant="warning"
href="#modal-revert-commit" @click="openRevertModal"
data-toggle="modal"
data-container="body"
> >
{{ revertLabel }} {{ revertLabel }}
</gl-button> </gl-button>
......
...@@ -365,6 +365,7 @@ export default { ...@@ -365,6 +365,7 @@ export default {
const el = document.createElement('div'); const el = document.createElement('div');
el.innerHTML = res.data; el.innerHTML = res.data;
document.body.appendChild(el); document.body.appendChild(el);
document.dispatchEvent(new CustomEvent('merged:UpdateActions'));
Project.initRefSwitcher(); Project.initRefSwitcher();
} }
}) })
......
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
= render 'shared/issuable/sidebar', issuable_sidebar: @issuable_sidebar, assignees: @merge_request.assignees, reviewers: @merge_request.reviewers, source_branch: @merge_request.source_branch = render 'shared/issuable/sidebar', issuable_sidebar: @issuable_sidebar, assignees: @merge_request.assignees, reviewers: @merge_request.reviewers, source_branch: @merge_request.source_branch
- if @merge_request.can_be_reverted?(current_user) - if @merge_request.can_be_reverted?(current_user)
= render "projects/commit/change", type: 'revert', commit: @merge_request.merge_commit, title: @merge_request.title = render "projects/commit/change", type: 'revert', commit: @merge_request.merge_commit, pajamas: true
- if @merge_request.can_be_cherry_picked? - if @merge_request.can_be_cherry_picked?
= render "projects/commit/change", type: 'cherry-pick', commit: @merge_request.merge_commit, title: @merge_request.title = render "projects/commit/change", type: 'cherry-pick', commit: @merge_request.merge_commit, title: @merge_request.title
......
- if @merge_request.can_be_reverted?(current_user) - if @merge_request.can_be_reverted?(current_user)
= render "projects/commit/change", type: 'revert', commit: @merge_request.merge_commit, title: @merge_request.title = render "projects/commit/change", type: 'revert', commit: @merge_request.merge_commit, pajamas: true
- if @merge_request.can_be_cherry_picked? - if @merge_request.can_be_cherry_picked?
= render "projects/commit/change", type: 'cherry-pick', commit: @merge_request.merge_commit, title: @merge_request.title = render "projects/commit/change", type: 'cherry-pick', commit: @merge_request.merge_commit, title: @merge_request.title
---
title: "[MR Page] Migrate to GlModal for revert MR"
merge_request: 52019
author:
type: other
...@@ -17,46 +17,28 @@ RSpec.describe 'User reverts a merge request', :js do ...@@ -17,46 +17,28 @@ RSpec.describe 'User reverts a merge request', :js do
wait_for_requests wait_for_requests
visit(merge_request_path(merge_request)) # do not reload the page by visiting, let javascript update the page as it will validate we have loaded the modal
# code correctly on page update that adds the `revert` button
end end
it 'reverts a merge request', :sidekiq_might_not_need_inline do it 'reverts a merge request', :sidekiq_might_not_need_inline do
find("a[href='#modal-revert-commit']").click revert_commit
page.within('#modal-revert-commit') do wait_for_requests
uncheck('create_merge_request')
click_button('Revert')
end
expect(page).to have_content('The merge request has been successfully reverted.') expect(page).to have_content('The merge request has been successfully reverted.')
wait_for_requests
end end
it 'does not revert a merge request that was previously reverted', :sidekiq_might_not_need_inline do it 'does not revert a merge request that was previously reverted', :sidekiq_might_not_need_inline do
find("a[href='#modal-revert-commit']").click revert_commit
page.within('#modal-revert-commit') do
uncheck('create_merge_request')
click_button('Revert')
end
find("a[href='#modal-revert-commit']").click
page.within('#modal-revert-commit') do revert_commit
uncheck('create_merge_request')
click_button('Revert')
end
expect(page).to have_content('Sorry, we cannot revert this merge request automatically.') expect(page).to have_content('Sorry, we cannot revert this merge request automatically.')
end end
it 'reverts a merge request in a new merge request', :sidekiq_might_not_need_inline do it 'reverts a merge request in a new merge request', :sidekiq_might_not_need_inline do
find("a[href='#modal-revert-commit']").click revert_commit(create_merge_request: true)
page.within('#modal-revert-commit') do
click_button('Revert')
end
expect(page).to have_content('The merge request has been successfully reverted. You can now submit a merge request to get this change into the original branch.') expect(page).to have_content('The merge request has been successfully reverted. You can now submit a merge request to get this change into the original branch.')
end end
...@@ -68,4 +50,13 @@ RSpec.describe 'User reverts a merge request', :js do ...@@ -68,4 +50,13 @@ RSpec.describe 'User reverts a merge request', :js do
expect(page).not_to have_link('Revert') expect(page).not_to have_link('Revert')
end end
def revert_commit(create_merge_request: false)
click_button('Revert')
page.within('[data-testid="modal-commit"]') do
uncheck('create_merge_request') unless create_merge_request
click_button('Revert')
end
end
end end
...@@ -160,7 +160,7 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request', ...@@ -160,7 +160,7 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request',
it 'merges the merge request' do it 'merges the merge request' do
expect(page).to have_content('Merged by') expect(page).to have_content('Merged by')
expect(page).to have_link('Revert') expect(page).to have_button('Revert')
end end
end end
...@@ -357,7 +357,7 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request', ...@@ -357,7 +357,7 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request',
it 'merges the merge request' do it 'merges the merge request' do
expect(page).to have_content('Merged by') expect(page).to have_content('Merged by')
expect(page).to have_link('Revert') expect(page).to have_button('Revert')
end end
end end
......
...@@ -7,26 +7,33 @@ RSpec.describe 'Merge request > User sees revert modal', :js, :sidekiq_might_not ...@@ -7,26 +7,33 @@ RSpec.describe 'Merge request > User sees revert modal', :js, :sidekiq_might_not
let(:user) { project.creator } let(:user) { project.creator }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
shared_examples 'showing the revert modal' do
it 'shows the revert modal' do
click_button('Revert')
page.within('[data-testid="modal-commit"]') do
expect(page).to have_content 'Revert this merge request'
end
end
end
before do before do
sign_in(user) sign_in(user)
visit(project_merge_request_path(project, merge_request)) visit(project_merge_request_path(project, merge_request))
click_button('Merge') click_button('Merge')
wait_for_requests wait_for_requests
visit(merge_request_path(merge_request))
click_link('Revert')
end end
it 'shows the revert modal' do context 'without page reload after merge validates js correctly loaded' do
page.within('.modal-header') do it_behaves_like 'showing the revert modal'
expect(page).to have_content 'Revert this merge request'
end
end end
it 'closes the revert modal with escape keypress' do context 'with page reload validates js correctly loaded' do
find('#modal-revert-commit').send_keys(:escape) before do
visit(merge_request_path(merge_request))
end
expect(page).not_to have_selector('#modal-revert-commit', visible: true) it_behaves_like 'showing the revert modal'
end end
end end
import Vue from 'vue'; import Vue from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import { getByRole } from '@testing-library/dom';
import mergedComponent from '~/vue_merge_request_widget/components/states/mr_widget_merged.vue'; import mergedComponent from '~/vue_merge_request_widget/components/states/mr_widget_merged.vue';
import eventHub from '~/vue_merge_request_widget/event_hub'; import eventHub from '~/vue_merge_request_widget/event_hub';
import modalEventHub from '~/projects/commit/event_hub';
import { OPEN_REVERT_MODAL } from '~/projects/commit/constants';
describe('MRWidgetMerged', () => { describe('MRWidgetMerged', () => {
let vm; let vm;
...@@ -16,6 +19,7 @@ describe('MRWidgetMerged', () => { ...@@ -16,6 +19,7 @@ describe('MRWidgetMerged', () => {
}; };
beforeEach(() => { beforeEach(() => {
jest.spyOn(document, 'dispatchEvent');
const Component = Vue.extend(mergedComponent); const Component = Vue.extend(mergedComponent);
const mr = { const mr = {
isRemovingSourceBranch: false, isRemovingSourceBranch: false,
...@@ -147,6 +151,18 @@ describe('MRWidgetMerged', () => { ...@@ -147,6 +151,18 @@ describe('MRWidgetMerged', () => {
}); });
}); });
it('calls dispatchDocumentEvent to load in the modal component', () => {
expect(document.dispatchEvent).toHaveBeenCalledWith(new CustomEvent('merged:UpdateActions'));
});
it('emits event to open the revert modal on revert button click', () => {
const eventHubSpy = jest.spyOn(modalEventHub, '$emit');
getByRole(vm.$el, 'button', { name: /Revert/i }).click();
expect(eventHubSpy).toHaveBeenCalledWith(OPEN_REVERT_MODAL);
});
it('has merged by information', () => { it('has merged by information', () => {
expect(vm.$el.textContent).toContain('Merged by'); expect(vm.$el.textContent).toContain('Merged by');
expect(vm.$el.textContent).toContain('Administrator'); expect(vm.$el.textContent).toContain('Administrator');
......
...@@ -67,6 +67,7 @@ describe('MrWidgetOptions', () => { ...@@ -67,6 +67,7 @@ describe('MrWidgetOptions', () => {
describe('default', () => { describe('default', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(document, 'dispatchEvent');
return createComponent(); return createComponent();
}); });
...@@ -353,6 +354,9 @@ describe('MrWidgetOptions', () => { ...@@ -353,6 +354,9 @@ describe('MrWidgetOptions', () => {
return nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.vm.service.fetchMergeActionsContent).toHaveBeenCalled(); expect(wrapper.vm.service.fetchMergeActionsContent).toHaveBeenCalled();
expect(document.body.textContent).toContain('hello world'); expect(document.body.textContent).toContain('hello world');
expect(document.dispatchEvent).toHaveBeenCalledWith(
new CustomEvent('merged:UpdateActions'),
);
}); });
}); });
}); });
......
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