summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-01-31 17:51:53 +0000
committerPhil Hughes <me@iamphill.com>2018-01-31 17:51:53 +0000
commit0f895147ff52d71c7ced5db536d2be6154839112 (patch)
tree96dc9d1923a7b0f42833b2ae2acd89b94f08f319
parenta3356bce09d1a5e1222254a8e193b98f90d71e4e (diff)
downloadgitlab-ce-0f895147ff52d71c7ced5db536d2be6154839112.tar.gz
fixed issue_spec transient failure
-rw-r--r--spec/javascripts/issue_spec.js59
1 files changed, 27 insertions, 32 deletions
diff --git a/spec/javascripts/issue_spec.js b/spec/javascripts/issue_spec.js
index 7eaaa0ff027..5245bf6455c 100644
--- a/spec/javascripts/issue_spec.js
+++ b/spec/javascripts/issue_spec.js
@@ -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();
+ });
});
});
});