summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/merge_request_widget.js.coffee12
-rw-r--r--spec/javascripts/merge_request_widget_spec.js.coffee35
2 files changed, 41 insertions, 6 deletions
diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee
index 065626beeb8..1abda3530c4 100644
--- a/app/assets/javascripts/merge_request_widget.js.coffee
+++ b/app/assets/javascripts/merge_request_widget.js.coffee
@@ -68,13 +68,13 @@ class @MergeRequestWidget
$.getJSON @opts.ci_status_url, (data) =>
@readyForCICheck = true
- if @firstCICheck
- @firstCICheck = false
+ if @firstCICheck || @opts.ci_status is ''
+ if @firstCICheck
+ @firstCICheck = false
@opts.ci_status = data.status
-
- if @opts.ci_status is ''
- @opts.ci_status = data.status
- return
+ @showCIStatus data.status
+ if data.coverage
+ @showCICoverage data.coverage
if data.status isnt @opts.ci_status and data.status?
@showCIStatus data.status
diff --git a/spec/javascripts/merge_request_widget_spec.js.coffee b/spec/javascripts/merge_request_widget_spec.js.coffee
new file mode 100644
index 00000000000..e1fb610654e
--- /dev/null
+++ b/spec/javascripts/merge_request_widget_spec.js.coffee
@@ -0,0 +1,35 @@
+#= require merge_request_widget
+
+describe 'MergeRequestWidget', ->
+
+ beforeEach ->
+ window.notifyPermissions = () ->
+ @opts = {ci_status_url:"http://sampledomain.local/ci/getstatus",ci_status:""}
+ @class = new MergeRequestWidget(@opts)
+ @ciStatusData = {"title":"Sample MR title","sha":"12a34bc5","status":"success","coverage":98}
+
+ describe 'getCIStatus', ->
+ beforeEach ->
+ spyOn(jQuery, 'getJSON').and.callFake (req, cb) =>
+ cb(@ciStatusData)
+
+ it 'should call showCIStatus even if a notification should not be displayed', ->
+ spy = spyOn(@class, 'showCIStatus').and.stub()
+ @class.getCIStatus(false)
+ expect(spy).toHaveBeenCalledWith(@ciStatusData.status)
+
+ it 'should call showCIStatus when a notification should be displayed', ->
+ spy = spyOn(@class, 'showCIStatus').and.stub()
+ @class.getCIStatus(true)
+ expect(spy).toHaveBeenCalledWith(@ciStatusData.status)
+
+ it 'should call showCICoverage when the coverage rate is set', ->
+ spy = spyOn(@class, 'showCICoverage').and.stub()
+ @class.getCIStatus(true)
+ expect(spy).toHaveBeenCalledWith(@ciStatusData.coverage)
+
+ it 'should not call showCICoverage when the coverage rate is not set', ->
+ @ciStatusData.coverage = null
+ spy = spyOn(@class, 'showCICoverage').and.stub()
+ @class.getCIStatus(true)
+ expect(spy).not.toHaveBeenCalled()