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, {
mr: {
divergedCommitsCount: 12, divergedCommitsCount: 12,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
targetBranch: 'master', 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, {
mr: {
divergedCommitsCount: 0, divergedCommitsCount: 0,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
targetBranch: 'master', 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, {
mr: {
divergedCommitsCount: 1, divergedCommitsCount: 1,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
targetBranch: 'master', 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, {
mr: {
divergedCommitsCount: 2, divergedCommitsCount: 2,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">Link</a>',
targetBranch: 'master', targetBranch: 'master',
} }); statusPath: 'abc',
},
});
expect(vm.commitsText).toEqual('2 commits behind'); expect(vm.commitsText).toEqual('2 commits behind');
}); });
...@@ -66,7 +78,8 @@ describe('MRWidgetHeader', () => { ...@@ -66,7 +78,8 @@ describe('MRWidgetHeader', () => {
describe('template', () => { describe('template', () => {
describe('common elements', () => { describe('common elements', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
mr: {
divergedCommitsCount: 12, divergedCommitsCount: 12,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
...@@ -77,13 +90,15 @@ describe('MRWidgetHeader', () => { ...@@ -77,13 +90,15 @@ describe('MRWidgetHeader', () => {
isOpen: true, isOpen: true,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
plainDiffPath: '/mr/plainDiffPath', 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,7 +116,8 @@ describe('MRWidgetHeader', () => { ...@@ -101,7 +116,8 @@ describe('MRWidgetHeader', () => {
}); });
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
mr: {
divergedCommitsCount: 12, divergedCommitsCount: 12,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
...@@ -112,7 +128,9 @@ describe('MRWidgetHeader', () => { ...@@ -112,7 +128,9 @@ describe('MRWidgetHeader', () => {
isOpen: true, isOpen: true,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
plainDiffPath: '/mr/plainDiffPath', plainDiffPath: '/mr/plainDiffPath',
} }); statusPath: 'abc',
},
});
}); });
it('renders checkout branch button with modal trigger', () => { it('renders checkout branch button with modal trigger', () => {
...@@ -123,28 +141,36 @@ describe('MRWidgetHeader', () => { ...@@ -123,28 +141,36 @@ 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, {
mr: {
divergedCommitsCount: 12, divergedCommitsCount: 12,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
...@@ -155,7 +181,9 @@ describe('MRWidgetHeader', () => { ...@@ -155,7 +181,9 @@ describe('MRWidgetHeader', () => {
isOpen: false, isOpen: false,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
plainDiffPath: '/mr/plainDiffPath', 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,19 +193,16 @@ describe('MRWidgetHeader', () => { ...@@ -165,19 +193,16 @@ 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, {
mr: {
divergedCommitsCount: 0, divergedCommitsCount: 0,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
...@@ -188,7 +213,9 @@ describe('MRWidgetHeader', () => { ...@@ -188,7 +213,9 @@ describe('MRWidgetHeader', () => {
isOpen: true, isOpen: true,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
plainDiffPath: '/mr/plainDiffPath', plainDiffPath: '/mr/plainDiffPath',
} }); statusPath: 'abc',
},
});
}); });
it('does not render diverged commits info', () => { it('does not render diverged commits info', () => {
...@@ -198,7 +225,8 @@ describe('MRWidgetHeader', () => { ...@@ -198,7 +225,8 @@ describe('MRWidgetHeader', () => {
describe('with diverged commits', () => { describe('with diverged commits', () => {
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { mr: { vm = mountComponent(Component, {
mr: {
divergedCommitsCount: 12, divergedCommitsCount: 12,
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>', sourceBranchLink: '<a href="/foo/bar/mr-widget-refactor">mr-widget-refactor</a>',
...@@ -209,11 +237,15 @@ describe('MRWidgetHeader', () => { ...@@ -209,11 +237,15 @@ describe('MRWidgetHeader', () => {
isOpen: true, isOpen: true,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
plainDiffPath: '/mr/plainDiffPath', 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