2022-03-11 21:07:59 +00:00
|
|
|
import { GlModal } from '@gitlab/ui';
|
2020-11-20 18:09:37 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import MrWidgetHowToMergeModal from '~/vue_merge_request_widget/components/mr_widget_how_to_merge_modal.vue';
|
|
|
|
|
|
|
|
describe('MRWidgetHowToMerge', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function mountComponent({ data = {}, props = {} } = {}) {
|
|
|
|
wrapper = shallowMount(MrWidgetHowToMergeModal, {
|
|
|
|
data() {
|
2021-09-30 18:11:31 +00:00
|
|
|
return data;
|
2020-11-20 18:09:37 +00:00
|
|
|
},
|
2021-09-30 18:11:31 +00:00
|
|
|
propsData: props,
|
2020-11-20 18:09:37 +00:00
|
|
|
stubs: {},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent();
|
|
|
|
});
|
|
|
|
|
2022-09-21 15:14:09 +00:00
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
2020-11-20 18:09:37 +00:00
|
|
|
const findInstructionsFields = () =>
|
|
|
|
wrapper.findAll('[ data-testid="how-to-merge-instructions"]');
|
2022-03-11 21:07:59 +00:00
|
|
|
const findTipLink = () => wrapper.find("[data-testid='docs-tip']");
|
2020-11-20 18:09:37 +00:00
|
|
|
|
|
|
|
it('renders a modal', () => {
|
|
|
|
expect(findModal().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a selection of markdown fields', () => {
|
|
|
|
expect(findInstructionsFields().length).toBe(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a tip including a link to docs when a valid link is present', () => {
|
|
|
|
mountComponent({ props: { reviewingDocsPath: '/gitlab-org/help' } });
|
|
|
|
expect(findTipLink().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render a tip including a link to docs when a valid link is not present', () => {
|
|
|
|
expect(findTipLink().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render different instructions based on if the user can merge', () => {
|
|
|
|
mountComponent({ props: { canMerge: true } });
|
2020-12-23 12:10:26 +00:00
|
|
|
expect(findInstructionsFields().at(2).text()).toContain('git push origin');
|
2020-11-20 18:09:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render different instructions based on if the merge is based off a fork', () => {
|
|
|
|
mountComponent({ props: { isFork: true } });
|
2020-12-23 12:10:26 +00:00
|
|
|
expect(findInstructionsFields().at(0).text()).toContain('FETCH_HEAD');
|
2020-11-20 18:09:37 +00:00
|
|
|
});
|
2021-09-30 18:11:31 +00:00
|
|
|
|
|
|
|
it('escapes the target branch name shell-secure', () => {
|
|
|
|
mountComponent({ props: { targetBranch: '";echo$IFS"you_shouldnt_run_this' } });
|
|
|
|
|
|
|
|
expect(findInstructionsFields().at(1).text()).toContain('\'";echo$IFS"you_shouldnt_run_this\'');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('escapes the source branch name shell-secure', () => {
|
|
|
|
mountComponent({ props: { sourceBranch: 'branch-of-$USER' } });
|
|
|
|
|
|
|
|
expect(findInstructionsFields().at(0).text()).toContain("'branch-of-$USER'");
|
|
|
|
});
|
2020-11-20 18:09:37 +00:00
|
|
|
});
|