BigW Consortium Gitlab

fixed issue_spec transient failure

parent a3356bce
...@@ -92,21 +92,6 @@ describe('Issue', function() { ...@@ -92,21 +92,6 @@ describe('Issue', function() {
const action = isIssueInitiallyOpen ? 'close' : 'reopen'; const action = isIssueInitiallyOpen ? 'close' : 'reopen';
let mock; let mock;
function ajaxSpy(req) {
if (req.url === this.$triggeredButton.attr('href')) {
expect(req.type).toBe('PUT');
expectNewBranchButtonState(true, false);
return this.issueStateDeferred;
} else if (req.url === Issue.createMrDropdownWrap.dataset.canCreatePath) {
expect(req.type).toBe('GET');
expectNewBranchButtonState(true, false);
return this.canCreateBranchDeferred;
}
expect(req.url).toBe('unexpected');
return null;
}
function mockCloseButtonResponseSuccess(url, response) { function mockCloseButtonResponseSuccess(url, response) {
mock.onPut(url).reply(() => { mock.onPut(url).reply(() => {
expectNewBranchButtonState(true, false); expectNewBranchButtonState(true, false);
...@@ -119,6 +104,12 @@ describe('Issue', function() { ...@@ -119,6 +104,12 @@ describe('Issue', function() {
mock.onPut(url).networkError(); mock.onPut(url).networkError();
} }
function mockCanCreateBranch(canCreateBranch) {
mock.onGet(/(.*)\/can_create_branch$/).reply(200, {
can_create_branch: canCreateBranch,
});
}
beforeEach(function() { beforeEach(function() {
if (isIssueInitiallyOpen) { if (isIssueInitiallyOpen) {
loadFixtures('issues/open-issue.html.raw'); loadFixtures('issues/open-issue.html.raw');
...@@ -126,6 +117,11 @@ describe('Issue', function() { ...@@ -126,6 +117,11 @@ describe('Issue', function() {
loadFixtures('issues/closed-issue.html.raw'); loadFixtures('issues/closed-issue.html.raw');
} }
mock = new MockAdapter(axios);
mock.onGet(/(.*)\/related_branches$/).reply(200, {});
mock.onGet(/(.*)\/referenced_merge_requests$/).reply(200, {});
findElements(isIssueInitiallyOpen); findElements(isIssueInitiallyOpen);
this.issue = new Issue(); this.issue = new Issue();
expectIssueState(isIssueInitiallyOpen); expectIssueState(isIssueInitiallyOpen);
...@@ -135,27 +131,21 @@ describe('Issue', function() { ...@@ -135,27 +131,21 @@ describe('Issue', function() {
this.$projectIssuesCounter = $('.issue_counter').first(); this.$projectIssuesCounter = $('.issue_counter').first();
this.$projectIssuesCounter.text('1,001'); this.$projectIssuesCounter.text('1,001');
this.issueStateDeferred = new jQuery.Deferred(); spyOn(axios, 'get').and.callThrough();
this.canCreateBranchDeferred = new jQuery.Deferred();
mock = new MockAdapter(axios);
spyOn(jQuery, 'ajax').and.callFake(ajaxSpy.bind(this));
}); });
afterEach(() => { afterEach(() => {
mock.restore(); mock.restore();
$('div.flash-alert').remove();
}); });
it(`${action}s the issue`, function(done) { it(`${action}s the issue`, function(done) {
mockCloseButtonResponseSuccess(this.$triggeredButton.attr('href'), { mockCloseButtonResponseSuccess(this.$triggeredButton.attr('href'), {
id: 34 id: 34
}); });
mockCanCreateBranch(!isIssueInitiallyOpen);
this.$triggeredButton.trigger('click'); this.$triggeredButton.trigger('click');
this.canCreateBranchDeferred.resolve({
can_create_branch: !isIssueInitiallyOpen
});
setTimeout(() => { setTimeout(() => {
expectIssueState(!isIssueInitiallyOpen); expectIssueState(!isIssueInitiallyOpen);
...@@ -171,10 +161,9 @@ describe('Issue', function() { ...@@ -171,10 +161,9 @@ describe('Issue', function() {
mockCloseButtonResponseSuccess(this.$triggeredButton.attr('href'), { mockCloseButtonResponseSuccess(this.$triggeredButton.attr('href'), {
saved: false saved: false
}); });
mockCanCreateBranch(isIssueInitiallyOpen);
this.$triggeredButton.trigger('click'); this.$triggeredButton.trigger('click');
this.canCreateBranchDeferred.resolve({
can_create_branch: isIssueInitiallyOpen
});
setTimeout(() => { setTimeout(() => {
expectIssueState(isIssueInitiallyOpen); expectIssueState(isIssueInitiallyOpen);
...@@ -189,10 +178,9 @@ describe('Issue', function() { ...@@ -189,10 +178,9 @@ describe('Issue', function() {
it(`fails to ${action} the issue if HTTP error occurs`, function(done) { it(`fails to ${action} the issue if HTTP error occurs`, function(done) {
mockCloseButtonResponseError(this.$triggeredButton.attr('href')); mockCloseButtonResponseError(this.$triggeredButton.attr('href'));
mockCanCreateBranch(isIssueInitiallyOpen);
this.$triggeredButton.trigger('click'); this.$triggeredButton.trigger('click');
this.canCreateBranchDeferred.resolve({
can_create_branch: isIssueInitiallyOpen
});
setTimeout(() => { setTimeout(() => {
expectIssueState(isIssueInitiallyOpen); expectIssueState(isIssueInitiallyOpen);
...@@ -207,18 +195,25 @@ describe('Issue', function() { ...@@ -207,18 +195,25 @@ describe('Issue', function() {
it('disables the new branch button if Ajax call fails', function() { it('disables the new branch button if Ajax call fails', function() {
mockCloseButtonResponseError(this.$triggeredButton.attr('href')); mockCloseButtonResponseError(this.$triggeredButton.attr('href'));
mock.onGet(/(.*)\/can_create_branch$/).networkError();
this.$triggeredButton.trigger('click'); this.$triggeredButton.trigger('click');
this.canCreateBranchDeferred.reject();
expectNewBranchButtonState(false, false); expectNewBranchButtonState(false, false);
}); });
it('does not trigger Ajax call if new branch button is missing', function() { it('does not trigger Ajax call if new branch button is missing', function(done) {
mockCloseButtonResponseError(this.$triggeredButton.attr('href')); mockCloseButtonResponseError(this.$triggeredButton.attr('href'));
Issue.$btnNewBranch = $(); Issue.$btnNewBranch = $();
this.canCreateBranchDeferred = null; this.canCreateBranchDeferred = null;
this.$triggeredButton.trigger('click'); this.$triggeredButton.trigger('click');
setTimeout(() => {
expect(axios.get).not.toHaveBeenCalled();
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