BigW Consortium Gitlab

fixed issue_spec transient failure

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