Commit af22ddaf authored by Phil Hughes's avatar Phil Hughes

updated file references in specs

parent f527e6e1
......@@ -30,9 +30,9 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => {
const currentProject = rootState.projects[rootState.currentProjectId];
const commitStats = data.stats
? sprintf(__('with %{additions} additions, %{deletions} deletions.'), {
additions: data.stats.additions,
deletions: data.stats.deletions,
})
additions: data.stats.additions, // eslint-disable-line indent
deletions: data.stats.deletions, // eslint-disable-line indent
}) // eslint-disable-line indent
: '';
const commitMsg = sprintf(
__('Your changes have been committed. Commit %{commitId} %{commitStats}'),
......
import Vue from 'vue';
import changedFileIcon from 'ee/ide/components/changed_file_icon.vue';
import changedFileIcon from '~/ide/components/changed_file_icon.vue';
import createComponent from 'spec/helpers/vue_mount_component_helper';
describe('IDE changed file icon', () => {
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import commitActions from 'ee/ide/components/commit_sidebar/actions.vue';
import store from '~/ide/stores';
import commitActions from '~/ide/components/commit_sidebar/actions.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from 'spec/ide/helpers';
describe('IDE commit sidebar actions', () => {
let vm;
beforeEach((done) => {
beforeEach(done => {
const Component = Vue.extend(commitActions);
vm = createComponentWithStore(Component, store);
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import listCollapsed from 'ee/ide/components/commit_sidebar/list_collapsed.vue';
import store from '~/ide/stores';
import listCollapsed from '~/ide/components/commit_sidebar/list_collapsed.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file } from '../../helpers';
......
import Vue from 'vue';
import listItem from 'ee/ide/components/commit_sidebar/list_item.vue';
import router from 'ee/ide/ide_router';
import listItem from '~/ide/components/commit_sidebar/list_item.vue';
import router from '~/ide/ide_router';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { file } from '../../helpers';
......@@ -23,7 +23,9 @@ describe('Multi-file editor commit sidebar list item', () => {
});
it('renders file path', () => {
expect(vm.$el.querySelector('.multi-file-commit-list-path').textContent.trim()).toBe(f.path);
expect(
vm.$el.querySelector('.multi-file-commit-list-path').textContent.trim(),
).toBe(f.path);
});
it('calls discardFileChanges when clicking discard button', () => {
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import commitSidebarList from 'ee/ide/components/commit_sidebar/list.vue';
import store from '~/ide/stores';
import commitSidebarList from '~/ide/components/commit_sidebar/list.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file } from '../../helpers';
......@@ -25,7 +25,7 @@ describe('Multi-file editor commit sidebar list', () => {
});
describe('with a list of files', () => {
beforeEach((done) => {
beforeEach(done => {
const f = file('file name');
f.changed = true;
vm.fileList.push(f);
......@@ -39,7 +39,7 @@ describe('Multi-file editor commit sidebar list', () => {
});
describe('collapsed', () => {
beforeEach((done) => {
beforeEach(done => {
vm.$store.state.rightPanelCollapsed = true;
Vue.nextTick(done);
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import radioGroup from 'ee/ide/components/commit_sidebar/radio_group.vue';
import store from '~/ide/stores';
import radioGroup from '~/ide/components/commit_sidebar/radio_group.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from 'spec/ide/helpers';
describe('IDE commit sidebar radio group', () => {
let vm;
beforeEach((done) => {
beforeEach(done => {
const Component = Vue.extend(radioGroup);
store.state.commit.commitAction = '2';
......@@ -33,7 +33,7 @@ describe('IDE commit sidebar radio group', () => {
expect(vm.$el.textContent).toContain('test');
});
it('uses slot if label is not present', (done) => {
it('uses slot if label is not present', done => {
vm.$destroy();
vm = new Vue({
......@@ -59,7 +59,7 @@ describe('IDE commit sidebar radio group', () => {
});
});
it('updates store when changing radio button', (done) => {
it('updates store when changing radio button', done => {
vm.$el.querySelector('input').dispatchEvent(new Event('change'));
Vue.nextTick(() => {
......@@ -69,7 +69,7 @@ describe('IDE commit sidebar radio group', () => {
});
});
it('renders helpText tooltip', (done) => {
it('renders helpText tooltip', done => {
vm.helpText = 'help text';
Vue.nextTick(() => {
......@@ -83,7 +83,7 @@ describe('IDE commit sidebar radio group', () => {
});
describe('with input', () => {
beforeEach((done) => {
beforeEach(done => {
vm.$destroy();
const Component = Vue.extend(radioGroup);
......@@ -106,7 +106,7 @@ describe('IDE commit sidebar radio group', () => {
expect(vm.$el.querySelector('.form-control')).not.toBeNull();
});
it('hides input when commitAction doesnt match value', (done) => {
it('hides input when commitAction doesnt match value', done => {
store.state.commit.commitAction = '2';
Vue.nextTick(() => {
......@@ -115,7 +115,7 @@ describe('IDE commit sidebar radio group', () => {
});
});
it('updates branch name in store on input', (done) => {
it('updates branch name in store on input', done => {
const input = vm.$el.querySelector('.form-control');
input.value = 'testing-123';
input.dispatchEvent(new Event('input'));
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import ideContextBar from 'ee/ide/components/ide_context_bar.vue';
import store from '~/ide/stores';
import ideContextBar from '~/ide/components/ide_context_bar.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
describe('Multi-file editor right context bar', () => {
......@@ -24,7 +24,7 @@ describe('Multi-file editor right context bar', () => {
});
describe('collapsed', () => {
beforeEach((done) => {
beforeEach(done => {
vm.$store.state.rightPanelCollapsed = true;
Vue.nextTick(done);
......
import Vue from 'vue';
import ideExternalLinks from 'ee/ide/components/ide_external_links.vue';
import ideExternalLinks from '~/ide/components/ide_external_links.vue';
import createComponent from 'spec/helpers/vue_mount_component_helper';
describe('ide external links component', () => {
......
import Vue from 'vue';
import ideRepoTree from 'ee/ide/components/ide_repo_tree.vue';
import ideRepoTree from '~/ide/components/ide_repo_tree.vue';
import createComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
......@@ -29,11 +29,13 @@ describe('IdeRepoTree', () => {
expect(vm.$el.querySelector('.file')).not.toBeNull();
});
it('renders 3 loading files if tree is loading', (done) => {
it('renders 3 loading files if tree is loading', done => {
tree.loading = true;
vm.$nextTick(() => {
expect(vm.$el.querySelectorAll('.multi-file-loading-container').length).toEqual(3);
expect(
vm.$el.querySelectorAll('.multi-file-loading-container').length,
).toEqual(3);
done();
});
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import ideSidebar from 'ee/ide/components/ide_side_bar.vue';
import store from '~/ide/stores';
import ideSidebar from '~/ide/components/ide_side_bar.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../helpers';
......@@ -20,15 +20,21 @@ describe('IdeSidebar', () => {
});
it('renders a sidebar', () => {
expect(vm.$el.querySelector('.multi-file-commit-panel-inner')).not.toBeNull();
expect(
vm.$el.querySelector('.multi-file-commit-panel-inner'),
).not.toBeNull();
});
it('renders loading icon component', (done) => {
it('renders loading icon component', done => {
vm.$store.state.loading = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.multi-file-loading-container')).not.toBeNull();
expect(vm.$el.querySelectorAll('.multi-file-loading-container').length).toBe(3);
expect(
vm.$el.querySelector('.multi-file-loading-container'),
).not.toBeNull();
expect(
vm.$el.querySelectorAll('.multi-file-loading-container').length,
).toBe(3);
done();
});
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import ide from 'ee/ide/components/ide.vue';
import store from '~/ide/stores';
import ide from '~/ide/components/ide.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file, resetStore } from '../helpers';
......@@ -27,7 +27,7 @@ describe('ide component', () => {
expect(vm.$el.querySelector('.panel-right')).toBeNull();
});
it('renders panel right when files are open', (done) => {
it('renders panel right when files are open', done => {
vm.$store.state.trees['abcproject/mybranch'] = {
tree: [file()],
};
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import newDropdown from 'ee/ide/components/new_dropdown/index.vue';
import store from '~/ide/stores';
import newDropdown from '~/ide/components/new_dropdown/index.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../../helpers';
......
import Vue from 'vue';
import modal from 'ee/ide/components/new_dropdown/modal.vue';
import modal from '~/ide/components/new_dropdown/modal.vue';
import createComponent from 'spec/helpers/vue_mount_component_helper';
describe('new file modal component', () => {
......@@ -10,7 +10,7 @@ describe('new file modal component', () => {
vm.$destroy();
});
['tree', 'blob'].forEach((type) => {
['tree', 'blob'].forEach(type => {
describe(type, () => {
beforeEach(() => {
vm = createComponent(Component, {
......@@ -25,19 +25,25 @@ describe('new file modal component', () => {
it(`sets modal title as ${type}`, () => {
const title = type === 'tree' ? 'directory' : 'file';
expect(vm.$el.querySelector('.modal-title').textContent.trim()).toBe(`Create new ${title}`);
expect(vm.$el.querySelector('.modal-title').textContent.trim()).toBe(
`Create new ${title}`,
);
});
it(`sets button label as ${type}`, () => {
const title = type === 'tree' ? 'directory' : 'file';
expect(vm.$el.querySelector('.btn-success').textContent.trim()).toBe(`Create ${title}`);
expect(vm.$el.querySelector('.btn-success').textContent.trim()).toBe(
`Create ${title}`,
);
});
it(`sets form label as ${type}`, () => {
const title = type === 'tree' ? 'Directory' : 'File';
expect(vm.$el.querySelector('.label-light').textContent.trim()).toBe(`${title} name`);
expect(vm.$el.querySelector('.label-light').textContent.trim()).toBe(
`${title} name`,
);
});
describe('createEntryInStore', () => {
......@@ -59,11 +65,15 @@ describe('new file modal component', () => {
it('focuses field on mount', () => {
document.body.innerHTML += '<div class="js-test"></div>';
vm = createComponent(Component, {
vm = createComponent(
Component,
{
type: 'tree',
branchId: 'master',
path: '',
}, '.js-test');
},
'.js-test',
);
expect(document.activeElement).toBe(vm.$refs.fieldName);
......
import Vue from 'vue';
import upload from 'ee/ide/components/new_dropdown/upload.vue';
import upload from '~/ide/components/new_dropdown/upload.vue';
import createComponent from 'spec/helpers/vue_mount_component_helper';
describe('new dropdown upload', () => {
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import service from 'ee/ide/services';
import repoCommitSection from 'ee/ide/components/repo_commit_section.vue';
import store from '~/ide/stores';
import service from '~/ide/services';
import repoCommitSection from '~/ide/components/repo_commit_section.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import getSetTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
import { file, resetStore } from '../helpers';
......@@ -31,22 +31,26 @@ describe('RepoCommitSection', () => {
vm.$store.state.rightPanelCollapsed = false;
vm.$store.state.currentBranch = 'master';
vm.$store.state.changedFiles = [file('file1'), file('file2')];
vm.$store.state.changedFiles.forEach(f => Object.assign(f, {
vm.$store.state.changedFiles.forEach(f =>
Object.assign(f, {
changed: true,
content: 'testing',
}));
}),
);
return vm.$mount();
}
beforeEach((done) => {
beforeEach(done => {
vm = createComponent();
spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({
spyOn(service, 'getTreeData').and.returnValue(
Promise.resolve({
headers: {
'page-title': 'test',
},
json: () => Promise.resolve({
json: () =>
Promise.resolve({
last_commit_path: 'last_commit_path',
parent_tree_url: 'parent_tree_url',
path: '/',
......@@ -54,7 +58,8 @@ describe('RepoCommitSection', () => {
blobs: [{ name: 'blob' }],
submodules: [{ name: 'submodule' }],
}),
}));
}),
);
Vue.nextTick(done);
});
......@@ -75,27 +80,35 @@ describe('RepoCommitSection', () => {
committedStateSvgPath: 'svg',
}).$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');
expect(
vm.$el.querySelector('.js-empty-state').textContent.trim(),
).toContain('No changes');
expect(
vm.$el.querySelector('.js-empty-state img').getAttribute('src'),
).toBe('nochangessvg');
});
});
it('renders a commit section', () => {
const changedFileElements = [...vm.$el.querySelectorAll('.multi-file-commit-list li')];
const changedFileElements = [
...vm.$el.querySelectorAll('.multi-file-commit-list li'),
];
const submitCommit = vm.$el.querySelector('form .btn');
expect(vm.$el.querySelector('.multi-file-commit-form')).not.toBeNull();
expect(changedFileElements.length).toEqual(2);
changedFileElements.forEach((changedFile, i) => {
expect(changedFile.textContent.trim()).toContain(vm.$store.state.changedFiles[i].path);
expect(changedFile.textContent.trim()).toContain(
vm.$store.state.changedFiles[i].path,
);
});
expect(submitCommit.disabled).toBeTruthy();
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeNull();
});
it('updates commitMessage in store on input', (done) => {
it('updates commitMessage in store on input', done => {
const textarea = vm.$el.querySelector('textarea');
textarea.value = 'testing commit message';
......@@ -104,7 +117,9 @@ describe('RepoCommitSection', () => {
getSetTimeoutPromise()
.then(() => {
expect(vm.$store.state.commit.commitMessage).toBe('testing commit message');
expect(vm.$store.state.commit.commitMessage).toBe(
'testing commit message',
);
})
.then(done)
.catch(done.fail);
......@@ -112,10 +127,12 @@ describe('RepoCommitSection', () => {
describe('discard draft button', () => {
it('hidden when commitMessage is empty', () => {
expect(vm.$el.querySelector('.multi-file-commit-form .btn-default')).toBeNull();
expect(
vm.$el.querySelector('.multi-file-commit-form .btn-default'),
).toBeNull();
});
it('resets commitMessage when clicking discard button', (done) => {
it('resets commitMessage when clicking discard button', done => {
vm.$store.state.commit.commitMessage = 'testing commit message';
getSetTimeoutPromise()
......@@ -124,7 +141,9 @@ describe('RepoCommitSection', () => {
})
.then(Vue.nextTick)
.then(() => {
expect(vm.$store.state.commit.commitMessage).not.toBe('testing commit message');
expect(vm.$store.state.commit.commitMessage).not.toBe(
'testing commit message',
);
})
.then(done)
.catch(done.fail);
......@@ -136,7 +155,7 @@ describe('RepoCommitSection', () => {
spyOn(vm, 'commitChanges');
});
it('calls commitChanges', (done) => {
it('calls commitChanges', done => {
vm.$store.state.commit.commitMessage = 'testing commit message';
getSetTimeoutPromise()
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import repoEditor from 'ee/ide/components/repo_editor.vue';
import monacoLoader from 'ee/ide/monaco_loader';
import Editor from 'ee/ide/lib/editor';
import store from '~/ide/stores';
import repoEditor from '~/ide/components/repo_editor.vue';
import monacoLoader from '~/ide/monaco_loader';
import Editor from '~/ide/lib/editor';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { file, resetStore } from '../helpers';
describe('RepoEditor', () => {
let vm;
beforeEach((done) => {
beforeEach(done => {
const f = file();
const RepoEditor = Vue.extend(repoEditor);
......@@ -39,7 +39,7 @@ describe('RepoEditor', () => {
Editor.editorInstance.modelManager.dispose();
});
it('renders an ide container', (done) => {
it('renders an ide container', done => {
Vue.nextTick(() => {
expect(vm.shouldHideEditor).toBeFalsy();
......@@ -48,7 +48,7 @@ describe('RepoEditor', () => {
});
describe('when open file is binary and not raw', () => {
beforeEach((done) => {
beforeEach(done => {
vm.file.binary = true;
vm.$nextTick(done);
......@@ -64,7 +64,7 @@ describe('RepoEditor', () => {
});
describe('createEditorInstance', () => {
it('calls createInstance when viewer is editor', (done) => {
it('calls createInstance when viewer is editor', done => {
spyOn(vm.editor, 'createInstance');
vm.createEditorInstance();
......@@ -76,7 +76,7 @@ describe('RepoEditor', () => {
});
});
it('calls createDiffInstance when viewer is diff', (done) => {
it('calls createDiffInstance when viewer is diff', done => {
vm.$store.state.viewer = 'diff';
spyOn(vm.editor, 'createDiffInstance');
......@@ -124,7 +124,7 @@ describe('RepoEditor', () => {
expect(vm.model.events.size).toBe(1);
});
it('updates state when model content changed', (done) => {
it('updates state when model content changed', done => {
vm.model.setValue('testing 123');
setTimeout(() => {
......
import Vue from 'vue';
import repoFileButtons from 'ee/ide/components/repo_file_buttons.vue';
import repoFileButtons from '~/ide/components/repo_file_buttons.vue';
import createVueComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
......@@ -23,7 +23,7 @@ describe('RepoFileButtons', () => {
vm.$destroy();
});
it('renders Raw, Blame, History, Permalink and Preview toggle', (done) => {
it('renders Raw, Blame, History, Permalink and Preview toggle', done => {
vm = createComponent();
vm.$nextTick(() => {
......@@ -37,7 +37,9 @@ describe('RepoFileButtons', () => {
expect(blame.textContent.trim()).toEqual('Blame');
expect(history.href).toMatch(`/${activeFile.commitsPath}`);
expect(history.textContent.trim()).toEqual('History');
expect(vm.$el.querySelector('.permalink').textContent.trim()).toEqual('Permalink');
expect(vm.$el.querySelector('.permalink').textContent.trim()).toEqual(
'Permalink',
);
done();
});
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import repoFile from 'ee/ide/components/repo_file.vue';
import router from 'ee/ide/ide_router';
import store from '~/ide/stores';
import repoFile from '~/ide/components/repo_file.vue';
import router from '~/ide/ide_router';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import repoLoadingFile from 'ee/ide/components/repo_loading_file.vue';
import store from '~/ide/stores';
import repoLoadingFile from '~/ide/components/repo_loading_file.vue';
import { resetStore } from '../helpers';
describe('RepoLoadingFile', () => {
......@@ -22,7 +22,7 @@ describe('RepoLoadingFile', () => {
}
function assertColumns(columns) {
columns.forEach((column) => {
columns.forEach(column => {
const container = column.querySelector('.animation-container');
const lines = [...container.querySelectorAll(':scope > div')];
......@@ -46,7 +46,7 @@ describe('RepoLoadingFile', () => {
assertColumns(columns);
});
it('renders 1 column of animated LoC if isMini', (done) => {
it('renders 1 column of animated LoC if isMini', done => {
vm = createComponent();
vm.$store.state.leftPanelCollapsed = true;
vm.$store.state.openFiles.push('test');
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import repoTab from 'ee/ide/components/repo_tab.vue';
import router from 'ee/ide/ide_router';
import store from '~/ide/stores';
import repoTab from '~/ide/components/repo_tab.vue';
import router from '~/ide/ide_router';
import { file, resetStore } from '../helpers';
describe('RepoTab', () => {
......@@ -62,7 +62,7 @@ describe('RepoTab', () => {
expect(vm.closeFile).toHaveBeenCalledWith(vm.tab.path);
});
it('changes icon on hover', (done) => {
it('changes icon on hover', done => {
const tab = file();
tab.changed = true;
vm = createComponent({
......@@ -112,13 +112,15 @@ describe('RepoTab', () => {
});
it('renders a tooltip', () => {
expect(vm.$el.querySelector('span:nth-child(2)').dataset.originalTitle).toContain('Locked by testuser');
expect(
vm.$el.querySelector('span:nth-child(2)').dataset.originalTitle,
).toContain('Locked by testuser');
});
});
describe('methods', () => {
describe('closeTab', () => {
it('closes tab if file has changed', (done) => {
it('closes tab if file has changed', done => {
const tab = file();
tab.changed = true;
tab.opened = true;
......@@ -140,7 +142,7 @@ describe('RepoTab', () => {
});
});
it('closes tab when clicking close btn', (done) => {
it('closes tab when clicking close btn', done => {
const tab = file('lose');
tab.opened = true;
vm = createComponent({
......
import Vue from 'vue';
import repoTabs from 'ee/ide/components/repo_tabs.vue';
import repoTabs from '~/ide/components/repo_tabs.vue';
import createComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
......
import { decorateData } from 'ee/ide/stores/utils';
import state from 'ee/ide/stores/state';
import commitState from 'ee/ide/stores/modules/commit/state';
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
export const resetStore = (store) => {
export const resetStore = store => {
const newState = {
...state(),
commit: commitState(),
......@@ -10,7 +10,8 @@ export const resetStore = (store) => {
store.replaceState(newState);
};
export const file = (name = 'name', id = name, type = '') => decorateData({
export const file = (name = 'name', id = name, type = '') =>
decorateData({
id,
type,
icon: 'icon',
......@@ -18,4 +19,4 @@ export const file = (name = 'name', id = name, type = '') => decorateData({
name,
path: name,
lastCommit: {},
});
});
import Disposable from 'ee/ide/lib/common/disposable';
import Disposable from '~/ide/lib/common/disposable';
describe('Multi-file editor library disposable class', () => {
let instance;
......
/* global monaco */
import eventHub from 'ee/ide/eventhub';
import monacoLoader from 'ee/ide/monaco_loader';
import ModelManager from 'ee/ide/lib/common/model_manager';
import eventHub from '~/ide/eventhub';
import monacoLoader from '~/ide/monaco_loader';
import ModelManager from '~/ide/lib/common/model_manager';
import { file } from '../../helpers';
describe('Multi-file editor library model manager', () => {
let instance;
beforeEach((done) => {
beforeEach(done => {
monacoLoader(['vs/editor/editor.main'], () => {
instance = new ModelManager(monaco);
......@@ -55,7 +55,10 @@ describe('Multi-file editor library model manager', () => {
instance.addModel(f);
expect(eventHub.$on).toHaveBeenCalledWith(`editor.update.model.dispose.${f.path}`, jasmine.anything());
expect(eventHub.$on).toHaveBeenCalledWith(
`editor.update.model.dispose.${f.path}`,
jasmine.anything(),
);
});
});
......@@ -99,7 +102,10 @@ describe('Multi-file editor library model manager', () => {
instance.removeCachedModel(f);
expect(eventHub.$off).toHaveBeenCalledWith(`editor.update.model.dispose.${f.path}`, jasmine.anything());
expect(eventHub.$off).toHaveBeenCalledWith(
`editor.update.model.dispose.${f.path}`,
jasmine.anything(),
);
});
});
......
/* global monaco */
import eventHub from 'ee/ide/eventhub';
import monacoLoader from 'ee/ide/monaco_loader';
import Model from 'ee/ide/lib/common/model';
import eventHub from '~/ide/eventhub';
import monacoLoader from '~/ide/monaco_loader';
import Model from '~/ide/lib/common/model';
import { file } from '../../helpers';
describe('Multi-file editor library model', () => {
let model;
beforeEach((done) => {
beforeEach(done => {
spyOn(eventHub, '$on').and.callThrough();
monacoLoader(['vs/editor/editor.main'], () => {
......@@ -27,7 +27,10 @@ describe('Multi-file editor library model', () => {
});
it('adds eventHub listener', () => {
expect(eventHub.$on).toHaveBeenCalledWith(`editor.update.model.dispose.${model.file.path}`, jasmine.anything());
expect(eventHub.$on).toHaveBeenCalledWith(
`editor.update.model.dispose.${model.file.path}`,
jasmine.anything(),
);
});
describe('path', () => {
......@@ -64,7 +67,7 @@ describe('Multi-file editor library model', () => {
expect(model.events.keys().next().value).toBe('path');
});
it('calls callback on change', (done) => {
it('calls callback on change', done => {
const spy = jasmine.createSpy();
model.onChange(spy);
......@@ -101,7 +104,10 @@ describe('Multi-file editor library model', () => {
model.dispose();
expect(eventHub.$off).toHaveBeenCalledWith(`editor.update.model.dispose.${model.file.path}`, jasmine.anything());
expect(eventHub.$off).toHaveBeenCalledWith(
`editor.update.model.dispose.${model.file.path}`,
jasmine.anything(),
);
});
});
});
/* global monaco */
import monacoLoader from 'ee/ide/monaco_loader';
import editor from 'ee/ide/lib/editor';
import DecorationsController from 'ee/ide/lib/decorations/controller';
import Model from 'ee/ide/lib/common/model';
import monacoLoader from '~/ide/monaco_loader';
import editor from '~/ide/lib/editor';
import DecorationsController from '~/ide/lib/decorations/controller';
import Model from '~/ide/lib/common/model';
import { file } from '../../helpers';
describe('Multi-file editor library decorations controller', () => {
......@@ -10,7 +10,7 @@ describe('Multi-file editor library decorations controller', () => {
let controller;
let model;
beforeEach((done) => {
beforeEach(done => {
monacoLoader(['vs/editor/editor.main'], () => {
editorInstance = editor.create(monaco);
editorInstance.createInstance(document.createElement('div'));
......@@ -36,7 +36,9 @@ describe('Multi-file editor library decorations controller', () => {
});
it('returns decorations by model URL', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
const decorations = controller.getAllDecorationsForModel(model);
......@@ -46,20 +48,28 @@ describe('Multi-file editor library decorations controller', () => {
describe('addDecorations', () => {
it('caches decorations in a new map', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
expect(controller.decorations.size).toBe(1);
});
it('does not create new cache model', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue2' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue2' },
]);
expect(controller.decorations.size).toBe(1);
});
it('caches decorations by model URL', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
expect(controller.decorations.size).toBe(1);
expect(controller.decorations.keys().next().value).toBe('path');
......@@ -68,7 +78,9 @@ describe('Multi-file editor library decorations controller', () => {
it('calls decorate method', () => {
spyOn(controller, 'decorate');
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
expect(controller.decorate).toHaveBeenCalled();
});
......@@ -80,7 +92,10 @@ describe('Multi-file editor library decorations controller', () => {
controller.decorate(model);
expect(controller.editor.instance.deltaDecorations).toHaveBeenCalledWith([], []);
expect(controller.editor.instance.deltaDecorations).toHaveBeenCalledWith(
[],
[],
);
});
it('caches decorations', () => {
......@@ -102,7 +117,9 @@ describe('Multi-file editor library decorations controller', () => {
describe('dispose', () => {
it('clears cached decorations', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
controller.dispose();
......@@ -110,7 +127,9 @@ describe('Multi-file editor library decorations controller', () => {
});
it('clears cached editorDecorations', () => {
controller.addDecorations(model, 'key', [{ decoration: 'decorationValue' }]);
controller.addDecorations(model, 'key', [
{ decoration: 'decorationValue' },
]);
controller.dispose();
......
/* global monaco */
import monacoLoader from 'ee/ide/monaco_loader';
import editor from 'ee/ide/lib/editor';
import ModelManager from 'ee/ide/lib/common/model_manager';
import DecorationsController from 'ee/ide/lib/decorations/controller';
import DirtyDiffController, { getDiffChangeType, getDecorator } from 'ee/ide/lib/diff/controller';
import { computeDiff } from 'ee/ide/lib/diff/diff';
import monacoLoader from '~/ide/monaco_loader';
import editor from '~/ide/lib/editor';
import ModelManager from '~/ide/lib/common/model_manager';
import DecorationsController from '~/ide/lib/decorations/controller';
import DirtyDiffController, {
getDiffChangeType,
getDecorator,
} from '~/ide/lib/diff/controller';
import { computeDiff } from '~/ide/lib/diff/diff';
import { file } from '../../helpers';
describe('Multi-file editor library dirty diff controller', () => {
......@@ -14,7 +17,7 @@ describe('Multi-file editor library dirty diff controller', () => {
let decorationsController;
let model;
beforeEach((done) => {
beforeEach(done => {
monacoLoader(['vs/editor/editor.main'], () => {
editorInstance = editor.create(monaco);
editorInstance.createInstance(document.createElement('div'));
......@@ -38,7 +41,7 @@ describe('Multi-file editor library dirty diff controller', () => {
});
describe('getDiffChangeType', () => {
['added', 'removed', 'modified'].forEach((type) => {
['added', 'removed', 'modified'].forEach(type => {
it(`returns ${type}`, () => {
const change = {
[type]: true,
......@@ -50,15 +53,15 @@ describe('Multi-file editor library dirty diff controller', () => {
});
describe('getDecorator', () => {
['added', 'removed', 'modified'].forEach((type) => {
['added', 'removed', 'modified'].forEach(type => {
it(`returns with linesDecorationsClassName for ${type}`, () => {
const change = {
[type]: true,
};
expect(
getDecorator(change).options.linesDecorationsClassName,
).toBe(`dirty-diff dirty-diff-${type}`);
expect(getDecorator(change).options.linesDecorationsClassName).toBe(
`dirty-diff dirty-diff-${type}`,
);
});
it('returns with line numbers', () => {
......@@ -118,7 +121,9 @@ describe('Multi-file editor library dirty diff controller', () => {
controller.reDecorate(model);
expect(controller.decorationsController.decorate).toHaveBeenCalledWith(model);
expect(controller.decorationsController.decorate).toHaveBeenCalledWith(
model,
);
});
});
......@@ -128,23 +133,33 @@ describe('Multi-file editor library dirty diff controller', () => {
controller.decorate({ data: { changes: [], path: 'path' } });
expect(controller.decorationsController.addDecorations).toHaveBeenCalledWith(model, 'dirtyDiff', jasmine.anything());
expect(
controller.decorationsController.addDecorations,
).toHaveBeenCalledWith(model, 'dirtyDiff', jasmine.anything());
});
it('adds decorations into editor', () => {
const spy = spyOn(controller.decorationsController.editor.instance, 'deltaDecorations');
const spy = spyOn(
controller.decorationsController.editor.instance,
'deltaDecorations',
);
controller.decorate({ data: { changes: computeDiff('123', '1234'), path: 'path' } });
controller.decorate({
data: { changes: computeDiff('123', '1234'), path: 'path' },
});
expect(spy).toHaveBeenCalledWith([], [{
range: new monaco.Range(
1, 1, 1, 1,
),
expect(spy).toHaveBeenCalledWith(
[],
[
{
range: new monaco.Range(1, 1, 1, 1),
options: {
isWholeLine: true,
linesDecorationsClassName: 'dirty-diff dirty-diff-modified',
},
}]);
},
],
);
});
});
......@@ -166,11 +181,16 @@ describe('Multi-file editor library dirty diff controller', () => {
});
it('removes worker event listener', () => {
spyOn(controller.dirtyDiffWorker, 'removeEventListener').and.callThrough();
spyOn(
controller.dirtyDiffWorker,
'removeEventListener',
).and.callThrough();
controller.dispose();
expect(controller.dirtyDiffWorker.removeEventListener).toHaveBeenCalledWith('message', jasmine.anything());
expect(
controller.dirtyDiffWorker.removeEventListener,
).toHaveBeenCalledWith('message', jasmine.anything());
});
});
});
import { computeDiff } from 'ee/ide/lib/diff/diff';
import { computeDiff } from '~/ide/lib/diff/diff';
describe('Multi-file editor library diff calculator', () => {
describe('computeDiff', () => {
......
import editorOptions from 'ee/ide/lib/editor_options';
import editorOptions from '~/ide/lib/editor_options';
describe('Multi-file editor library editor options', () => {
it('returns an array', () => {
......
/* global monaco */
import monacoLoader from 'ee/ide/monaco_loader';
import editor from 'ee/ide/lib/editor';
import monacoLoader from '~/ide/monaco_loader';
import editor from '~/ide/lib/editor';
import { file } from '../helpers';
describe('Multi-file editor library', () => {
......
import monacoContext from 'monaco-editor/dev/vs/loader';
import monacoLoader from 'ee/ide/monaco_loader';
import monacoLoader from '~/ide/monaco_loader';
describe('MonacoLoader', () => {
it('calls require.config and exports require', () => {
expect(monacoContext.require.getConfig()).toEqual(jasmine.objectContaining({
expect(monacoContext.require.getConfig()).toEqual(
jasmine.objectContaining({
paths: {
vs: `${__webpack_public_path__}monaco-editor/vs`, // eslint-disable-line camelcase
},
}));
}),
);
expect(monacoLoader).toBe(monacoContext.require);
});
});
import Vue from 'vue';
import store from 'ee/ide/stores';
import service from 'ee/ide/services';
import router from 'ee/ide/ide_router';
import eventHub from 'ee/ide/eventhub';
import store from '~/ide/stores';
import service from '~/ide/services';
import router from '~/ide/ide_router';
import eventHub from '~/ide/eventhub';
import { file, resetStore } from '../../helpers';
describe('Multi-file store file actions', () => {
......
import Vue from 'vue';
import store from 'ee/ide/stores';
import service from 'ee/ide/services';
import router from 'ee/ide/ide_router';
import store from '~/ide/stores';
import service from '~/ide/services';
import router from '~/ide/ide_router';
import { file, resetStore } from '../../helpers';
describe('Multi-file store tree actions', () => {
......@@ -35,26 +35,32 @@ describe('Multi-file store tree actions', () => {
describe('getFiles', () => {
beforeEach(() => {
spyOn(service, 'getFiles').and.returnValue(Promise.resolve({
json: () => Promise.resolve([
spyOn(service, 'getFiles').and.returnValue(
Promise.resolve({
json: () =>
Promise.resolve([
'file.txt',
'folder/fileinfolder.js',
'folder/subfolder/fileinsubfolder.js',
]),
}));
}),
);
});
it('calls service getFiles', (done) => {
store.dispatch('getFiles', basicCallParameters)
it('calls service getFiles', done => {
store
.dispatch('getFiles', basicCallParameters)
.then(() => {
expect(service.getFiles).toHaveBeenCalledWith('', 'master');
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('adds data into tree', (done) => {
store.dispatch('getFiles', basicCallParameters)
it('adds data into tree', done => {
store
.dispatch('getFiles', basicCallParameters)
.then(() => {
projectTree = store.state.trees['abcproject/master'];
expect(projectTree.tree.length).toBe(2);
......@@ -62,10 +68,13 @@ describe('Multi-file store tree actions', () => {
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
expect(projectTree.tree[1].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].name).toBe('fileinsubfolder.js');
expect(projectTree.tree[0].tree[0].tree[0].name).toBe(
'fileinsubfolder.js',
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
});
......@@ -77,30 +86,38 @@ describe('Multi-file store tree actions', () => {
store.state.entries[tree.path] = tree;
});
it('toggles the tree open', (done) => {
store.dispatch('toggleTreeOpen', tree.path).then(() => {
it('toggles the tree open', done => {
store
.dispatch('toggleTreeOpen', tree.path)
.then(() => {
expect(tree.opened).toBeTruthy();
done();
}).catch(done.fail);
})
.catch(done.fail);
});
});
describe('getLastCommitData', () => {
beforeEach(() => {
spyOn(service, 'getTreeLastCommit').and.returnValue(Promise.resolve({
spyOn(service, 'getTreeLastCommit').and.returnValue(
Promise.resolve({
headers: {
'more-logs-url': null,
},
json: () => Promise.resolve([{
json: () =>
Promise.resolve([
{
type: 'tree',
file_name: 'testing',
commit: {
message: 'commit message',
authored_date: '123',
},
}]),
}));
},
]),
}),
);
store.state.trees['abcproject/mybranch'] = {
tree: [],
......@@ -111,35 +128,45 @@ describe('Multi-file store tree actions', () => {
projectTree.lastCommitPath = 'lastcommitpath';
});
it('calls service with lastCommitPath', (done) => {
store.dispatch('getLastCommitData', projectTree)
it('calls service with lastCommitPath', done => {
store
.dispatch('getLastCommitData', projectTree)
.then(() => {
expect(service.getTreeLastCommit).toHaveBeenCalledWith('lastcommitpath');
expect(service.getTreeLastCommit).toHaveBeenCalledWith(
'lastcommitpath',
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('updates trees last commit data', (done) => {
store.dispatch('getLastCommitData', projectTree)
it('updates trees last commit data', done => {
store
.dispatch('getLastCommitData', projectTree)
.then(Vue.nextTick)
.then(() => {
expect(projectTree.tree[0].lastCommit.message).toBe('commit message');
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('does not update entry if not found', (done) => {
it('does not update entry if not found', done => {
projectTree.tree[0].name = 'a';
store.dispatch('getLastCommitData', projectTree)
store
.dispatch('getLastCommitData', projectTree)
.then(Vue.nextTick)
.then(() => {
expect(projectTree.tree[0].lastCommit.message).not.toBe('commit message');
expect(projectTree.tree[0].lastCommit.message).not.toBe(
'commit message',
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
});
});
import * as urlUtils from '~/lib/utils/url_utility';
import store from 'ee/ide/stores';
import router from 'ee/ide/ide_router';
import store from '~/ide/stores';
import router from '~/ide/ide_router';
import { resetStore, file } from '../helpers';
describe('Multi-file store actions', () => {
......
import * as getters from 'ee/ide/stores/getters';
import state from 'ee/ide/stores/state';
import * as getters from '~/ide/stores/getters';
import state from '~/ide/stores/state';
import { file } from '../helpers';
describe('Multi-file store getters', () => {
......
import store from 'ee/ide/stores';
import service from 'ee/ide/services';
import router from 'ee/ide/ide_router';
import store from '~/ide/stores';
import service from '~/ide/services';
import router from '~/ide/ide_router';
import * as urlUtils from '~/lib/utils/url_utility';
import eventHub from 'ee/ide/eventhub';
import * as consts from 'ee/ide/stores/modules/commit/constants';
import eventHub from '~/ide/eventhub';
import * as consts from '~/ide/stores/modules/commit/constants';
import { resetStore, file } from 'spec/ide/helpers';
describe('IDE commit module actions', () => {
......@@ -16,8 +16,9 @@ describe('IDE commit module actions', () => {
});
describe('updateCommitMessage', () => {
it('updates store with new commit message', (done) => {
store.dispatch('commit/updateCommitMessage', 'testing')
it('updates store with new commit message', done => {
store
.dispatch('commit/updateCommitMessage', 'testing')
.then(() => {
expect(store.state.commit.commitMessage).toBe('testing');
})
......@@ -27,10 +28,11 @@ describe('IDE commit module actions', () => {
});
describe('discardDraft', () => {
it('resets commit message to blank', (done) => {
it('resets commit message to blank', done => {
store.state.commit.commitMessage = 'testing';
store.dispatch('commit/discardDraft')
store
.dispatch('commit/discardDraft')
.then(() => {
expect(store.state.commit.commitMessage).not.toBe('testing');
})
......@@ -40,8 +42,9 @@ describe('IDE commit module actions', () => {
});
describe('updateCommitAction', () => {
it('updates store with new commit action', (done) => {
store.dispatch('commit/updateCommitAction', '1')
it('updates store with new commit action', done => {
store
.dispatch('commit/updateCommitAction', '1')
.then(() => {
expect(store.state.commit.commitAction).toBe('1');
})
......@@ -51,8 +54,9 @@ describe('IDE commit module actions', () => {
});
describe('updateBranchName', () => {
it('updates store with new branch name', (done) => {
store.dispatch('commit/updateBranchName', 'branch-name')
it('updates store with new branch name', done => {
store
.dispatch('commit/updateBranchName', 'branch-name')
.then(() => {
expect(store.state.commit.newBranchName).toBe('branch-name');
})
......@@ -73,8 +77,9 @@ describe('IDE commit module actions', () => {
});
});
it('updates commit message with short_id', (done) => {
store.dispatch('commit/setLastCommitMessage', { short_id: '123' })
it('updates commit message with short_id', done => {
store
.dispatch('commit/setLastCommitMessage', { short_id: '123' })
.then(() => {
expect(store.state.lastCommitMsg).toContain(
'Your changes have been committed. Commit <a href="http://testing/commit/123" class="commit-sha">123</a>',
......@@ -84,8 +89,9 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('updates commit message with stats', (done) => {
store.dispatch('commit/setLastCommitMessage', {
it('updates commit message with stats', done => {
store
.dispatch('commit/setLastCommitMessage', {
short_id: '123',
stats: {
additions: '1',
......@@ -93,7 +99,9 @@ describe('IDE commit module actions', () => {
},
})
.then(() => {
expect(store.state.lastCommitMsg).toBe('Your changes have been committed. Commit <a href="http://testing/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.');
expect(store.state.lastCommitMsg).toBe(
'Your changes have been committed. Commit <a href="http://testing/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.',
);
})
.then(done)
.catch(done.fail);
......@@ -113,31 +121,40 @@ describe('IDE commit module actions', () => {
};
});
it('calls service', (done) => {
spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({
it('calls service', done => {
spyOn(service, 'getBranchData').and.returnValue(
Promise.resolve({
data: {
commit: { id: '123' },
},
}));
}),
);
store.dispatch('commit/checkCommitStatus')
store
.dispatch('commit/checkCommitStatus')
.then(() => {
expect(service.getBranchData).toHaveBeenCalledWith('abcproject', 'master');
expect(service.getBranchData).toHaveBeenCalledWith(
'abcproject',
'master',
);
done();
})
.catch(done.fail);
});
it('returns true if current ref does not equal returned ID', (done) => {
spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({
it('returns true if current ref does not equal returned ID', done => {
spyOn(service, 'getBranchData').and.returnValue(
Promise.resolve({
data: {
commit: { id: '123' },
},
}));
}),
);
store.dispatch('commit/checkCommitStatus')
.then((val) => {
store
.dispatch('commit/checkCommitStatus')
.then(val => {
expect(val).toBeTruthy();
done();
......@@ -145,15 +162,18 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('returns false if current ref equals returned ID', (done) => {
spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({
it('returns false if current ref equals returned ID', done => {
spyOn(service, 'getBranchData').and.returnValue(
Promise.resolve({
data: {
commit: { id: '1' },
},
}));
}),
);
store.dispatch('commit/checkCommitStatus')
.then((val) => {
store
.dispatch('commit/checkCommitStatus')
.then(val => {
expect(val).toBeFalsy();
done();
......@@ -198,13 +218,14 @@ describe('IDE commit module actions', () => {
});
store.state.openFiles = store.state.changedFiles;
store.state.changedFiles.forEach((changedFile) => {
store.state.changedFiles.forEach(changedFile => {
store.state.entries[changedFile.path] = changedFile;
});
});
it('updates stores working reference', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('updates stores working reference', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
......@@ -217,13 +238,14 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('resets all files changed status', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('resets all files changed status', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
store.state.openFiles.forEach((entry) => {
store.state.openFiles.forEach(entry => {
expect(entry.changed).toBeFalsy();
});
})
......@@ -231,8 +253,9 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('removes all changed files', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('removes all changed files', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
......@@ -243,8 +266,9 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('sets files commit data', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('sets files commit data', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
......@@ -255,8 +279,9 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('updates raw content for changed file', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('updates raw content for changed file', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
......@@ -267,22 +292,27 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('emits changed event for file', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
it('emits changed event for file', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.path}`, f.content);
expect(eventHub.$emit).toHaveBeenCalledWith(
`editor.update.model.content.${f.path}`,
f.content,
);
})
.then(done)
.catch(done.fail);
});
it('pushes route to new branch if commitAction is new branch', (done) => {
it('pushes route to new branch if commitAction is new branch', done => {
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.dispatch('commit/updateFilesAfterCommit', {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
......@@ -295,15 +325,18 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
it('resets stores commit actions', (done) => {
it('resets stores commit actions', done => {
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.dispatch('commit/updateFilesAfterCommit', {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
expect(store.state.commit.commitAction).not.toBe(consts.COMMIT_TO_NEW_BRANCH);
expect(store.state.commit.commitAction).not.toBe(
consts.COMMIT_TO_NEW_BRANCH,
);
})
.then(done)
.catch(done.fail);
......@@ -330,7 +363,7 @@ describe('IDE commit module actions', () => {
store.state.changedFiles[0].active = true;
store.state.openFiles = store.state.changedFiles;
store.state.openFiles.forEach((f) => {
store.state.openFiles.forEach(f => {
store.state.entries[f.path] = f;
});
......@@ -344,7 +377,8 @@ describe('IDE commit module actions', () => {
describe('success', () => {
beforeEach(() => {
spyOn(service, 'commit').and.returnValue(Promise.resolve({
spyOn(service, 'commit').and.returnValue(
Promise.resolve({
data: {
id: '123456',
short_id: '123',
......@@ -355,95 +389,116 @@ describe('IDE commit module actions', () => {
deletions: '2',
},
},
}));
}),
);
});
it('calls service', (done) => {
store.dispatch('commit/commitChanges')
it('calls service', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
expect(service.commit).toHaveBeenCalledWith('abcproject', {
branch: jasmine.anything(),
commit_message: 'testing 123',
actions: [{
actions: [
{
action: 'update',
file_path: jasmine.anything(),
content: jasmine.anything(),
encoding: jasmine.anything(),
}],
},
],
start_branch: 'master',
});
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('pushes router to new route', (done) => {
store.dispatch('commit/commitChanges')
it('pushes router to new route', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
expect(router.push).toHaveBeenCalledWith(
`/project/${store.state.currentProjectId}/blob/${store.getters['commit/newBranchName']}/changed`,
`/project/${store.state.currentProjectId}/blob/${
store.getters['commit/newBranchName']
}/changed`,
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('sets last Commit Msg', (done) => {
store.dispatch('commit/commitChanges')
it('sets last Commit Msg', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.lastCommitMsg).toBe(
'Your changes have been committed. Commit <a href="webUrl/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.',
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('adds commit data to changed files', (done) => {
store.dispatch('commit/commitChanges')
it('adds commit data to changed files', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.openFiles[0].lastCommit.message).toBe('test message');
expect(store.state.openFiles[0].lastCommit.message).toBe(
'test message',
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
it('redirects to new merge request page', (done) => {
it('redirects to new merge request page', done => {
spyOn(eventHub, '$on');
store.state.commit.commitAction = '3';
store.dispatch('commit/commitChanges')
store
.dispatch('commit/commitChanges')
.then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalledWith(
`webUrl/merge_requests/new?merge_request[source_branch]=${store.getters['commit/newBranchName']}&merge_request[target_branch]=master`,
`webUrl/merge_requests/new?merge_request[source_branch]=${
store.getters['commit/newBranchName']
}&merge_request[target_branch]=master`,
);
done();
}).catch(done.fail);
})
.catch(done.fail);
});
});
describe('failed', () => {
beforeEach(() => {
spyOn(service, 'commit').and.returnValue(Promise.resolve({
spyOn(service, 'commit').and.returnValue(
Promise.resolve({
data: {
message: 'failed message',
},
}));
}),
);
});
it('shows failed message', (done) => {
store.dispatch('commit/commitChanges')
it('shows failed message', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
const alert = document.querySelector('.flash-container');
expect(alert.textContent.trim()).toBe(
'failed message',
);
expect(alert.textContent.trim()).toBe('failed message');
done();
}).catch(done.fail);
})
.catch(done.fail);
});
});
});
......
import commitState from 'ee/ide/stores/modules/commit/state';
import * as consts from 'ee/ide/stores/modules/commit/constants';
import * as getters from 'ee/ide/stores/modules/commit/getters';
import commitState from '~/ide/stores/modules/commit/state';
import * as consts from '~/ide/stores/modules/commit/constants';
import * as getters from '~/ide/stores/modules/commit/getters';
describe('IDE commit module getters', () => {
let state;
......@@ -38,26 +38,34 @@ describe('IDE commit module getters', () => {
};
it('returns false when discardDraftButtonDisabled is false & changedFiles is not empty', () => {
expect(getters.commitButtonDisabled(state, localGetters, rootState)).toBeFalsy();
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeFalsy();
});
it('returns true when discardDraftButtonDisabled is false & changedFiles is empty', () => {
rootState.changedFiles.length = 0;
expect(getters.commitButtonDisabled(state, localGetters, rootState)).toBeTruthy();
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
it('returns true when discardDraftButtonDisabled is true', () => {
localGetters.discardDraftButtonDisabled = true;
expect(getters.commitButtonDisabled(state, localGetters, rootState)).toBeTruthy();
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
it('returns true when discardDraftButtonDisabled is false & changedFiles is not empty', () => {
localGetters.discardDraftButtonDisabled = false;
rootState.changedFiles.length = 0;
expect(getters.commitButtonDisabled(state, localGetters, rootState)).toBeTruthy();
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
});
......@@ -65,7 +73,9 @@ describe('IDE commit module getters', () => {
it('includes username, currentBranchId, patch & random number', () => {
gon.current_username = 'username';
const branch = getters.newBranchName(state, null, { currentBranchId: 'testing' });
const branch = getters.newBranchName(state, null, {
currentBranchId: 'testing',
});
expect(branch).toMatch(/username-testing-patch-\d{5}$/);
});
......@@ -89,7 +99,7 @@ describe('IDE commit module getters', () => {
expect(getters.branchName(state, null, rootState)).toBe('master');
});
['COMMIT_TO_NEW_BRANCH', 'COMMIT_TO_NEW_BRANCH_MR'].forEach((type) => {
['COMMIT_TO_NEW_BRANCH', 'COMMIT_TO_NEW_BRANCH_MR'].forEach(type => {
describe(type, () => {
beforeEach(() => {
Object.assign(state, {
......@@ -98,7 +108,9 @@ describe('IDE commit module getters', () => {
});
it('uses newBranchName when not empty', () => {
expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName');
expect(getters.branchName(state, localGetters, rootState)).toBe(
'state-newBranchName',
);
});
it('uses getters newBranchName when state newBranchName is empty', () => {
......@@ -106,7 +118,9 @@ describe('IDE commit module getters', () => {
newBranchName: '',
});
expect(getters.branchName(state, localGetters, rootState)).toBe('newBranchName');
expect(getters.branchName(state, localGetters, rootState)).toBe(
'newBranchName',
);
});
});
});
......
import commitState from 'ee/ide/stores/modules/commit/state';
import mutations from 'ee/ide/stores/modules/commit/mutations';
import commitState from '~/ide/stores/modules/commit/state';
import mutations from '~/ide/stores/modules/commit/mutations';
describe('IDE commit module mutations', () => {
let state;
......
import mutations from 'ee/ide/stores/mutations/branch';
import state from 'ee/ide/stores/state';
import mutations from '~/ide/stores/mutations/branch';
import state from '~/ide/stores/state';
describe('Multi-file store branch mutations', () => {
let localState;
......
import mutations from 'ee/ide/stores/mutations/file';
import state from 'ee/ide/stores/state';
import mutations from '~/ide/stores/mutations/file';
import state from '~/ide/stores/state';
import { file } from '../../helpers';
describe('Multi-file store file mutations', () => {
......
import mutations from 'ee/ide/stores/mutations/tree';
import state from 'ee/ide/stores/state';
import mutations from '~/ide/stores/mutations/tree';
import state from '~/ide/stores/state';
import { file } from '../../helpers';
describe('Multi-file store tree mutations', () => {
......@@ -26,7 +26,8 @@ describe('Multi-file store tree mutations', () => {
});
describe('SET_DIRECTORY_DATA', () => {
const data = [{
const data = [
{
name: 'tree',
},
{
......@@ -34,7 +35,8 @@ describe('Multi-file store tree mutations', () => {
},
{
name: 'blob',
}];
},
];
it('adds directory data', () => {
localState.trees['project/master'] = {
......
import mutations from 'ee/ide/stores/mutations';
import state from 'ee/ide/stores/state';
import mutations from '~/ide/stores/mutations';
import state from '~/ide/stores/state';
import { file } from '../helpers';
describe('Multi-file store mutations', () => {
......
import * as utils from 'ee/ide/stores/utils';
import * as utils from '~/ide/stores/utils';
describe('Multi-file store utils', () => {
describe('setPageTitle', () => {
......@@ -13,11 +13,14 @@ describe('Multi-file store utils', () => {
let localState;
beforeEach(() => {
localState = [{
localState = [
{
path: '1',
}, {
},
{
path: '2',
}];
},
];
});
it('finds in the index of an entry by path', () => {
......@@ -34,13 +37,16 @@ describe('Multi-file store utils', () => {
beforeEach(() => {
localState = {
tree: [{
tree: [
{
type: 'tree',
name: 'test',
}, {
},
{
type: 'blob',
name: 'file',
}],
},
],
};
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment