2021-03-11 19:13:27 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { createLocalVue, shallowMount, mount } from '@vue/test-utils';
|
2019-02-15 15:39:39 +05:30
|
|
|
import Vuex from 'vuex';
|
|
|
|
import NoChanges from '~/diffs/components/no_changes.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2021-03-08 18:12:59 +05:30
|
|
|
import diffsMockData from '../mock_data/merge_request_diffs';
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const TEST_TARGET_BRANCH = 'foo';
|
|
|
|
const TEST_SOURCE_BRANCH = 'dev/update';
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('Diff no changes empty state', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
function createComponent(mountFn = shallowMount) {
|
|
|
|
wrapper = mountFn(NoChanges, {
|
2019-02-15 15:39:39 +05:30
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
changesEmptyStateIllustration: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
store.state.diffs.mergeRequestDiff = {};
|
|
|
|
store.state.notes.noteableData = {
|
|
|
|
target_branch: TEST_TARGET_BRANCH,
|
|
|
|
source_branch: TEST_SOURCE_BRANCH,
|
|
|
|
};
|
|
|
|
store.state.diffs.mergeRequestDiffs = diffsMockData;
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
afterEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const findMessage = () => wrapper.find('[data-testid="no-changes-message"]');
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('prevents XSS', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
store.state.notes.noteableData = {
|
|
|
|
source_branch: '<script>alert("test");</script>',
|
|
|
|
target_branch: '<script>alert("test");</script>',
|
|
|
|
};
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find('script').exists()).toBe(false);
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
describe('Renders', () => {
|
|
|
|
it('Show create commit button', () => {
|
|
|
|
createComponent();
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
expect(wrapper.find(GlButton).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
it.each`
|
|
|
|
expectedText | sourceIndex | targetIndex
|
|
|
|
${`No changes between ${TEST_SOURCE_BRANCH} and ${TEST_TARGET_BRANCH}`} | ${null} | ${null}
|
|
|
|
${`No changes between ${TEST_SOURCE_BRANCH} and version 1`} | ${diffsMockData[0].version_index} | ${1}
|
|
|
|
${`No changes between version 3 and version 2`} | ${3} | ${2}
|
|
|
|
${`No changes between version 3 and ${TEST_TARGET_BRANCH}`} | ${3} | ${-1}
|
|
|
|
`(
|
|
|
|
'renders text "$expectedText" (sourceIndex=$sourceIndex and targetIndex=$targetIndex)',
|
|
|
|
({ expectedText, targetIndex, sourceIndex }) => {
|
|
|
|
if (targetIndex !== null) {
|
|
|
|
store.state.diffs.startVersion = { version_index: targetIndex };
|
|
|
|
}
|
|
|
|
if (sourceIndex !== null) {
|
|
|
|
store.state.diffs.mergeRequestDiff.version_index = sourceIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
createComponent(mount);
|
|
|
|
|
|
|
|
expect(findMessage().text()).toBe(expectedText);
|
|
|
|
},
|
|
|
|
);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|