2018-06-21 08:22:40 -04:00
|
|
|
import Vue from 'vue';
|
2018-07-09 10:40:48 -04:00
|
|
|
import Vuex from 'vuex';
|
2018-06-21 08:22:40 -04:00
|
|
|
import { mountComponentWithStore } from 'spec/helpers';
|
2018-07-09 10:40:48 -04:00
|
|
|
import diffsModule from '~/diffs/store/modules';
|
|
|
|
import changedFiles from '~/diffs/components/changed_files.vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
describe('ChangedFiles', () => {
|
2018-07-09 10:40:48 -04:00
|
|
|
const Component = Vue.extend(changedFiles);
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
diffs: diffsModule,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div id="dummy-element"></div>
|
|
|
|
<div class="js-tabs-affix"></div>
|
|
|
|
`);
|
2018-07-09 10:40:48 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
const props = {
|
|
|
|
diffFiles: [
|
|
|
|
{
|
|
|
|
addedLines: 10,
|
|
|
|
removedLines: 20,
|
|
|
|
blob: {
|
|
|
|
path: 'some/code.txt',
|
|
|
|
},
|
|
|
|
filePath: 'some/code.txt',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2018-07-09 10:40:48 -04:00
|
|
|
|
|
|
|
vm = mountComponentWithStore(Component, { props, store });
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with single file added', () => {
|
|
|
|
it('shows files changes', () => {
|
|
|
|
expect(vm.$el).toContainText('1 changed file');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows file additions and deletions', () => {
|
|
|
|
expect(vm.$el).toContainText('10 additions');
|
|
|
|
expect(vm.$el).toContainText('20 deletions');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
describe('diff view mode buttons', () => {
|
|
|
|
let inlineButton;
|
|
|
|
let parallelButton;
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
inlineButton = vm.$el.querySelector('.js-inline-diff-button');
|
|
|
|
parallelButton = vm.$el.querySelector('.js-parallel-diff-button');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have Inline and Side-by-side buttons', () => {
|
|
|
|
expect(inlineButton).toBeDefined();
|
|
|
|
expect(parallelButton).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add active class to Inline button', done => {
|
|
|
|
vm.$store.state.diffs.diffViewType = 'inline';
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(inlineButton.classList.contains('active')).toEqual(true);
|
|
|
|
expect(parallelButton.classList.contains('active')).toEqual(false);
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
done();
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2018-07-09 10:40:48 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
it('should toggle active state of buttons when diff view type changed', done => {
|
|
|
|
vm.$store.state.diffs.diffViewType = 'parallel';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(inlineButton.classList.contains('active')).toEqual(false);
|
|
|
|
expect(parallelButton.classList.contains('active')).toEqual(true);
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
done();
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
2018-07-09 10:40:48 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
describe('clicking them', () => {
|
|
|
|
it('should toggle the diff view type', done => {
|
|
|
|
parallelButton.click();
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(inlineButton.classList.contains('active')).toEqual(false);
|
|
|
|
expect(parallelButton.classList.contains('active')).toEqual(true);
|
|
|
|
|
2018-07-09 10:40:48 -04:00
|
|
|
inlineButton.click();
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2018-07-09 10:40:48 -04:00
|
|
|
expect(inlineButton.classList.contains('active')).toEqual(true);
|
|
|
|
expect(parallelButton.classList.contains('active')).toEqual(false);
|
|
|
|
done();
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|