From 70dfa3a721700cf0151a7d097933d75684e69fc9 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 13:06:09 -0500 Subject: open and close issue via ajax request. With tests --- app/assets/javascripts/issue.js.coffee | 30 +++++++++++++++++++++ app/helpers/issues_helper.rb | 4 +++ app/views/projects/issues/show.html.haml | 13 +++------ spec/javascripts/fixtures/issues_show.html.haml | 5 +++- spec/javascripts/issue_spec.js.coffee | 36 +++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index eff80bf63bb..8d028268b81 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -8,11 +8,41 @@ class @Issue if $("a.btn-close").length @initTaskList() + @initIssueBtnEventListeners() initTaskList: -> $('.detail-page-description .js-task-list-container').taskList('enable') $(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList + initIssueBtnEventListeners: -> + $("a.btn-close, a.btn-reopen").on "click", (e) -> + e.preventDefault() + e.stopImmediatePropagation() + $this = $(this) + isClose = $this.hasClass('btn-close') + $this.prop("disabled", true) + url = $this.data('url') + $.ajax + type: 'PUT' + url: url, + error: (jqXHR, textStatus, errorThrown) -> + issueStatus = if isClose then 'close' else 'open' + console.log("Cannot #{issueStatus} this issue, at this time.") + success: (data, textStatus, jqXHR) -> + if data.saved + $this.addClass('hidden') + if isClose + $('a.btn-reopen').removeClass('hidden') + $('div.issue-box-closed').removeClass('hidden') + $('div.issue-box-open').addClass('hidden') + else + $('a.btn-close').removeClass('hidden') + $('div.issue-box-closed').addClass('hidden') + $('div.issue-box-open').removeClass('hidden') + else + console.log("Did not work") + $this.prop('disabled', false) + disableTaskList: -> $('.detail-page-description .js-task-list-container').taskList('disable') $(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container' diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index d2186427dba..1f0f6aeeac2 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -69,6 +69,10 @@ module IssuesHelper end end + def issue_button_visibility(issue, closed) + return 'hidden' if issue.closed? == closed + end + def issue_to_atom(xml, issue) xml.entry do xml.id namespace_project_issue_url(issue.project.namespace, diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml index 2fe6f88b2a9..9444a1c1d84 100644 --- a/app/views/projects/issues/show.html.haml +++ b/app/views/projects/issues/show.html.haml @@ -3,11 +3,8 @@ .issue .detail-page-header - .status-box{ class: status_box_class(@issue) } - - if @issue.closed? - Closed - - else - Open + .status-box{ class: "status-box-closed #{issue_button_visibility(@issue, false)}"} Closed + .status-box{ class: "status-box-open #{issue_button_visibility(@issue, true)}"} Open %span.identifier Issue ##{@issue.iid} %span.creator @@ -27,10 +24,8 @@ = icon('plus') New Issue - if can?(current_user, :update_issue, @issue) - - if @issue.closed? - = link_to 'Reopen', issue_path(@issue, issue: {state_event: :reopen}, status_only: true), method: :put, class: 'btn btn-grouped btn-reopen' - - else - = link_to 'Close', issue_path(@issue, issue: {state_event: :close}, status_only: true), method: :put, class: 'btn btn-grouped btn-close', title: 'Close Issue' + = link_to 'Reopen', '#', data: {no_turbolink: true, url: issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json')}, class: "btn btn-grouped btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen Issue' + = link_to 'Close', '#', data: {no_turbolink: true, url: issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json')}, class: "btn btn-grouped btn-close #{issue_button_visibility(@issue, true)}", title: 'Close Issue' = link_to edit_namespace_project_issue_path(@project.namespace, @project, @issue), class: 'btn btn-grouped issuable-edit' do = icon('pencil-square-o') diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml index 8447dfdda32..6c985a32966 100644 --- a/spec/javascripts/fixtures/issues_show.html.haml +++ b/spec/javascripts/fixtures/issues_show.html.haml @@ -1,4 +1,7 @@ -%a.btn-close +.issue-box.issue-box-open Open +.issue-box.issue-box-closed.hidden Closed +%a.btn-close{"data-url" => "http://gitlab/issues/6/close"} Close +%a.btn-reopen.hidden{"data-url" => "http://gitlab/issues/6/reopen"} Reopen .detail-page-description .description.js-task-list-container diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index 268e4c68c31..60df3a8878b 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -20,3 +20,39 @@ describe 'Issue', -> expect(req.data.issue.description).not.toBe(null) $('.js-task-list-field').trigger('tasklist:changed') +describe 'reopen/close issue', -> + fixture.preload('issues_show.html') + beforeEach -> + fixture.load('issues_show.html') + @issue = new Issue() + it 'closes an issue', -> + $.ajax = (obj) -> + expect(obj.type).toBe('PUT') + expect(obj.url).toBe('http://gitlab/issues/6/close') + obj.success saved: true + $btnClose = $('a.btn-close') + $btnReopen = $('a.btn-reopen') + expect($btnReopen.hasClass('hidden')).toBe(true) + expect($btnClose.text()).toBe('Close') + expect(typeof $btnClose.prop('disabled')).toBe('undefined') + $btnClose.trigger('click') + expect($btnClose.hasClass('hidden')).toBe(true) + expect($btnReopen.hasClass('hidden')).toBe(false) + expect($btnClose.prop('disabled')).toBe(false) + expect($('div.issue-box-open').hasClass('hidden')).toBe(true) + expect($('div.issue-box-closed').hasClass('hidden')).toBe(false) + it 'reopens an issue', -> + $.ajax = (obj) -> + expect(obj.type).toBe('PUT') + expect(obj.url).toBe('http://gitlab/issues/6/reopen') + obj.success saved: true + $btnClose = $('a.btn-close') + $btnReopen = $('a.btn-reopen') + expect(typeof $btnReopen.prop('disabled')).toBe('undefined') + expect($btnReopen.text()).toBe('Reopen') + $btnReopen.trigger('click') + expect($btnReopen.hasClass('hidden')).toBe(true) + expect($btnClose.hasClass('hidden')).toBe(false) + expect($btnReopen.prop('disabled')).toBe(false) + expect($('div.issue-box-open').hasClass('hidden')).toBe(false) + expect($('div.issue-box-closed').hasClass('hidden')).toBe(true) \ No newline at end of file -- cgit v1.2.1 From 531d06d170fd5cfcb6d4f6c919034c49266e42e9 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 16:16:04 -0500 Subject: removes `console.log`s --- app/assets/javascripts/issue.js.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 8d028268b81..1d57c24587d 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -27,7 +27,6 @@ class @Issue url: url, error: (jqXHR, textStatus, errorThrown) -> issueStatus = if isClose then 'close' else 'open' - console.log("Cannot #{issueStatus} this issue, at this time.") success: (data, textStatus, jqXHR) -> if data.saved $this.addClass('hidden') @@ -40,7 +39,6 @@ class @Issue $('div.issue-box-closed').addClass('hidden') $('div.issue-box-open').removeClass('hidden') else - console.log("Did not work") $this.prop('disabled', false) disableTaskList: -> -- cgit v1.2.1 From fec7c99e2f2221f22680c140b7d9b1d959d8aeb0 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 16:27:52 -0500 Subject: updates tests style for four-phase-testing as per: https://robots.thoughtbot.com/four-phase-test --- spec/javascripts/issue_spec.js.coffee | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index 60df3a8878b..f8e60565b9a 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -30,29 +30,45 @@ describe 'reopen/close issue', -> expect(obj.type).toBe('PUT') expect(obj.url).toBe('http://gitlab/issues/6/close') obj.success saved: true + + # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') expect($btnReopen.hasClass('hidden')).toBe(true) expect($btnClose.text()).toBe('Close') expect(typeof $btnClose.prop('disabled')).toBe('undefined') + + # excerize $btnClose.trigger('click') + + # verify expect($btnClose.hasClass('hidden')).toBe(true) expect($btnReopen.hasClass('hidden')).toBe(false) expect($btnClose.prop('disabled')).toBe(false) expect($('div.issue-box-open').hasClass('hidden')).toBe(true) expect($('div.issue-box-closed').hasClass('hidden')).toBe(false) + + # teardown it 'reopens an issue', -> $.ajax = (obj) -> expect(obj.type).toBe('PUT') expect(obj.url).toBe('http://gitlab/issues/6/reopen') obj.success saved: true + + # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') expect(typeof $btnReopen.prop('disabled')).toBe('undefined') expect($btnReopen.text()).toBe('Reopen') + + # excerize $btnReopen.trigger('click') + + # verify expect($btnReopen.hasClass('hidden')).toBe(true) expect($btnClose.hasClass('hidden')).toBe(false) expect($btnReopen.prop('disabled')).toBe(false) expect($('div.issue-box-open').hasClass('hidden')).toBe(false) - expect($('div.issue-box-closed').hasClass('hidden')).toBe(true) \ No newline at end of file + expect($('div.issue-box-closed').hasClass('hidden')).toBe(true) + + # teardown \ No newline at end of file -- cgit v1.2.1 From 3e7e7ae0aceaa8a805093841b07b9b5d9f911cb1 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 16:35:03 -0500 Subject: clarifies tests with methods like `toBeVisible()` etc. --- spec/javascripts/issue_spec.js.coffee | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index f8e60565b9a..f50640d1821 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -34,7 +34,7 @@ describe 'reopen/close issue', -> # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') - expect($btnReopen.hasClass('hidden')).toBe(true) + expect($btnReopen.toBeHidden()) expect($btnClose.text()).toBe('Close') expect(typeof $btnClose.prop('disabled')).toBe('undefined') @@ -42,11 +42,10 @@ describe 'reopen/close issue', -> $btnClose.trigger('click') # verify - expect($btnClose.hasClass('hidden')).toBe(true) - expect($btnReopen.hasClass('hidden')).toBe(false) - expect($btnClose.prop('disabled')).toBe(false) - expect($('div.issue-box-open').hasClass('hidden')).toBe(true) - expect($('div.issue-box-closed').hasClass('hidden')).toBe(false) + expect($btnClose.toBeHidden()) + expect($btnReopen.toBeVisible()) + expect($('div.issue-box-open').toBeVisible()) + expect($('div.issue-box-closed').toBeHidden()) # teardown it 'reopens an issue', -> @@ -58,17 +57,15 @@ describe 'reopen/close issue', -> # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') - expect(typeof $btnReopen.prop('disabled')).toBe('undefined') expect($btnReopen.text()).toBe('Reopen') # excerize $btnReopen.trigger('click') # verify - expect($btnReopen.hasClass('hidden')).toBe(true) - expect($btnClose.hasClass('hidden')).toBe(false) - expect($btnReopen.prop('disabled')).toBe(false) - expect($('div.issue-box-open').hasClass('hidden')).toBe(false) - expect($('div.issue-box-closed').hasClass('hidden')).toBe(true) + expect($btnReopen.toBeHidden()) + expect($btnClose.toBeVisible()) + expect($('div.issue-box-open').toBeVisible()) + expect($('div.issue-box-closed').toBeHidden()) # teardown \ No newline at end of file -- cgit v1.2.1 From 1f5b8e88f3fedc382555e89b5a6ba9be57d551c7 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 16:45:52 -0500 Subject: changes `data-url` to `href` for javascript url grabbing --- app/assets/javascripts/issue.js.coffee | 3 ++- app/views/projects/issues/show.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 1d57c24587d..ba5205fb471 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -16,12 +16,13 @@ class @Issue initIssueBtnEventListeners: -> $("a.btn-close, a.btn-reopen").on "click", (e) -> + console.log('closing') e.preventDefault() e.stopImmediatePropagation() $this = $(this) isClose = $this.hasClass('btn-close') $this.prop("disabled", true) - url = $this.data('url') + url = $this.attr('href') $.ajax type: 'PUT' url: url, diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml index 9444a1c1d84..4ca122ba55f 100644 --- a/app/views/projects/issues/show.html.haml +++ b/app/views/projects/issues/show.html.haml @@ -24,8 +24,8 @@ = icon('plus') New Issue - if can?(current_user, :update_issue, @issue) - = link_to 'Reopen', '#', data: {no_turbolink: true, url: issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json')}, class: "btn btn-grouped btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen Issue' - = link_to 'Close', '#', data: {no_turbolink: true, url: issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json')}, class: "btn btn-grouped btn-close #{issue_button_visibility(@issue, true)}", title: 'Close Issue' + = link_to 'Reopen', issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-grouped btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen Issue' + = link_to 'Close', issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-grouped btn-close #{issue_button_visibility(@issue, true)}", title: 'Close Issue' = link_to edit_namespace_project_issue_path(@project.namespace, @project, @issue), class: 'btn btn-grouped issuable-edit' do = icon('pencil-square-o') -- cgit v1.2.1 From 801b801bf08a0bc6df8ba13775f3050d091ce84d Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 16:46:36 -0500 Subject: removes console logs --- app/assets/javascripts/issue.js.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index ba5205fb471..1423daa281b 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -16,7 +16,6 @@ class @Issue initIssueBtnEventListeners: -> $("a.btn-close, a.btn-reopen").on "click", (e) -> - console.log('closing') e.preventDefault() e.stopImmediatePropagation() $this = $(this) -- cgit v1.2.1 From 453479143dd4784d7284b2e6f98694ff8fc18ce8 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 17:03:28 -0500 Subject: adds alerts for when http request errors out in some way. --- app/assets/javascripts/issue.js.coffee | 2 ++ spec/javascripts/issue_spec.js.coffee | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 1423daa281b..2e0ef99a587 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -27,6 +27,7 @@ class @Issue url: url, error: (jqXHR, textStatus, errorThrown) -> issueStatus = if isClose then 'close' else 'open' + new Flash("Issues update failed", 'alert') success: (data, textStatus, jqXHR) -> if data.saved $this.addClass('hidden') @@ -39,6 +40,7 @@ class @Issue $('div.issue-box-closed').addClass('hidden') $('div.issue-box-open').removeClass('hidden') else + new Flash("Issues update failed", 'alert') $this.prop('disabled', false) disableTaskList: -> diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index f50640d1821..ef78cfbc653 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -31,41 +31,32 @@ describe 'reopen/close issue', -> expect(obj.url).toBe('http://gitlab/issues/6/close') obj.success saved: true - # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') expect($btnReopen.toBeHidden()) expect($btnClose.text()).toBe('Close') expect(typeof $btnClose.prop('disabled')).toBe('undefined') - # excerize $btnClose.trigger('click') - # verify expect($btnClose.toBeHidden()) expect($btnReopen.toBeVisible()) expect($('div.issue-box-open').toBeVisible()) expect($('div.issue-box-closed').toBeHidden()) - # teardown it 'reopens an issue', -> $.ajax = (obj) -> expect(obj.type).toBe('PUT') expect(obj.url).toBe('http://gitlab/issues/6/reopen') obj.success saved: true - # setup $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') expect($btnReopen.text()).toBe('Reopen') - # excerize $btnReopen.trigger('click') - # verify expect($btnReopen.toBeHidden()) expect($btnClose.toBeVisible()) expect($('div.issue-box-open').toBeVisible()) - expect($('div.issue-box-closed').toBeHidden()) - - # teardown \ No newline at end of file + expect($('div.issue-box-closed').toBeHidden()) \ No newline at end of file -- cgit v1.2.1 From 3ea3d9ef284fcfaaa1b631e98926df7dae4129c9 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Mon, 21 Dec 2015 17:10:27 -0500 Subject: changes `issue-box` to `status-box` since html was changed as well --- app/assets/javascripts/issue.js.coffee | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 2e0ef99a587..1a9e03e4ee3 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -6,7 +6,7 @@ class @Issue # Prevent duplicate event bindings @disableTaskList() - if $("a.btn-close").length + if $('a.btn-close').length @initTaskList() @initIssueBtnEventListeners() @@ -15,32 +15,32 @@ class @Issue $(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList initIssueBtnEventListeners: -> - $("a.btn-close, a.btn-reopen").on "click", (e) -> + $('a.btn-close, a.btn-reopen').on 'click', (e) -> e.preventDefault() e.stopImmediatePropagation() $this = $(this) isClose = $this.hasClass('btn-close') - $this.prop("disabled", true) + $this.prop('disabled', true) url = $this.attr('href') $.ajax type: 'PUT' url: url, error: (jqXHR, textStatus, errorThrown) -> issueStatus = if isClose then 'close' else 'open' - new Flash("Issues update failed", 'alert') + new Flash('Issues update failed', 'alert') success: (data, textStatus, jqXHR) -> if data.saved $this.addClass('hidden') if isClose $('a.btn-reopen').removeClass('hidden') - $('div.issue-box-closed').removeClass('hidden') - $('div.issue-box-open').addClass('hidden') + $('div.status-box-closed').removeClass('hidden') + $('div.status-box-open').addClass('hidden') else $('a.btn-close').removeClass('hidden') - $('div.issue-box-closed').addClass('hidden') - $('div.issue-box-open').removeClass('hidden') + $('div.status-box-closed').addClass('hidden') + $('div.status-box-open').removeClass('hidden') else - new Flash("Issues update failed", 'alert') + new Flash('Issues update failed', 'alert') $this.prop('disabled', false) disableTaskList: -> -- cgit v1.2.1 From 7e43fa67096f60856d1cf862f245367bc710a44f Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Wed, 23 Dec 2015 16:56:36 -0500 Subject: fixes tests to work with jasmine/jquery --- spec/javascripts/fixtures/issues_show.html.haml | 11 +++++++---- spec/javascripts/issue_spec.js.coffee | 18 +++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml index 6c985a32966..f67ea5a13c7 100644 --- a/spec/javascripts/fixtures/issues_show.html.haml +++ b/spec/javascripts/fixtures/issues_show.html.haml @@ -1,7 +1,10 @@ -.issue-box.issue-box-open Open -.issue-box.issue-box-closed.hidden Closed -%a.btn-close{"data-url" => "http://gitlab/issues/6/close"} Close -%a.btn-reopen.hidden{"data-url" => "http://gitlab/issues/6/reopen"} Reopen +:css + .hidden { display: none !important; } + +.status-box.status-box-open Open +.status-box.status-box-closed.hidden Closed +%a.btn-close{"href" => "http://gitlab/issues/6/close"} Close +%a.btn-reopen.hidden{"href" => "http://gitlab/issues/6/reopen"} Reopen .detail-page-description .description.js-task-list-container diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index ef78cfbc653..142eb05cc67 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -33,16 +33,16 @@ describe 'reopen/close issue', -> $btnClose = $('a.btn-close') $btnReopen = $('a.btn-reopen') - expect($btnReopen.toBeHidden()) + expect($btnReopen).toBeHidden() expect($btnClose.text()).toBe('Close') expect(typeof $btnClose.prop('disabled')).toBe('undefined') $btnClose.trigger('click') - expect($btnClose.toBeHidden()) - expect($btnReopen.toBeVisible()) - expect($('div.issue-box-open').toBeVisible()) - expect($('div.issue-box-closed').toBeHidden()) + expect($btnReopen).toBeVisible() + expect($btnClose).toBeHidden() + expect($('div.status-box-closed')).toBeVisible() + expect($('div.status-box-open')).toBeHidden() it 'reopens an issue', -> $.ajax = (obj) -> @@ -56,7 +56,7 @@ describe 'reopen/close issue', -> $btnReopen.trigger('click') - expect($btnReopen.toBeHidden()) - expect($btnClose.toBeVisible()) - expect($('div.issue-box-open').toBeVisible()) - expect($('div.issue-box-closed').toBeHidden()) \ No newline at end of file + expect($btnReopen).toBeHidden() + expect($btnClose).toBeVisible() + expect($('div.status-box-open')).toBeVisible() + expect($('div.status-box-closed')).toBeHidden() \ No newline at end of file -- cgit v1.2.1 From e11ee5ff01bf031cd4fda377a7444f2ba4d50f40 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Wed, 23 Dec 2015 17:41:05 -0500 Subject: adds test for issue close/reopen failure --- app/assets/javascripts/issue.js.coffee | 5 ++- spec/javascripts/fixtures/issues_show.html.haml | 13 ++++++- spec/javascripts/issue_spec.js.coffee | 51 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 1a9e03e4ee3..3d9d514a9c7 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -15,6 +15,7 @@ class @Issue $(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList initIssueBtnEventListeners: -> + issueFailMessage = 'Unable to update this issue at this time.' $('a.btn-close, a.btn-reopen').on 'click', (e) -> e.preventDefault() e.stopImmediatePropagation() @@ -27,7 +28,7 @@ class @Issue url: url, error: (jqXHR, textStatus, errorThrown) -> issueStatus = if isClose then 'close' else 'open' - new Flash('Issues update failed', 'alert') + new Flash(issueFailMessage, 'alert') success: (data, textStatus, jqXHR) -> if data.saved $this.addClass('hidden') @@ -40,7 +41,7 @@ class @Issue $('div.status-box-closed').addClass('hidden') $('div.status-box-open').removeClass('hidden') else - new Flash('Issues update failed', 'alert') + new Flash(issueFailMessage, 'alert') $this.prop('disabled', false) disableTaskList: -> diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml index f67ea5a13c7..dd01b6378c5 100644 --- a/spec/javascripts/fixtures/issues_show.html.haml +++ b/spec/javascripts/fixtures/issues_show.html.haml @@ -1,10 +1,19 @@ :css .hidden { display: none !important; } +.flash-container + - if alert + .flash-alert + = alert + + - elsif notice + .flash-notice + = notice + .status-box.status-box-open Open .status-box.status-box-closed.hidden Closed -%a.btn-close{"href" => "http://gitlab/issues/6/close"} Close -%a.btn-reopen.hidden{"href" => "http://gitlab/issues/6/reopen"} Reopen +%a.btn-close{"href" => "http://gitlab.com/issues/6/close"} Close +%a.btn-reopen.hidden{"href" => "http://gitlab.com/issues/6/reopen"} Reopen .detail-page-description .description.js-task-list-container diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index 142eb05cc67..f0a57d99c56 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -1,3 +1,4 @@ +#= require flash #= require issue describe 'Issue', -> @@ -28,7 +29,7 @@ describe 'reopen/close issue', -> it 'closes an issue', -> $.ajax = (obj) -> expect(obj.type).toBe('PUT') - expect(obj.url).toBe('http://gitlab/issues/6/close') + expect(obj.url).toBe('http://gitlab.com/issues/6/close') obj.success saved: true $btnClose = $('a.btn-close') @@ -44,10 +45,56 @@ describe 'reopen/close issue', -> expect($('div.status-box-closed')).toBeVisible() expect($('div.status-box-open')).toBeHidden() + it 'fails to closes an issue with success:false', -> + + $.ajax = (obj) -> + expect(obj.type).toBe('PUT') + expect(obj.url).toBe('http://goesnowhere.nothing/whereami') + obj.success saved: false + + $btnClose = $('a.btn-close') + $btnReopen = $('a.btn-reopen') + $btnClose.attr('href','http://goesnowhere.nothing/whereami') + expect($btnReopen).toBeHidden() + expect($btnClose.text()).toBe('Close') + expect(typeof $btnClose.prop('disabled')).toBe('undefined') + + $btnClose.trigger('click') + + expect($btnReopen).toBeHidden() + expect($btnClose).toBeVisible() + expect($('div.status-box-closed')).toBeHidden() + expect($('div.status-box-open')).toBeVisible() + expect($('div.flash-alert')).toBeVisible() + expect($('div.flash-alert').text()).toBe('Unable to update this issue at this time.') + + it 'fails to closes an issue with HTTP error', -> + + $.ajax = (obj) -> + expect(obj.type).toBe('PUT') + expect(obj.url).toBe('http://goesnowhere.nothing/whereami') + obj.error() + + $btnClose = $('a.btn-close') + $btnReopen = $('a.btn-reopen') + $btnClose.attr('href','http://goesnowhere.nothing/whereami') + expect($btnReopen).toBeHidden() + expect($btnClose.text()).toBe('Close') + expect(typeof $btnClose.prop('disabled')).toBe('undefined') + + $btnClose.trigger('click') + + expect($btnReopen).toBeHidden() + expect($btnClose).toBeVisible() + expect($('div.status-box-closed')).toBeHidden() + expect($('div.status-box-open')).toBeVisible() + expect($('div.flash-alert')).toBeVisible() + expect($('div.flash-alert').text()).toBe('Unable to update this issue at this time.') + it 'reopens an issue', -> $.ajax = (obj) -> expect(obj.type).toBe('PUT') - expect(obj.url).toBe('http://gitlab/issues/6/reopen') + expect(obj.url).toBe('http://gitlab.com/issues/6/reopen') obj.success saved: true $btnClose = $('a.btn-close') -- cgit v1.2.1 From 00e967a07f476f7df7aaddc652258668af392f5d Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Wed, 23 Dec 2015 20:57:16 -0500 Subject: removes unused `alert` from issue spec. Requires flash in the *implementation* instead of the spec. --- app/assets/javascripts/issue.js.coffee | 1 + spec/javascripts/fixtures/issues_show.html.haml | 9 ++------- spec/javascripts/issue_spec.js.coffee | 1 - 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index 3d9d514a9c7..c256ec8f41b 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -1,3 +1,4 @@ +#= require flash #= require jquery.waitforimages #= require task_list diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml index dd01b6378c5..470cabeafbb 100644 --- a/spec/javascripts/fixtures/issues_show.html.haml +++ b/spec/javascripts/fixtures/issues_show.html.haml @@ -2,13 +2,8 @@ .hidden { display: none !important; } .flash-container - - if alert - .flash-alert - = alert - - - elsif notice - .flash-notice - = notice + .flash-alert + .flash-notice .status-box.status-box-open Open .status-box.status-box-closed.hidden Closed diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee index f0a57d99c56..7e67c778861 100644 --- a/spec/javascripts/issue_spec.js.coffee +++ b/spec/javascripts/issue_spec.js.coffee @@ -1,4 +1,3 @@ -#= require flash #= require issue describe 'Issue', -> -- cgit v1.2.1