summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/components/new_dropdown/index_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/repo/components/new_dropdown/index_spec.js')
-rw-r--r--spec/javascripts/repo/components/new_dropdown/index_spec.js172
1 files changed, 9 insertions, 163 deletions
diff --git a/spec/javascripts/repo/components/new_dropdown/index_spec.js b/spec/javascripts/repo/components/new_dropdown/index_spec.js
index ddffef53300..93b10fc1fee 100644
--- a/spec/javascripts/repo/components/new_dropdown/index_spec.js
+++ b/spec/javascripts/repo/components/new_dropdown/index_spec.js
@@ -1,9 +1,8 @@
import Vue from 'vue';
+import store from '~/repo/stores';
import newDropdown from '~/repo/components/new_dropdown/index.vue';
-import RepoStore from '~/repo/stores/repo_store';
-import RepoHelper from '~/repo/helpers/repo_helper';
-import eventHub from '~/repo/event_hub';
-import createComponent from '../../../helpers/vue_mount_component_helper';
+import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
+import { resetStore } from '../../helpers';
describe('new dropdown component', () => {
let vm;
@@ -11,15 +10,17 @@ describe('new dropdown component', () => {
beforeEach(() => {
const component = Vue.extend(newDropdown);
- vm = createComponent(component);
+ vm = createComponentWithStore(component, store);
+
+ vm.$store.state.path = '';
+
+ vm.$mount();
});
afterEach(() => {
vm.$destroy();
- RepoStore.files = [];
- RepoStore.openedFiles = [];
- RepoStore.setViewToPreview();
+ resetStore(vm.$store);
});
it('renders new file and new directory links', () => {
@@ -67,159 +68,4 @@ describe('new dropdown component', () => {
.catch(done.fail);
});
});
-
- describe('createEntryInStore', () => {
- ['tree', 'blob'].forEach((type) => {
- describe(type, () => {
- it('closes modal after creating file', () => {
- vm.openModal = true;
-
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type,
- toggleModal: true,
- });
-
- expect(vm.openModal).toBeFalsy();
- });
-
- it('sets editMode to true', () => {
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type,
- });
-
- expect(RepoStore.editMode).toBeTruthy();
- });
-
- it('toggles blob view', () => {
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type,
- });
-
- expect(RepoStore.isPreviewView()).toBeFalsy();
- });
-
- it('adds file into activeFiles', () => {
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type,
- });
-
- expect(RepoStore.openedFiles.length).toBe(1);
- });
-
- it(`creates ${type} in the current stores path`, () => {
- RepoStore.path = 'testing';
-
- eventHub.$emit('createNewEntry', {
- name: 'testing/app',
- type,
- });
-
- expect(RepoStore.files[0].path).toBe('testing/app');
- expect(RepoStore.files[0].name).toBe('app');
-
- if (type === 'tree') {
- expect(RepoStore.files[0].files.length).toBe(1);
- }
-
- RepoStore.path = '';
- });
- });
- });
-
- describe('file', () => {
- it('creates new file', () => {
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type: 'blob',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('testing');
- expect(RepoStore.files[0].type).toBe('blob');
- expect(RepoStore.files[0].tempFile).toBeTruthy();
- });
-
- it('does not create temp file when file already exists', () => {
- RepoStore.files.push(RepoHelper.serializeRepoEntity('blob', {
- name: 'testing',
- }));
-
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type: 'blob',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('testing');
- expect(RepoStore.files[0].type).toBe('blob');
- expect(RepoStore.files[0].tempFile).toBeUndefined();
- });
- });
-
- describe('tree', () => {
- it('creates new tree', () => {
- eventHub.$emit('createNewEntry', {
- name: 'testing',
- type: 'tree',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('testing');
- expect(RepoStore.files[0].type).toBe('tree');
- expect(RepoStore.files[0].tempFile).toBeTruthy();
- expect(RepoStore.files[0].files.length).toBe(1);
- expect(RepoStore.files[0].files[0].name).toBe('.gitkeep');
- });
-
- it('creates multiple trees when entryName has slashes', () => {
- eventHub.$emit('createNewEntry', {
- name: 'app/test',
- type: 'tree',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('app');
- expect(RepoStore.files[0].files[0].name).toBe('test');
- expect(RepoStore.files[0].files[0].files[0].name).toBe('.gitkeep');
- });
-
- it('creates tree in existing tree', () => {
- RepoStore.files.push(RepoHelper.serializeRepoEntity('tree', {
- name: 'app',
- }));
-
- eventHub.$emit('createNewEntry', {
- name: 'app/test',
- type: 'tree',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('app');
- expect(RepoStore.files[0].tempFile).toBeUndefined();
- expect(RepoStore.files[0].files[0].tempFile).toBeTruthy();
- expect(RepoStore.files[0].files[0].name).toBe('test');
- expect(RepoStore.files[0].files[0].files[0].name).toBe('.gitkeep');
- });
-
- it('does not create new tree when already exists', () => {
- RepoStore.files.push(RepoHelper.serializeRepoEntity('tree', {
- name: 'app',
- }));
-
- eventHub.$emit('createNewEntry', {
- name: 'app',
- type: 'tree',
- });
-
- expect(RepoStore.files.length).toBe(1);
- expect(RepoStore.files[0].name).toBe('app');
- expect(RepoStore.files[0].tempFile).toBeUndefined();
- expect(RepoStore.files[0].files.length).toBe(0);
- });
- });
- });
});