summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/components
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/repo/components')
-rw-r--r--spec/javascripts/repo/components/new_branch_form_spec.js122
-rw-r--r--spec/javascripts/repo/components/repo_spec.js96
2 files changed, 218 insertions, 0 deletions
diff --git a/spec/javascripts/repo/components/new_branch_form_spec.js b/spec/javascripts/repo/components/new_branch_form_spec.js
new file mode 100644
index 00000000000..c9c5ce096fc
--- /dev/null
+++ b/spec/javascripts/repo/components/new_branch_form_spec.js
@@ -0,0 +1,122 @@
+import Vue from 'vue';
+import newBranchForm from '~/repo/components/new_branch_form.vue';
+import eventHub from '~/repo/event_hub';
+import RepoStore from '~/repo/stores/repo_store';
+import createComponent from '../../helpers/vue_mount_component_helper';
+
+describe('Multi-file editor new branch form', () => {
+ let vm;
+
+ beforeEach(() => {
+ const Component = Vue.extend(newBranchForm);
+
+ RepoStore.currentBranch = 'master';
+
+ vm = createComponent(Component, {
+ currentBranch: RepoStore.currentBranch,
+ });
+ });
+
+ afterEach(() => {
+ vm.$destroy();
+
+ RepoStore.currentBranch = '';
+ });
+
+ describe('template', () => {
+ it('renders submit as disabled', () => {
+ expect(vm.$el.querySelector('.btn').getAttribute('disabled')).toBe('disabled');
+ });
+
+ it('enables the submit button when branch is not empty', (done) => {
+ vm.branchName = 'testing';
+
+ Vue.nextTick(() => {
+ expect(vm.$el.querySelector('.btn').getAttribute('disabled')).toBeNull();
+
+ done();
+ });
+ });
+
+ it('displays current branch creating from', (done) => {
+ Vue.nextTick(() => {
+ expect(vm.$el.querySelector('p').textContent.replace(/\s+/g, ' ').trim()).toBe('Create from: master');
+
+ done();
+ });
+ });
+ });
+
+ describe('submitNewBranch', () => {
+ it('sets to loading', () => {
+ vm.submitNewBranch();
+
+ expect(vm.loading).toBeTruthy();
+ });
+
+ it('hides current flash element', (done) => {
+ vm.$refs.flashContainer.innerHTML = '<div class="flash-alert"></div>';
+
+ vm.submitNewBranch();
+
+ Vue.nextTick(() => {
+ expect(vm.$el.querySelector('.flash-alert')).toBeNull();
+
+ done();
+ });
+ });
+
+ it('emits an event with branchName', () => {
+ spyOn(eventHub, '$emit');
+
+ vm.branchName = 'testing';
+
+ vm.submitNewBranch();
+
+ expect(eventHub.$emit).toHaveBeenCalledWith('createNewBranch', 'testing');
+ });
+ });
+
+ describe('showErrorMessage', () => {
+ it('sets loading to false', () => {
+ vm.loading = true;
+
+ vm.showErrorMessage();
+
+ expect(vm.loading).toBeFalsy();
+ });
+
+ it('creates flash element', () => {
+ vm.showErrorMessage('error message');
+
+ expect(vm.$el.querySelector('.flash-alert')).not.toBeNull();
+ expect(vm.$el.querySelector('.flash-alert').textContent.trim()).toBe('error message');
+ });
+ });
+
+ describe('createdNewBranch', () => {
+ it('set loading to false', () => {
+ vm.loading = true;
+
+ vm.createdNewBranch();
+
+ expect(vm.loading).toBeFalsy();
+ });
+
+ it('resets branch name', () => {
+ vm.branchName = 'testing';
+
+ vm.createdNewBranch();
+
+ expect(vm.branchName).toBe('');
+ });
+
+ it('sets the dropdown toggle text', () => {
+ vm.dropdownText = document.createElement('span');
+
+ vm.createdNewBranch('branch name');
+
+ expect(vm.dropdownText.textContent).toBe('branch name');
+ });
+ });
+});
diff --git a/spec/javascripts/repo/components/repo_spec.js b/spec/javascripts/repo/components/repo_spec.js
new file mode 100644
index 00000000000..3558a155728
--- /dev/null
+++ b/spec/javascripts/repo/components/repo_spec.js
@@ -0,0 +1,96 @@
+import Vue from 'vue';
+import repo from '~/repo/components/repo.vue';
+import RepoStore from '~/repo/stores/repo_store';
+import Service from '~/repo/services/repo_service';
+import eventHub from '~/repo/event_hub';
+import createComponent from '../../helpers/vue_mount_component_helper';
+
+describe('repo component', () => {
+ let vm;
+
+ beforeEach(() => {
+ const Component = Vue.extend(repo);
+
+ RepoStore.currentBranch = 'master';
+
+ vm = createComponent(Component);
+ });
+
+ afterEach(() => {
+ vm.$destroy();
+
+ RepoStore.currentBranch = '';
+ });
+
+ describe('createNewBranch', () => {
+ beforeEach(() => {
+ spyOn(history, 'pushState');
+ });
+
+ describe('success', () => {
+ beforeEach(() => {
+ spyOn(Service, 'createBranch').and.returnValue(Promise.resolve({
+ data: {
+ name: 'test',
+ },
+ }));
+ });
+
+ it('calls createBranch with branchName', () => {
+ eventHub.$emit('createNewBranch', 'test');
+
+ expect(Service.createBranch).toHaveBeenCalledWith({
+ branch: 'test',
+ ref: RepoStore.currentBranch,
+ });
+ });
+
+ it('pushes new history state', (done) => {
+ RepoStore.currentBranch = 'master';
+
+ spyOn(vm, 'getCurrentLocation').and.returnValue('http://test.com/master');
+
+ eventHub.$emit('createNewBranch', 'test');
+
+ setTimeout(() => {
+ expect(history.pushState).toHaveBeenCalledWith(jasmine.anything(), '', 'http://test.com/test');
+ done();
+ });
+ });
+
+ it('updates stores currentBranch', (done) => {
+ eventHub.$emit('createNewBranch', 'test');
+
+ setTimeout(() => {
+ expect(RepoStore.currentBranch).toBe('test');
+
+ done();
+ });
+ });
+ });
+
+ describe('failure', () => {
+ beforeEach(() => {
+ spyOn(Service, 'createBranch').and.returnValue(Promise.reject({
+ response: {
+ data: {
+ message: 'test',
+ },
+ },
+ }));
+ });
+
+ it('emits createNewBranchError event', (done) => {
+ spyOn(eventHub, '$emit').and.callThrough();
+
+ eventHub.$emit('createNewBranch', 'test');
+
+ setTimeout(() => {
+ expect(eventHub.$emit).toHaveBeenCalledWith('createNewBranchError', 'test');
+
+ done();
+ });
+ });
+ });
+ });
+});