/
main.module.spec.coffee
124 lines (111 loc) · 4.43 KB
/
main.module.spec.coffee
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
beforeEach ->
module 'waterfall_view'
# Mock modalService
module ($provide) ->
$provide.service '$modal', -> open: ->
null
describe 'Waterfall view controller', ->
$rootScope = $state = elem = w = $document = $window = $modal = config = $timeout = null
injected = ($injector) ->
$rootScope = $injector.get('$rootScope')
scope = $rootScope.$new()
$compile = $injector.get('$compile')
$controller = $injector.get('$controller')
$state = $injector.get('$state')
$document = $injector.get('$document')
$window = $injector.get('$window')
$modal = $injector.get('$modal')
$timeout = $injector.get('$timeout')
config = $injector.get('config')
elem = angular.element('<div></div>')
elem.append($compile('<ui-view></ui-view>')(scope))
$document.find('body').append(elem)
$state.transitionTo('waterfall')
$rootScope.$digest()
scope = $document.find('.waterfall').scope()
w = $document.find('.waterfall').controller()
spyOn(w, 'mouseOver').and.callThrough()
spyOn(w, 'mouseOut').and.callThrough()
spyOn(w, 'mouseMove').and.callThrough()
spyOn(w, 'click').and.callThrough()
spyOn(w, 'loadMore').and.callThrough()
# We don't want the setHeight to call loadMore
spyOn(w, 'setHeight').and.callFake ->
# Data is loaded
$timeout.flush()
beforeEach(inject(injected))
# make sure we remove the element from the dom
afterEach ->
expect($document.find("svg").length).toEqual(2)
elem.remove()
expect($document.find('svg').length).toEqual(0)
it 'should be defined', ->
expect(w).toBeDefined()
it 'should bind the builds and builders to scope', ->
limit = config.plugins.waterfall_view.limit
expect(w.builds).toBeDefined()
expect(w.builds.length).toBe(limit)
expect(w.builders).toBeDefined()
expect(w.builders.length).not.toBe(0)
it 'should create svg elements', ->
expect(elem.find('svg').length).toBeGreaterThan(1)
expect(elem.find('g').length).toBeGreaterThan(1)
it 'should trigger mouse events on builds', ->
e = d3.select('.build')
n = e.node()
# Test click event
spyOn($modal, 'open')
expect($modal.open).not.toHaveBeenCalled()
n.__onclick()
expect($modal.open).toHaveBeenCalled()
# Test mouseover
expect(w.mouseOver).not.toHaveBeenCalled()
expect(e.select('.svg-tooltip').empty()).toBe(true)
n.__onmouseover({})
expect(w.mouseOver).toHaveBeenCalled()
expect(e.select('.svg-tooltip').empty()).toBe(false)
# Test mousemove
expect(w.mouseMove).not.toHaveBeenCalled()
n.__onmousemove({})
expect(w.mouseMove).toHaveBeenCalled()
# Test mouseout
expect(w.mouseOut).not.toHaveBeenCalled()
expect(e.select('.svg-tooltip').empty()).toBe(false)
n.__onmouseout({})
expect(w.mouseOut).toHaveBeenCalled()
expect(e.select('.svg-tooltip').empty()).toBe(true)
it 'should rerender the waterfall on resize', ->
spyOn(w, 'render').and.callThrough()
expect(w.render).not.toHaveBeenCalled()
angular.element($window).triggerHandler('resize')
expect(w.render).toHaveBeenCalled()
it 'should rerender the waterfall on data change', ->
spyOn(w, 'render').and.callThrough()
expect(w.render).not.toHaveBeenCalled()
w.loadMore()
$timeout.flush()
expect(w.render).toHaveBeenCalled()
it 'should lazy load data on scroll', ->
spyOn(w, 'getHeight').and.returnValue(900)
e = d3.select('.inner-content')
n = e.node()
expect(w.loadMore).not.toHaveBeenCalled()
angular.element(n).triggerHandler('scroll')
expect(w.loadMore).toHaveBeenCalled()
it 'should have string representations of result codes', ->
testBuild =
complete: false
started_at: 0
expect(w.result(testBuild)).toBe('pending')
testBuild.complete = true
expect(w.result(testBuild)).toBe('unknown')
results =
0: 'success'
1: 'warnings'
2: 'failure'
3: 'skipped'
4: 'exception'
5: 'cancelled'
for i in [0..5]
testBuild.results = i
expect(w.result(testBuild)).toBe(results[i])