2021-03-08 18:12:59 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-03-08 18:12:59 +05:30
|
|
|
import WidgetRebase from '~/vue_merge_request_widget/components/states/mr_widget_rebase.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import eventHub from '~/vue_merge_request_widget/event_hub';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function factory(propsData, mergeRequestWidgetGraphql) {
|
|
|
|
wrapper = shallowMount(WidgetRebase, {
|
|
|
|
propsData,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
state: {
|
|
|
|
rebaseInProgress: propsData.mr.rebaseInProgress,
|
|
|
|
targetBranch: propsData.mr.targetBranch,
|
|
|
|
userPermissions: {
|
|
|
|
pushToSourceBranch: propsData.mr.canPushToSourceBranch,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
provide: { glFeatures: { mergeRequestWidgetGraphql } },
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
state: { loading: false },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('Merge request widget rebase component', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
const findRebaseMessageEl = () => wrapper.find('[data-testid="rebase-message"]');
|
|
|
|
const findRebaseMessageElText = () => findRebaseMessageEl().text();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
[true, false].forEach((mergeRequestWidgetGraphql) => {
|
|
|
|
describe(`widget graphql is ${mergeRequestWidgetGraphql ? 'enabled' : 'dislabed'}`, () => {
|
|
|
|
describe('While rebasing', () => {
|
|
|
|
it('should show progress message', () => {
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: { rebaseInProgress: true },
|
|
|
|
service: {},
|
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(findRebaseMessageElText()).toContain('Rebase in progress');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('With permissions', () => {
|
|
|
|
it('it should render rebase button and warning message', () => {
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: {
|
|
|
|
rebaseInProgress: false,
|
|
|
|
canPushToSourceBranch: true,
|
|
|
|
},
|
|
|
|
service: {},
|
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
|
|
|
|
|
|
|
const text = findRebaseMessageElText();
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(text).toContain('Merge blocked');
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(text.replace(/\s\s+/g, ' ')).toContain(
|
2021-09-30 23:02:18 +05:30
|
|
|
'the source branch must be rebased onto the target branch',
|
2021-03-08 18:12:59 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('it should render error message when it fails', async () => {
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: {
|
|
|
|
rebaseInProgress: false,
|
|
|
|
canPushToSourceBranch: true,
|
|
|
|
},
|
|
|
|
service: {},
|
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.setData({ rebasingError: 'Something went wrong!' });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findRebaseMessageElText()).toContain('Something went wrong!');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('Without permissions', () => {
|
|
|
|
it('should render a message explaining user does not have permissions', () => {
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: {
|
|
|
|
rebaseInProgress: false,
|
|
|
|
canPushToSourceBranch: false,
|
|
|
|
targetBranch: 'foo',
|
|
|
|
},
|
|
|
|
service: {},
|
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
|
|
|
|
|
|
|
const text = findRebaseMessageElText();
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(text).toContain(
|
|
|
|
'Merge blocked: the source branch must be rebased onto the target branch.',
|
2021-03-08 18:12:59 +05:30
|
|
|
);
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(text).toContain('the source branch must be rebased');
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the correct target branch name', () => {
|
|
|
|
const targetBranch = 'fake-branch-to-test-with';
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: {
|
|
|
|
rebaseInProgress: false,
|
|
|
|
canPushToSourceBranch: false,
|
|
|
|
targetBranch,
|
|
|
|
},
|
|
|
|
service: {},
|
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const elem = findRebaseMessageEl();
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(elem.text()).toContain(
|
2021-09-30 23:02:18 +05:30
|
|
|
`Merge blocked: the source branch must be rebased onto the target branch.`,
|
2021-03-08 18:12:59 +05:30
|
|
|
);
|
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('methods', () => {
|
|
|
|
it('checkRebaseStatus', async () => {
|
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
|
|
|
factory(
|
|
|
|
{
|
|
|
|
mr: {},
|
|
|
|
service: {
|
|
|
|
rebase() {
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
|
|
|
poll() {
|
|
|
|
return Promise.resolve({
|
|
|
|
data: {
|
|
|
|
rebase_in_progress: false,
|
|
|
|
merge_error: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
|
|
|
mergeRequestWidgetGraphql,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.vm.rebase();
|
|
|
|
|
|
|
|
// Wait for the rebase request
|
|
|
|
await nextTick();
|
|
|
|
// Wait for the polling request
|
|
|
|
await nextTick();
|
|
|
|
// Wait for the eventHub to be called
|
|
|
|
await nextTick();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetRebaseSuccess');
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|