summaryrefslogtreecommitdiff
path: root/spec/javascripts/merge_request_widget_spec.js.coffee
blob: 92b7eeb1116d0b11acd3f16ff0a94808fd8a3501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#= require merge_request_widget

describe 'MergeRequestWidget', ->

  beforeEach ->
    window.notifyPermissions = () ->
    window.notify = () ->
    @opts = {
      ci_status_url:"http://sampledomain.local/ci/getstatus",
      ci_status:"",
      ci_message: {
        normal: "Build {{status}} for \"{{title}}\"",
        preparing: "{{status}} build for \"{{title}}\""
      },
      ci_title: {
        preparing: "{{status}} build",
        normal: "Build {{status}}"
      },
      gitlab_icon:"gitlab_logo.png",
      builds_path:"http://sampledomain.local/sampleBuildsPath"
    }
    @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(false)
      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(false)
      expect(spy).not.toHaveBeenCalled()

    it 'should not display a notification on the first check after the widget has been created', ->
      spy = spyOn(window, 'notify')
      @class = new MergeRequestWidget(@opts)
      @class.getCIStatus(true)
      expect(spy).not.toHaveBeenCalled()