Commit d9b7c33f authored by Tim Zallmann's avatar Tim Zallmann

Updated MR Widget Header Test

parent ae3abc38
...@@ -17,46 +17,58 @@ describe('MRWidgetHeader', () => { ...@@ -17,46 +17,58 @@ describe('MRWidgetHeader', () => {
describe('computed', () => { describe('computed', () => {
describe('shouldShowCommitsBehindText', () => { describe('shouldShowCommitsBehindText', () => {
it('return true when there are divergedCommitsCount', () => { it('return true when there are divergedCommitsCount', () => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 12, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 12,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranch: 'mr-widget-refactor',
targetBranch: 'master', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
} }); targetBranch: 'master',
statusPath: 'abc',
},
});
expect(vm.shouldShowCommitsBehindText).toEqual(true); expect(vm.shouldShowCommitsBehindText).toEqual(true);
}); });
it('returns false where there are no divergedComits count', () => { it('returns false where there are no divergedComits count', () => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 0, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 0,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranch: 'mr-widget-refactor',
targetBranch: 'master', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
} }); targetBranch: 'master',
statusPath: 'abc',
},
});
expect(vm.shouldShowCommitsBehindText).toEqual(false); expect(vm.shouldShowCommitsBehindText).toEqual(false);
}); });
}); });
describe('commitsText', () => { describe('commitsText', () => {
it('returns singular when there is one commit', () => { it('returns singular when there is one commit', () => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 1, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 1,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranch: 'mr-widget-refactor',
targetBranch: 'master', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
} }); targetBranch: 'master',
statusPath: 'abc',
},
});
expect(vm.commitsText).toEqual('1 commit behind'); expect(vm.commitsText).toEqual('1 commit behind');
}); });
it('returns plural when there is more than one commit', () => { it('returns plural when there is more than one commit', () => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 2, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 2,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranch: 'mr-widget-refactor',
targetBranch: 'master', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
} }); targetBranch: 'master',
statusPath: 'abc',
},
});
expect(vm.commitsText).toEqual('2 commits behind'); expect(vm.commitsText).toEqual('2 commits behind');
}); });
...@@ -66,24 +78,27 @@ describe('MRWidgetHeader', () => { ...@@ -66,24 +78,27 @@ describe('MRWidgetHeader', () => {
describe('template', () => { describe('template', () => {
describe('common elements', () => { describe('common elements', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 12, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 12,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranch: 'mr-widget-refactor',
sourceBranchRemoved: false, sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
targetBranchPath: 'foo/bar/commits-path', sourceBranchRemoved: false,
targetBranchTreePath: 'foo/bar/tree/path', targetBranchPath: 'foo/bar/commits-path',
targetBranch: 'master', targetBranchTreePath: 'foo/bar/tree/path',
isOpen: true, targetBranch: 'master',
emailPatchesPath: '/mr/email-patches', isOpen: true,
plainDiffPath: '/mr/plainDiffPath', emailPatchesPath: '/mr/email-patches',
} }); plainDiffPath: '/mr/plainDiffPath',
statusPath: 'abc',
},
});
}); });
it('renders source branch link', () => { it('renders source branch link', () => {
expect( expect(vm.$el.querySelector('.js-source-branch').innerHTML).toEqual(
vm.$el.querySelector('.js-source-branch').innerHTML, '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
).toEqual('<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>'); );
}); });
it('renders clipboard button', () => { it('renders clipboard button', () => {
...@@ -101,18 +116,21 @@ describe('MRWidgetHeader', () => { ...@@ -101,18 +116,21 @@ describe('MRWidgetHeader', () => {
}); });
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 12, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 12,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranch: 'mr-widget-refactor',
sourceBranchRemoved: false, sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
targetBranchPath: 'foo/bar/commits-path', sourceBranchRemoved: false,
targetBranchTreePath: 'foo/bar/tree/path', targetBranchPath: 'foo/bar/commits-path',
targetBranch: 'master', targetBranchTreePath: 'foo/bar/tree/path',
isOpen: true, targetBranch: 'master',
emailPatchesPath: '/mr/email-patches', isOpen: true,
plainDiffPath: '/mr/plainDiffPath', emailPatchesPath: '/mr/email-patches',
} }); plainDiffPath: '/mr/plainDiffPath',
statusPath: 'abc',
},
});
}); });
it('renders checkout branch button with modal trigger', () => { it('renders checkout branch button with modal trigger', () => {
...@@ -123,39 +141,49 @@ describe('MRWidgetHeader', () => { ...@@ -123,39 +141,49 @@ describe('MRWidgetHeader', () => {
expect(button.getAttribute('data-toggle')).toEqual('modal'); expect(button.getAttribute('data-toggle')).toEqual('modal');
}); });
it('renders web ide button', () => {
const button = vm.$el.querySelector('.js-web-ide');
expect(button.textContent.trim()).toEqual('Open in Web IDE');
expect(button.getAttribute('href')).toEqual('undefined/-/ide/projectabc');
});
it('renders download dropdown with links', () => { it('renders download dropdown with links', () => {
expect( expect(vm.$el.querySelector('.js-download-email-patches').textContent.trim()).toEqual(
vm.$el.querySelector('.js-download-email-patches').textContent.trim(), 'Email patches',
).toEqual('Email patches'); );
expect( expect(vm.$el.querySelector('.js-download-email-patches').getAttribute('href')).toEqual(
vm.$el.querySelector('.js-download-email-patches').getAttribute('href'), '/mr/email-patches',
).toEqual('/mr/email-patches'); );
expect( expect(vm.$el.querySelector('.js-download-plain-diff').textContent.trim()).toEqual(
vm.$el.querySelector('.js-download-plain-diff').textContent.trim(), 'Plain diff',
).toEqual('Plain diff'); );
expect( expect(vm.$el.querySelector('.js-download-plain-diff').getAttribute('href')).toEqual(
vm.$el.querySelector('.js-download-plain-diff').getAttribute('href'), '/mr/plainDiffPath',
).toEqual('/mr/plainDiffPath'); );
}); });
}); });
describe('with a closed merge request', () => { describe('with a closed merge request', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 12, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 12,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranch: 'mr-widget-refactor',
sourceBranchRemoved: false, sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
targetBranchPath: 'foo/bar/commits-path', sourceBranchRemoved: false,
targetBranchTreePath: 'foo/bar/tree/path', targetBranchPath: 'foo/bar/commits-path',
targetBranch: 'master', targetBranchTreePath: 'foo/bar/tree/path',
isOpen: false, targetBranch: 'master',
emailPatchesPath: '/mr/email-patches', isOpen: false,
plainDiffPath: '/mr/plainDiffPath', emailPatchesPath: '/mr/email-patches',
} }); plainDiffPath: '/mr/plainDiffPath',
statusPath: 'abc',
},
});
}); });
it('does not render checkout branch button with modal trigger', () => { it('does not render checkout branch button with modal trigger', () => {
...@@ -165,30 +193,29 @@ describe('MRWidgetHeader', () => { ...@@ -165,30 +193,29 @@ describe('MRWidgetHeader', () => {
}); });
it('does not render download dropdown with links', () => { it('does not render download dropdown with links', () => {
expect( expect(vm.$el.querySelector('.js-download-email-patches')).toEqual(null);
vm.$el.querySelector('.js-download-email-patches'),
).toEqual(null);
expect( expect(vm.$el.querySelector('.js-download-plain-diff')).toEqual(null);
vm.$el.querySelector('.js-download-plain-diff'),
).toEqual(null);
}); });
}); });
describe('without diverged commits', () => { describe('without diverged commits', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 0, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 0,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranch: 'mr-widget-refactor',
sourceBranchRemoved: false, sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
targetBranchPath: 'foo/bar/commits-path', sourceBranchRemoved: false,
targetBranchTreePath: 'foo/bar/tree/path', targetBranchPath: 'foo/bar/commits-path',
targetBranch: 'master', targetBranchTreePath: 'foo/bar/tree/path',
isOpen: true, targetBranch: 'master',
emailPatchesPath: '/mr/email-patches', isOpen: true,
plainDiffPath: '/mr/plainDiffPath', emailPatchesPath: '/mr/email-patches',
} }); plainDiffPath: '/mr/plainDiffPath',
statusPath: 'abc',
},
});
}); });
it('does not render diverged commits info', () => { it('does not render diverged commits info', () => {
...@@ -198,22 +225,27 @@ describe('MRWidgetHeader', () => { ...@@ -198,22 +225,27 @@ describe('MRWidgetHeader', () => {
describe('with diverged commits', () => { describe('with diverged commits', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
divergedCommitsCount: 12, mr: {
sourceBranch: 'mr-widget-refactor', divergedCommitsCount: 12,
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranch: 'mr-widget-refactor',
sourceBranchRemoved: false, sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
targetBranchPath: 'foo/bar/commits-path', sourceBranchRemoved: false,
targetBranchTreePath: 'foo/bar/tree/path', targetBranchPath: 'foo/bar/commits-path',
targetBranch: 'master', targetBranchTreePath: 'foo/bar/tree/path',
isOpen: true, targetBranch: 'master',
emailPatchesPath: '/mr/email-patches', isOpen: true,
plainDiffPath: '/mr/plainDiffPath', emailPatchesPath: '/mr/email-patches',
} }); plainDiffPath: '/mr/plainDiffPath',
statusPath: 'abc',
},
});
}); });
it('renders diverged commits info', () => { it('renders diverged commits info', () => {
expect(vm.$el.querySelector('.diverged-commits-count').textContent.trim()).toEqual('(12 commits behind)'); expect(vm.$el.querySelector('.diverged-commits-count').textContent.trim()).toEqual(
'(12 commits behind)',
);
}); });
}); });
}); });
......
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