BigW Consortium Gitlab

[ci skip] Improve repo_commit_section_spec

parent 4402eefa
......@@ -77,7 +77,7 @@ export default RepoCommitSection;
</div>
<!-- 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>
<div class="col-md-4">
<span class="help-block">{{targetBranch}}</span>
......
......@@ -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();
});
......
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