Commit 3abceda6 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

[ci skip] Improve repo_commit_section_spec

parent 4402eefa
...@@ -77,7 +77,7 @@ export default RepoCommitSection; ...@@ -77,7 +77,7 @@ export default RepoCommitSection;
</div> </div>
<!-- Button Drop Down <!-- Button Drop Down
--> -->
<div class="form-group"> <div class="form-group target-branch">
<label class="col-md-4 control-label" for="target-branch">Target branch</label> <label class="col-md-4 control-label" for="target-branch">Target branch</label>
<div class="col-md-4"> <div class="col-md-4">
<span class="help-block">{{targetBranch}}</span> <span class="help-block">{{targetBranch}}</span>
......
...@@ -5,21 +5,21 @@ import RepoHelper from '~/repo/repo_helper'; ...@@ -5,21 +5,21 @@ import RepoHelper from '~/repo/repo_helper';
import Api from '~/api'; import Api from '~/api';
fdescribe('RepoCommitSection', () => { fdescribe('RepoCommitSection', () => {
const branch = 'master';
const openedFiles = [{ const openedFiles = [{
id: 0, id: 0,
changed: true, changed: true,
url: 'master/url0', url: `${branch}/url0`,
newContent: 'a', newContent: 'a',
}, { }, {
id: 1, id: 1,
changed: true, changed: true,
url: 'master/url1', url: `${branch}/url1`,
newContent: 'b', newContent: 'b',
}, { }, {
id: 2, id: 2,
changed: false, changed: false,
}]; }];
const branch = 'master';
function createComponent() { function createComponent() {
const RepoCommitSection = Vue.extend(repoCommitSection); const RepoCommitSection = Vue.extend(repoCommitSection);
...@@ -29,13 +29,16 @@ fdescribe('RepoCommitSection', () => { ...@@ -29,13 +29,16 @@ fdescribe('RepoCommitSection', () => {
it('renders a commit section', () => { it('renders a commit section', () => {
RepoStore.isCommitable = true; RepoStore.isCommitable = true;
RepoStore.targetBranch = branch;
RepoStore.openedFiles = openedFiles; RepoStore.openedFiles = openedFiles;
spyOn(RepoHelper, 'getBranch').and.returnValue(branch); spyOn(RepoHelper, 'getBranch').and.returnValue(branch);
const vm = createComponent(); const vm = createComponent();
const changedFiles = [...vm.$el.querySelectorAll('.changed-files > li')]; const changedFiles = [...vm.$el.querySelectorAll('.changed-files > li')];
const commitMessage = vm.$el.querySelector('#commit-message'); const commitMessage = vm.$el.querySelector('#commit-message');
const submitCommit = vm.$el.querySelector('.submit-commit'); 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(':scope > form')).toBeTruthy();
expect(vm.$el.querySelector('.staged-files').textContent).toEqual('Staged files (2)'); expect(vm.$el.querySelector('.staged-files').textContent).toEqual('Staged files (2)');
...@@ -51,7 +54,10 @@ fdescribe('RepoCommitSection', () => { ...@@ -51,7 +54,10 @@ fdescribe('RepoCommitSection', () => {
expect(commitMessage.name).toEqual('commit-message'); expect(commitMessage.name).toEqual('commit-message');
expect(submitCommit.type).toEqual('submit'); expect(submitCommit.type).toEqual('submit');
expect(submitCommit.disabled).toBeTruthy(); expect(submitCommit.disabled).toBeTruthy();
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeFalsy();
expect(vm.$el.querySelector('.commit-summary').textContent).toEqual('Commit 2 files'); 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', () => { it('does not render if not isCommitable', () => {
...@@ -82,6 +88,8 @@ fdescribe('RepoCommitSection', () => { ...@@ -82,6 +88,8 @@ fdescribe('RepoCommitSection', () => {
RepoStore.openedFiles = openedFiles; RepoStore.openedFiles = openedFiles;
RepoStore.projectId = projectId; RepoStore.projectId = projectId;
spyOn(RepoHelper, 'getBranch').and.returnValue(branch);
const vm = createComponent(); const vm = createComponent();
const commitMessageEl = vm.$el.querySelector('#commit-message'); const commitMessageEl = vm.$el.querySelector('#commit-message');
const submitCommit = vm.$el.querySelector('.submit-commit'); const submitCommit = vm.$el.querySelector('.submit-commit');
...@@ -102,15 +110,18 @@ fdescribe('RepoCommitSection', () => { ...@@ -102,15 +110,18 @@ fdescribe('RepoCommitSection', () => {
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeTruthy(); expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeTruthy();
const args = Api.commitMultiple.calls.allArgs()[0]; 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(args[0]).toBe(projectId);
expect(commit_message).toBe(commitMessage); expect(commit_message).toBe(commitMessage);
expect(actions.length).toEqual(2); expect(actions.length).toEqual(2);
expect(payloadBranch).toEqual(branch);
expect(actions[0].action).toEqual('update'); expect(actions[0].action).toEqual('update');
expect(actions[1].action).toEqual('update'); expect(actions[1].action).toEqual('update');
expect(actions[0].content).toEqual('a'); expect(actions[0].content).toEqual(openedFiles[0].newContent);
expect(actions[1].content).toEqual('b'); 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(); done();
}); });
......
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