2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
2018-03-20 10:16:38 -04:00
|
|
|
import store from '~/ide/stores';
|
2018-05-01 07:57:26 -04:00
|
|
|
import router from '~/ide/ide_router';
|
2018-03-20 10:16:38 -04:00
|
|
|
import repoCommitSection from '~/ide/components/repo_commit_section.vue';
|
2018-03-20 10:12:48 -04:00
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import { file, resetStore } from '../helpers';
|
|
|
|
|
|
|
|
describe('RepoCommitSection', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
function createComponent() {
|
|
|
|
const Component = Vue.extend(repoCommitSection);
|
|
|
|
|
2018-04-17 11:27:46 -04:00
|
|
|
store.state.noChangesStateSvgPath = 'svg';
|
|
|
|
store.state.committedStateSvgPath = 'commitsvg';
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
vm.$store.state.currentProjectId = 'abcproject';
|
|
|
|
vm.$store.state.currentBranchId = 'master';
|
|
|
|
vm.$store.state.projects.abcproject = {
|
|
|
|
web_url: '',
|
|
|
|
branches: {
|
|
|
|
master: {
|
|
|
|
workingReference: '1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-03-21 06:05:08 -04:00
|
|
|
const files = [file('file1'), file('file2')].map(f =>
|
|
|
|
Object.assign(f, {
|
|
|
|
type: 'blob',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
vm.$store.state.rightPanelCollapsed = false;
|
|
|
|
vm.$store.state.currentBranch = 'master';
|
2018-03-21 06:05:08 -04:00
|
|
|
vm.$store.state.changedFiles = [...files];
|
2018-03-20 10:16:38 -04:00
|
|
|
vm.$store.state.changedFiles.forEach(f =>
|
2018-03-21 06:05:08 -04:00
|
|
|
Object.assign(f, {
|
|
|
|
changed: true,
|
|
|
|
content: 'changedFile testing',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
vm.$store.state.stagedFiles = [{ ...files[0] }, { ...files[1] }];
|
|
|
|
vm.$store.state.stagedFiles.forEach(f =>
|
2018-03-20 10:16:38 -04:00
|
|
|
Object.assign(f, {
|
|
|
|
changed: true,
|
|
|
|
content: 'testing',
|
|
|
|
}),
|
|
|
|
);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-03-21 08:43:59 -04:00
|
|
|
vm.$store.state.changedFiles.forEach(f => {
|
|
|
|
vm.$store.state.entries[f.path] = f;
|
|
|
|
});
|
|
|
|
|
2018-06-12 07:19:59 -04:00
|
|
|
return vm;
|
2018-03-20 10:12:48 -04:00
|
|
|
}
|
|
|
|
|
2018-03-20 10:16:38 -04:00
|
|
|
beforeEach(done => {
|
2018-05-01 07:57:26 -04:00
|
|
|
spyOn(router, 'push');
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
vm = createComponent();
|
|
|
|
|
2018-06-12 07:19:59 -04:00
|
|
|
spyOn(vm, 'openPendingTab').and.callThrough();
|
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
Vue.nextTick(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
|
|
|
|
resetStore(vm.$store);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('empty Stage', () => {
|
|
|
|
it('renders no changes text', () => {
|
|
|
|
resetStore(vm.$store);
|
|
|
|
const Component = Vue.extend(repoCommitSection);
|
|
|
|
|
2018-04-17 11:27:46 -04:00
|
|
|
store.state.noChangesStateSvgPath = 'nochangessvg';
|
|
|
|
store.state.committedStateSvgPath = 'svg';
|
|
|
|
|
2018-06-12 04:38:04 -04:00
|
|
|
vm.$destroy();
|
2018-04-17 11:27:46 -04:00
|
|
|
vm = createComponentWithStore(Component, store).$mount();
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('No changes');
|
|
|
|
expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('nochangessvg');
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a commit section', () => {
|
2018-06-13 04:44:14 -04:00
|
|
|
const changedFileElements = [...vm.$el.querySelectorAll('.multi-file-commit-list > li')];
|
2018-04-19 07:45:53 -04:00
|
|
|
const allFiles = vm.$store.state.changedFiles.concat(vm.$store.state.stagedFiles);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-03-21 06:05:08 -04:00
|
|
|
expect(changedFileElements.length).toEqual(4);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
changedFileElements.forEach((changedFile, i) => {
|
2018-03-21 06:05:08 -04:00
|
|
|
expect(changedFile.textContent.trim()).toContain(allFiles[i].path);
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-21 06:05:08 -04:00
|
|
|
it('adds changed files into staged files', done => {
|
2018-04-27 12:55:39 -04:00
|
|
|
vm.$el.querySelector('.multi-file-discard-btn .btn').click();
|
|
|
|
vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => vm.$el.querySelector('.multi-file-discard-btn .btn').click())
|
|
|
|
.then(vm.$nextTick)
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.$el.querySelector('.ide-commit-list-container').textContent).toContain(
|
|
|
|
'No changes',
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-03-21 06:05:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('stages a single file', done => {
|
|
|
|
vm.$el.querySelector('.multi-file-discard-btn .btn').click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-06-13 04:44:14 -04:00
|
|
|
expect(
|
|
|
|
vm.$el
|
|
|
|
.querySelector('.ide-commit-list-container')
|
|
|
|
.querySelectorAll('.multi-file-commit-list > li').length,
|
|
|
|
).toBe(1);
|
2018-03-21 06:05:08 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('discards a single file', done => {
|
2018-06-13 04:44:14 -04:00
|
|
|
vm.$el.querySelector('.multi-file-discard-btn .dropdown-menu button').click();
|
2018-03-21 06:05:08 -04:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-04-19 07:45:53 -04:00
|
|
|
expect(vm.$el.querySelector('.ide-commit-list-container').textContent).not.toContain('file1');
|
2018-06-13 04:44:14 -04:00
|
|
|
expect(
|
|
|
|
vm.$el
|
|
|
|
.querySelector('.ide-commit-list-container')
|
|
|
|
.querySelectorAll('.multi-file-commit-list > li').length,
|
|
|
|
).toBe(1);
|
2018-03-21 06:05:08 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('unstages a single file', done => {
|
|
|
|
vm.$el
|
|
|
|
.querySelectorAll('.multi-file-discard-btn')[2]
|
|
|
|
.querySelector('.btn')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
2018-04-19 07:45:53 -04:00
|
|
|
vm.$el.querySelectorAll('.ide-commit-list-container')[1].querySelectorAll('li').length,
|
2018-03-21 06:05:08 -04:00
|
|
|
).toBe(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-01 07:57:26 -04:00
|
|
|
|
|
|
|
describe('mounted', () => {
|
|
|
|
it('opens last opened file', () => {
|
|
|
|
expect(store.state.openFiles.length).toBe(1);
|
|
|
|
expect(store.state.openFiles[0].pending).toBe(true);
|
|
|
|
});
|
2018-06-12 06:46:00 -04:00
|
|
|
|
|
|
|
it('calls openPendingTab', () => {
|
|
|
|
expect(vm.openPendingTab).toHaveBeenCalledWith({
|
|
|
|
file: vm.lastOpenedFile,
|
|
|
|
keyPrefix: 'unstaged',
|
|
|
|
});
|
|
|
|
});
|
2018-05-01 07:57:26 -04:00
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|