Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Aug 17, 2014
1 parent 73c561d commit 5e1cdd4
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion www/waterfall_view/package.json
Expand Up @@ -5,6 +5,6 @@
"npm": ">=1.4.10"
},
"devDependencies": {
"guanlecoja": "0.2.9"
"guanlecoja": "0.2.10"
}
}
18 changes: 9 additions & 9 deletions www/waterfall_view/src/module/main.module.coffee
Expand Up @@ -9,7 +9,7 @@ class WaterfallView extends App

class Waterfall extends Controller
self = null
constructor: (@$scope, $q, @$window, @$modal, @buildbotService, d3Service, @dataService, scaleService, @$timeout, config) ->
constructor: (@$scope, $q, @$window, @$modal, @buildbotService, d3Service, @dataService, scaleService, config) ->
self = @

# Show the loading spinner
Expand Down Expand Up @@ -374,7 +374,7 @@ class Waterfall extends Controller
###
# Event actions
###
mouseOver = (build) ->
@mouseOver = (build) ->
e = self.d3.select(@)
mouse = self.d3.mouse(@)
self.addTicks(build)
Expand Down Expand Up @@ -430,23 +430,23 @@ class Waterfall extends Controller
# Text format
.text((step, i) -> "#{i + 1}. #{step.name} #{duration(step)}")

mouseMove = (build) ->
@mouseMove = (build) ->
e = self.d3.select(@)

# Move the tooltip to the mouse position
mouse = self.d3.mouse(@)
e.select('.svg-tooltip')
.attr('transform', "translate(#{mouse[0]}, #{mouse[1]})")

mouseOut = (build) ->
@mouseOut = (build) ->
e = self.d3.select(@)
self.removeTicks()
self.drawYAxis()

# Remove tooltip
e.selectAll('.svg-tooltip').remove()

click = (build) ->
@click = (build) ->
# Open modal on click
modal = self.$modal.open
templateUrl: 'waterfall_view/views/modal.html'
Expand All @@ -457,10 +457,10 @@ class Waterfall extends Controller

# Add event listeners
builds
.on('mouseover', mouseOver)
.on('mousemove', mouseMove)
.on('mouseout', mouseOut)
.on('click', click)
.on('mouseover', @mouseOver)
.on('mousemove', @mouseMove)
.on('mouseout', @mouseOut)
.on('click', @click)

###
# Render the waterfall view
Expand Down
44 changes: 39 additions & 5 deletions www/waterfall_view/src/module/main.module.spec.coffee
@@ -1,8 +1,12 @@
beforeEach ->
module 'waterfall_view'
# Mock modalService
module ($provide) ->
$provide.service '$modal', -> open: ->
null

describe 'Waterfall view controller', ->
$rootScope = $state = elem = w = $document = $window = config = null
$rootScope = $state = elem = w = $document = $window = $modal = config = null

injected = ($injector) ->
$rootScope = $injector.get('$rootScope')
Expand All @@ -12,15 +16,18 @@ describe 'Waterfall view controller', ->
$state = $injector.get('$state')
$document = $injector.get('$document')
$window = $injector.get('$window')
$modal = $injector.get('$modal')
config = $injector.get('config')
elem = angular.element('<div></div>')
$document.find('body').append(elem)
elem.append($compile('<ui-view></ui-view>')(scope))
$document.find('body').append(elem)

$state.transitionTo('waterfall')
$rootScope.$digest()
w = $document.find('.waterfall').scope().w

spyOn(w, 'setHeight').and.callFake ->

beforeEach(inject(injected))

# make sure we remove the element from the dom
Expand All @@ -41,14 +48,41 @@ describe 'Waterfall view controller', ->

it 'should create svg elements', ->
expect(elem.find('svg').length).toBeGreaterThan(1)
expect(elem.find('.builder').length).toBeGreaterThan(1)
expect(elem.find('.build').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(e.select('.svg-tooltip').empty()).toBe(true)
n.__onmouseover({})
expect(e.select('.svg-tooltip').empty()).toBe(false)
# Test mousemove
event = document.createEvent('MouseEvents')
event.initMouseEvent('mousemove', true, true, window,
0, 0, 0, 100, 850, false, false, false, false, 0, null)
expect(e.select('.svg-tooltip').attr('transform')).toContain('NaN')
n.__onmousemove(event)
expect(e.select('.svg-tooltip').attr('transform')).not.toContain('NaN')
# Test mouseout
expect(e.select('.svg-tooltip').empty()).toBe(false)
n.__onmouseout({})
expect(e.select('.svg-tooltip').empty()).toBe(true)

it 'should rerender the waterfall on resize', ->
spyOn(w, 'render')
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')
expect(w.render).not.toHaveBeenCalled()
#w.loadMore()
$rootScope.$digest()
expect(w.render).toHaveBeenCalled()
Expand Up @@ -2,7 +2,6 @@ beforeEach ->
module 'waterfall_view'
# Mock modalService
module ($provide) ->
$provide.service '$modal', ->
$provide.service '$modalInstance', -> close: ->
null

Expand Down
Expand Up @@ -70,7 +70,7 @@ describe 'Scale service', ->
# Later times have greater Y coordinate
expect(idToY(date)).toBeGreaterThan(idToY(date + 10000))
# Out of domain
expect(idToY(1359731102)).toBeUndefined()
expect(idToY(1359731101)).toBeUndefined()
expect(idToY.invert(120)).toBeUndefined()

it 'should return a builderid to name scale', ->
Expand Down
8 changes: 6 additions & 2 deletions www/waterfall_view/test/buildbot/buildbot.service.coffee
Expand Up @@ -46,6 +46,8 @@ builds = [
complete_at: 0
complete: false
]
for build in builds
build.all = -> bind: -> then: ->

buildrequests = [
builderid: 1
Expand All @@ -72,7 +74,9 @@ class Buildbot extends Service('common')
when 'buildrequests' then deferred.resolve buildrequests[0..options.limit-1]
else
deferred.resolve []
bind: ->
bind: (scope) ->
deferred.promise.then (b) ->
scope[string] = b
deferred.promise
getSome: ->
deferred.promise
Expand All @@ -84,7 +88,7 @@ class Buildbot extends Service('common')
when 'buildrequests' then deferred.resolve buildrequests
else
deferred.resolve []
bind: ->
bind: (scope) ->
deferred.promise
getList: ->
deferred.promise
Empty file.
7 changes: 1 addition & 6 deletions www/waterfall_view/test/main.coffee
Expand Up @@ -2,9 +2,4 @@
angular.module('common', []).constant 'config', plugins: waterfall_view: {
limit: 2
}
angular.module('ngAnimate', [])
# Mock modalService
module ($provide) ->
$provide.service '$modal', ->
$provide.service '$modalInstance', ->
null
angular.module('ngAnimate', [])

0 comments on commit 5e1cdd4

Please sign in to comment.