2019-02-13 22:33:31 +05:30
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2018-12-05 23:21:45 +05:30
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
|
|
|
import App from '~/diffs/components/app.vue';
|
2019-02-13 22:33:31 +05:30
|
|
|
import NoChanges from '~/diffs/components/no_changes.vue';
|
|
|
|
import DiffFile from '~/diffs/components/diff_file.vue';
|
2018-12-05 23:21:45 +05:30
|
|
|
import createDiffsStore from '../create_diffs_store';
|
|
|
|
|
|
|
|
describe('diffs/components/app', () => {
|
|
|
|
const oldMrTabs = window.mrTabs;
|
2019-02-13 22:33:31 +05:30
|
|
|
let store;
|
2018-12-05 23:21:45 +05:30
|
|
|
let vm;
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
function createComponent(props = {}, extendStore = () => {}) {
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
store = createDiffsStore();
|
2018-12-05 23:21:45 +05:30
|
|
|
store.state.diffs.isLoading = false;
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
extendStore(store);
|
|
|
|
|
|
|
|
vm = shallowMount(localVue.extend(App), {
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
2018-12-05 23:21:45 +05:30
|
|
|
endpoint: `${TEST_HOST}/diff/endpoint`,
|
|
|
|
projectPath: 'namespace/project',
|
|
|
|
currentUser: {},
|
2019-02-13 22:33:31 +05:30
|
|
|
changesEmptyStateIllustration: '',
|
|
|
|
...props,
|
2018-12-05 23:21:45 +05:30
|
|
|
},
|
2019-02-13 22:33:31 +05:30
|
|
|
store,
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
2019-02-13 22:33:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// setup globals (needed for component to mount :/)
|
|
|
|
window.mrTabs = jasmine.createSpyObj('mrTabs', ['resetViewContainer']);
|
|
|
|
window.mrTabs.expandViewContainer = jasmine.createSpy();
|
|
|
|
window.location.hash = 'ABC_123';
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
// reset globals
|
|
|
|
window.mrTabs = oldMrTabs;
|
|
|
|
|
|
|
|
// reset component
|
2019-02-13 22:33:31 +05:30
|
|
|
vm.destroy();
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show commit info', () => {
|
2019-02-13 22:33:31 +05:30
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(vm.contains('.blob-commit-info')).toBe(false);
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
it('sets highlighted row if hash exists in location object', done => {
|
|
|
|
createComponent({
|
|
|
|
shouldShow: true,
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
// Component uses $nextTick so we wait until that has finished
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(store.state.diffs.highlightedRow).toBe('ABC_123');
|
2019-01-03 12:48:30 +05:30
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
done();
|
|
|
|
});
|
2019-01-03 12:48:30 +05:30
|
|
|
});
|
|
|
|
|
2019-02-13 22:33:31 +05:30
|
|
|
describe('empty state', () => {
|
|
|
|
it('renders empty state when no diff files exist', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(vm.contains(NoChanges)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render empty state when diff files exist', () => {
|
|
|
|
createComponent({}, () => {
|
|
|
|
store.state.diffs.diffFiles.push({
|
|
|
|
id: 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.contains(NoChanges)).toBe(false);
|
|
|
|
expect(vm.findAll(DiffFile).length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render empty state when versions match', () => {
|
|
|
|
createComponent({}, () => {
|
|
|
|
store.state.diffs.startVersion = { version_index: 1 };
|
|
|
|
store.state.diffs.mergeRequestDiff = { version_index: 1 };
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.contains(NoChanges)).toBe(false);
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
});
|