From e216a90b9bfa066615a893fb511ce60db52a4b27 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 12:44:05 +0100 Subject: [PATCH 1/8] [ci skip] Remove console from loadingError --- app/assets/javascripts/repo/repo_helper.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/javascripts/repo/repo_helper.js b/app/assets/javascripts/repo/repo_helper.js index 5663dc22b0f..f58d746c0a8 100644 --- a/app/assets/javascripts/repo/repo_helper.js +++ b/app/assets/javascripts/repo/repo_helper.js @@ -283,8 +283,7 @@ const RepoHelper = { } }, - loadingError(e) { - console.log(e) + loadingError() { Flash('Unable to load the file at this time.'); }, }; From 4402eefa422553e0ae8761b12d8888c4763d160e Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 14:08:53 +0100 Subject: [PATCH 2/8] [ci skip] Improve repo_binary_viewer_spec --- .../repo/repo_binary_viewer_spec.js | 73 ++++++++++++++----- .../repo/repo_commit_section_spec.js | 2 +- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/spec/javascripts/repo/repo_binary_viewer_spec.js b/spec/javascripts/repo/repo_binary_viewer_spec.js index 4b9ced8d9bc..abc0706effa 100644 --- a/spec/javascripts/repo/repo_binary_viewer_spec.js +++ b/spec/javascripts/repo/repo_binary_viewer_spec.js @@ -9,40 +9,77 @@ describe('RepoBinaryViewer', () => { return new RepoBinaryViewer().$mount(); } - it('renders an img if its png', () => { - const binaryTypes = { - png: true, - }; - const activeFile = { - name: 'name', - }; + function createActiveFile(type, activeFile = {}) { + const file = activeFile; + + switch (type) { + case 'svg': + case 'png': + file.name = 'name'; + break; + case 'md': + file.html = 'html'; + break; + default: + break; + } + + return file; + } + + function setActiveBinary(type) { + const binaryTypes = {}; + binaryTypes[type] = true; + + const activeFile = createActiveFile(type); + const uri = 'uri'; Store.binary = true; Store.binaryTypes = binaryTypes; Store.activeFile = activeFile; Store.pngBlobWithDataURI = uri; + + return { + activeFile, + uri, + }; + } + + function assertBinaryImg(img, activeFile, uri) { + expect(img.src).toMatch(`/${uri}`); + expect(img.alt).toEqual(activeFile.name); + } + + it('renders an img if its png', () => { + const { activeFile, uri } = setActiveBinary('png'); const vm = createComponent(); const img = vm.$el.querySelector(':scope > img'); - expect(img.src).toMatch(`/${uri}`); - expect(img.alt).toEqual(activeFile.name); + assertBinaryImg(img, activeFile, uri); + }); + + it('renders an img if its svg', () => { + const { activeFile, uri } = setActiveBinary('svg'); + const vm = createComponent(); + const img = vm.$el.querySelector(':scope > img'); + + assertBinaryImg(img, activeFile, uri); }); it('renders an div with content if its markdown', () => { - const binaryTypes = { - md: true, - }; - const activeFile = { - html: 'markdown', - }; - Store.binary = true; - Store.binaryTypes = binaryTypes; - Store.activeFile = activeFile; + const { activeFile } = setActiveBinary('md'); const vm = createComponent(); expect(vm.$el.querySelector(':scope > div').innerHTML).toEqual(activeFile.html); }); + it('renders no preview message if its unknown', () => { + setActiveBinary('unknown'); + const vm = createComponent(); + + expect(vm.$el.querySelector('.binary-unknown').textContent).toMatch('Binary file. No preview available.'); + }); + it('does not render if no binary', () => { Store.binary = false; const vm = createComponent(); diff --git a/spec/javascripts/repo/repo_commit_section_spec.js b/spec/javascripts/repo/repo_commit_section_spec.js index e5ffcb8a4ee..0f044ff681b 100644 --- a/spec/javascripts/repo/repo_commit_section_spec.js +++ b/spec/javascripts/repo/repo_commit_section_spec.js @@ -4,7 +4,7 @@ import RepoStore from '~/repo/repo_store'; import RepoHelper from '~/repo/repo_helper'; import Api from '~/api'; -describe('RepoCommitSection', () => { +fdescribe('RepoCommitSection', () => { const openedFiles = [{ id: 0, changed: true, From 3abceda69e306ade8e0866f7e31c82f634be4e53 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 15:18:29 +0100 Subject: [PATCH 3/8] [ci skip] Improve repo_commit_section_spec --- .../javascripts/repo/repo_commit_section.vue | 2 +- .../repo/repo_commit_section_spec.js | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/repo/repo_commit_section.vue b/app/assets/javascripts/repo/repo_commit_section.vue index c006b32824b..e942a8faed5 100644 --- a/app/assets/javascripts/repo/repo_commit_section.vue +++ b/app/assets/javascripts/repo/repo_commit_section.vue @@ -77,7 +77,7 @@ export default RepoCommitSection; -
+
{{targetBranch}} diff --git a/spec/javascripts/repo/repo_commit_section_spec.js b/spec/javascripts/repo/repo_commit_section_spec.js index 0f044ff681b..9dcf909effa 100644 --- a/spec/javascripts/repo/repo_commit_section_spec.js +++ b/spec/javascripts/repo/repo_commit_section_spec.js @@ -5,21 +5,21 @@ import RepoHelper from '~/repo/repo_helper'; import Api from '~/api'; fdescribe('RepoCommitSection', () => { + const branch = 'master'; const openedFiles = [{ id: 0, changed: true, - url: 'master/url0', + url: `${branch}/url0`, newContent: 'a', }, { id: 1, changed: true, - url: 'master/url1', + url: `${branch}/url1`, newContent: 'b', }, { id: 2, changed: false, }]; - const branch = 'master'; function createComponent() { const RepoCommitSection = Vue.extend(repoCommitSection); @@ -29,13 +29,16 @@ fdescribe('RepoCommitSection', () => { it('renders a commit section', () => { RepoStore.isCommitable = true; + RepoStore.targetBranch = branch; RepoStore.openedFiles = openedFiles; + spyOn(RepoHelper, 'getBranch').and.returnValue(branch); const vm = createComponent(); const changedFiles = [...vm.$el.querySelectorAll('.changed-files > li')]; const commitMessage = vm.$el.querySelector('#commit-message'); const submitCommit = vm.$el.querySelector('.submit-commit'); + const targetBranch = vm.$el.querySelector('.target-branch'); expect(vm.$el.querySelector(':scope > form')).toBeTruthy(); expect(vm.$el.querySelector('.staged-files').textContent).toEqual('Staged files (2)'); @@ -51,7 +54,10 @@ fdescribe('RepoCommitSection', () => { expect(commitMessage.name).toEqual('commit-message'); expect(submitCommit.type).toEqual('submit'); expect(submitCommit.disabled).toBeTruthy(); + expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeFalsy(); expect(vm.$el.querySelector('.commit-summary').textContent).toEqual('Commit 2 files'); + expect(targetBranch.querySelector(':scope > label').textContent).toEqual('Target branch'); + expect(targetBranch.querySelector('.help-block').textContent).toEqual(branch); }); it('does not render if not isCommitable', () => { @@ -82,6 +88,8 @@ fdescribe('RepoCommitSection', () => { RepoStore.openedFiles = openedFiles; RepoStore.projectId = projectId; + spyOn(RepoHelper, 'getBranch').and.returnValue(branch); + const vm = createComponent(); const commitMessageEl = vm.$el.querySelector('#commit-message'); const submitCommit = vm.$el.querySelector('.submit-commit'); @@ -102,15 +110,18 @@ fdescribe('RepoCommitSection', () => { expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeTruthy(); const args = Api.commitMultiple.calls.allArgs()[0]; - const { commit_message, actions } = args[1]; + const { commit_message, actions, branch: payloadBranch } = args[1]; expect(args[0]).toBe(projectId); expect(commit_message).toBe(commitMessage); expect(actions.length).toEqual(2); + expect(payloadBranch).toEqual(branch); expect(actions[0].action).toEqual('update'); expect(actions[1].action).toEqual('update'); - expect(actions[0].content).toEqual('a'); - expect(actions[1].content).toEqual('b'); + expect(actions[0].content).toEqual(openedFiles[0].newContent); + expect(actions[1].content).toEqual(openedFiles[1].newContent); + expect(actions[0].file_path).toEqual(RepoHelper.getFilePathFromFullPath(openedFiles[0].url, branch)); + expect(actions[1].file_path).toEqual(RepoHelper.getFilePathFromFullPath(openedFiles[1].url, branch)); done(); }); From 0786b87eb8510ce730ca4fd1e87e70c56129e72c Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 15:20:45 +0100 Subject: [PATCH 4/8] [ci skip] Add missing :key attrs --- app/assets/javascripts/repo/repo_commit_section.vue | 2 +- app/assets/javascripts/repo/repo_loading_file.vue | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/repo/repo_commit_section.vue b/app/assets/javascripts/repo/repo_commit_section.vue index e942a8faed5..b4bfd3813c6 100644 --- a/app/assets/javascripts/repo/repo_commit_section.vue +++ b/app/assets/javascripts/repo/repo_commit_section.vue @@ -61,7 +61,7 @@ export default RepoCommitSection;
    -
  • +
  • {{file}}
diff --git a/app/assets/javascripts/repo/repo_loading_file.vue b/app/assets/javascripts/repo/repo_loading_file.vue index c2d38ee50dc..38e9f16d041 100644 --- a/app/assets/javascripts/repo/repo_loading_file.vue +++ b/app/assets/javascripts/repo/repo_loading_file.vue @@ -32,19 +32,19 @@ export default RepoLoadingFile;
-
+
-
+
-
+
From a1f2bd7daa038b41b61db6147a31394f5abfa73e Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 15:27:58 +0100 Subject: [PATCH 5/8] [ci skip] Remove lock from ce --- app/assets/javascripts/repo/repo_file_buttons.vue | 1 - spec/javascripts/repo/repo_commit_section_spec.js | 2 +- spec/javascripts/repo/repo_file_buttons_spec.js | 3 +-- spec/javascripts/repo/repo_file_options_spec.js | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/repo/repo_file_buttons.vue b/app/assets/javascripts/repo/repo_file_buttons.vue index 4090ece420b..e2752e05cf1 100644 --- a/app/assets/javascripts/repo/repo_file_buttons.vue +++ b/app/assets/javascripts/repo/repo_file_buttons.vue @@ -51,7 +51,6 @@ export default RepoFileButtons; Blame History - Lock
{{activeFileLabel}} diff --git a/spec/javascripts/repo/repo_commit_section_spec.js b/spec/javascripts/repo/repo_commit_section_spec.js index 9dcf909effa..fd454d0570d 100644 --- a/spec/javascripts/repo/repo_commit_section_spec.js +++ b/spec/javascripts/repo/repo_commit_section_spec.js @@ -4,7 +4,7 @@ import RepoStore from '~/repo/repo_store'; import RepoHelper from '~/repo/repo_helper'; import Api from '~/api'; -fdescribe('RepoCommitSection', () => { +describe('RepoCommitSection', () => { const branch = 'master'; const openedFiles = [{ id: 0, diff --git a/spec/javascripts/repo/repo_file_buttons_spec.js b/spec/javascripts/repo/repo_file_buttons_spec.js index 882a8bf3f87..8de42f908b4 100644 --- a/spec/javascripts/repo/repo_file_buttons_spec.js +++ b/spec/javascripts/repo/repo_file_buttons_spec.js @@ -9,7 +9,7 @@ describe('RepoFileButtons', () => { return new RepoFileButtons().$mount(); } - it('renders Raw, Blame, History, Permalink, Lock and Preview toggle', () => { + it('renders Raw, Blame, History, Permalink and Preview toggle', () => { const activeFile = { extension: 'md', url: 'url', @@ -34,7 +34,6 @@ describe('RepoFileButtons', () => { expect(history.href).toMatch(`/${activeFile.url}`); expect(history.textContent).toEqual('History'); expect(vm.$el.querySelector('.permalink').textContent).toEqual('Permalink'); - expect(vm.$el.querySelector('.lock').textContent).toEqual('Lock'); expect(vm.$el.querySelector('.preview').textContent).toEqual(activeFileLabel); }); diff --git a/spec/javascripts/repo/repo_file_options_spec.js b/spec/javascripts/repo/repo_file_options_spec.js index cb840851620..a6ef09f6374 100644 --- a/spec/javascripts/repo/repo_file_options_spec.js +++ b/spec/javascripts/repo/repo_file_options_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import repoFileOptions from '~/repo/repo_file_options.vue'; -describe('RepoFileOptions', () => { +fdescribe('RepoFileOptions', () => { const projectName = 'projectName'; function createComponent(propsData) { From 1cb18b00f1bcf45e243a4990c84296fbcb89b7af Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Wed, 2 Aug 2017 15:39:44 +0100 Subject: [PATCH 6/8] [ci skip] Improved repo_file_spec --- app/assets/javascripts/repo/repo_file.vue | 2 +- .../repo/repo_file_options_spec.js | 2 +- spec/javascripts/repo/repo_file_spec.js | 21 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/repo/repo_file.vue b/app/assets/javascripts/repo/repo_file.vue index 571f3cd5bdb..143d0281400 100644 --- a/app/assets/javascripts/repo/repo_file.vue +++ b/app/assets/javascripts/repo/repo_file.vue @@ -42,7 +42,7 @@ export default RepoFile;