debian-mirror-gitlab/spec/javascripts/diffs/components/compare_versions_spec.js

146 lines
5 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
import Vue from 'vue';
import CompareVersionsComponent from '~/diffs/components/compare_versions.vue';
2019-10-12 21:52:04 +05:30
import { createStore } from '~/mr_notes/stores';
2018-12-13 13:39:08 +05:30
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffsMockData from '../mock_data/merge_request_diffs';
2019-02-15 15:39:39 +05:30
import getDiffWithCommit from '../mock_data/diff_with_commit';
2018-12-13 13:39:08 +05:30
describe('CompareVersions', () => {
let vm;
const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 };
beforeEach(() => {
2019-10-12 21:52:04 +05:30
const store = createStore();
2019-03-02 22:35:43 +05:30
store.state.diffs.addedLines = 10;
store.state.diffs.removedLines = 20;
store.state.diffs.diffFiles.push('test');
2018-12-13 13:39:08 +05:30
vm = createComponentWithStore(Vue.extend(CompareVersionsComponent), store, {
mergeRequestDiffs: diffsMockData,
mergeRequestDiff: diffsMockData[0],
targetBranch,
}).$mount();
});
describe('template', () => {
it('should render Tree List toggle button with correct attribute values', () => {
const treeListBtn = vm.$el.querySelector('.js-toggle-tree-list');
expect(treeListBtn).not.toBeNull();
2019-03-02 22:35:43 +05:30
expect(treeListBtn.dataset.originalTitle).toBe('Hide file browser');
2018-12-13 13:39:08 +05:30
expect(treeListBtn.querySelectorAll('svg use').length).not.toBe(0);
expect(treeListBtn.querySelector('svg use').getAttribute('xlink:href')).toContain(
2019-03-02 22:35:43 +05:30
'#collapse-left',
2018-12-13 13:39:08 +05:30
);
});
it('should render comparison dropdowns with correct values', () => {
const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown');
const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown');
expect(sourceDropdown).not.toBeNull();
expect(targetDropdown).not.toBeNull();
expect(sourceDropdown.querySelector('a span').innerHTML).toContain('latest version');
expect(targetDropdown.querySelector('a span').innerHTML).toContain(targetBranch.branchName);
});
it('should not render comparison dropdowns if no mergeRequestDiffs are specified', () => {
vm.mergeRequestDiffs = [];
vm.$nextTick(() => {
const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown');
const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown');
expect(sourceDropdown).toBeNull();
expect(targetDropdown).toBeNull();
});
});
it('should render view types buttons with correct values', () => {
const inlineBtn = vm.$el.querySelector('#inline-diff-btn');
const parallelBtn = vm.$el.querySelector('#parallel-diff-btn');
expect(inlineBtn).not.toBeNull();
expect(parallelBtn).not.toBeNull();
expect(inlineBtn.dataset.viewType).toEqual('inline');
expect(parallelBtn.dataset.viewType).toEqual('parallel');
expect(inlineBtn.innerHTML).toContain('Inline');
expect(parallelBtn.innerHTML).toContain('Side-by-side');
});
2019-07-07 11:18:12 +05:30
it('adds container-limiting classes when showFileTree is false with inline diffs', () => {
vm.isLimitedContainer = true;
vm.$nextTick(() => {
const limitedContainer = vm.$el.querySelector('.container-limited.limit-container-width');
expect(limitedContainer).not.toBeNull();
});
});
it('does not add container-limiting classes when showFileTree is false with inline diffs', () => {
vm.isLimitedContainer = false;
vm.$nextTick(() => {
const limitedContainer = vm.$el.querySelector('.container-limited.limit-container-width');
expect(limitedContainer).toBeNull();
});
});
2018-12-13 13:39:08 +05:30
});
describe('setInlineDiffViewType', () => {
it('should persist the view type in the url', () => {
const viewTypeBtn = vm.$el.querySelector('#inline-diff-btn');
viewTypeBtn.click();
expect(window.location.toString()).toContain('?view=inline');
});
});
describe('setParallelDiffViewType', () => {
it('should persist the view type in the url', () => {
const viewTypeBtn = vm.$el.querySelector('#parallel-diff-btn');
viewTypeBtn.click();
expect(window.location.toString()).toContain('?view=parallel');
});
});
describe('comparableDiffs', () => {
it('should not contain the first item in the mergeRequestDiffs property', () => {
const { comparableDiffs } = vm;
const comparableDiffsMock = diffsMockData.slice(1);
expect(comparableDiffs).toEqual(comparableDiffsMock);
});
});
2019-03-02 22:35:43 +05:30
describe('baseVersionPath', () => {
it('should be set correctly from mergeRequestDiff', () => {
expect(vm.baseVersionPath).toEqual(vm.mergeRequestDiff.base_version_path);
2018-12-13 13:39:08 +05:30
});
});
2019-02-15 15:39:39 +05:30
describe('commit', () => {
beforeEach(done => {
vm.$store.state.diffs.commit = getDiffWithCommit().commit;
vm.mergeRequestDiffs = [];
vm.$nextTick(done);
});
it('renders latest version button', () => {
expect(vm.$el.querySelector('.js-latest-version').textContent.trim()).toBe(
'Show latest version',
);
});
it('renders short commit ID', () => {
expect(vm.$el.textContent).toContain('Viewing commit');
expect(vm.$el.textContent).toContain(vm.commit.short_id);
});
});
2018-12-13 13:39:08 +05:30
});