Skip to content

Commit

Permalink
even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Aug 15, 2014
1 parent 5347f12 commit f1f07ed
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 97 deletions.
68 changes: 14 additions & 54 deletions www/waterfall_view/src/module/data/data.service.spec.coffee
@@ -1,62 +1,21 @@
beforeEach ->
module 'waterfall_view'

describe 'Scale service', ->
describe 'Data service', ->

###
# Test data
###
builders = [
builderid: 1
name: 'builder1'
,
builderid: 2
name: 'builder2'
,
builderid: 3
name: 'builder3'
,
builderid: 4
name: 'builder4'
]

builds = [
buildid: 1
builderid: 1
started_at: 1403059709
complete_at: 1403059772
complete: true
results: 'success'
,
buildid: 2
builderid: 2
buildrequestid: 1
started_at: 1403059802
complete_at: 1403060287
complete: true
results: 'success'
,
buildid: 3
builderid: 4
buildrequestid: 2
started_at: 1403059710
complete_at: 1403060278
complete: true
results: 'failure'
,
buildid: 4
builderid: 3
buildrequestid: 2
started_at: 1403060250
complete_at: 0
complete: false
]

dataService = null
dataService = builds = builders = null

injected = ($injector) ->
$rootScope = $injector.get('$rootScope')
dataService = $injector.get('dataService')
buildbotServiceMock = $injector.get('buildbotService')

# Use mocked buildbotService to get the sample data
buildbotServiceMock.all('builds').getList().then (b) ->
builds = b
buildbotServiceMock.all('builders').getList().then (b) ->
builders = b
$rootScope.$digest()

beforeEach(inject(injected))

Expand All @@ -72,12 +31,13 @@ describe 'Scale service', ->
it 'should add builds to builders', ->
# Add builds to builders
dataService.getGroups(builders, builds, 0)
# Builders builds length should be equal to all builds length
buildsInBuilders = 0
for build in builds
buildsInBuilders += builders[build.builderid - 1].builds.length
# A builder should contain its build
expect(builders[build.builderid - 1].builds).toContain(build)
# Builders builds length should be equal to all builds length
buildsInBuilders = 0
for builder in builders
buildsInBuilders += builder.builds.length
expect(buildsInBuilders).toEqual(builds.length)

it 'should create groups', ->
Expand Down
22 changes: 17 additions & 5 deletions www/waterfall_view/src/module/main.module.coffee
Expand Up @@ -30,6 +30,8 @@ class Waterfall extends Controller

# Minimum builder column width (px)
minColumnWidth: cfg.minColumnWidth or 40
# Maximum builder column width (px)
maxColumnWidth: cfg.maxColumnWidth or 80

# Y axis time format (new line: ^)
timeFormat: cfg.timeFormat or '%x^%I:%M'
Expand Down Expand Up @@ -133,12 +135,22 @@ class Waterfall extends Controller
# Set the content width
###
setWidth: ->
if (@$window.innerWidth - @c.margin.right - @c.margin.left) / @builders.length >= @c.minColumnWidth
width = '100%'
if @c.minColumnWidth > 0 and @c.maxColumnWidth > 0 and @c.minColumnWidth <= @c.maxColumnWidth
columnWidth = (@$window.innerWidth - @c.margin.right - @c.margin.left) / @builders.length

narrower = columnWidth <= @c.maxColumnWidth
wider = @c.minColumnWidth <= columnWidth

width =
if narrower and wider then '100%'
else if narrower
"#{@builders.length * @c.minColumnWidth + @c.margin.right + @c.margin.left}px"
else
"#{@builders.length * @c.maxColumnWidth + @c.margin.right + @c.margin.left}px"

else
width = "#{@builders.length * @c.minColumnWidth + @c.margin.right + @c.margin.left}px"
@d3.select('.header-content').style('width', width)
@d3.select('.inner-content').style('width', width)
@$log.error "Bad column width configuration\n\t min: #{@c.minColumnWidth}\n\t max: #{@c.maxColumnWidth}"
width = 40

###
# Get the container height
Expand Down
21 changes: 17 additions & 4 deletions www/waterfall_view/src/module/main.module.spec.coffee
Expand Up @@ -2,7 +2,7 @@ beforeEach ->
module 'waterfall_view'

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

injected = ($injector) ->
$rootScope = $injector.get('$rootScope')
Expand All @@ -11,6 +11,8 @@ describe 'Waterfall view controller', ->
$controller = $injector.get('$controller')
$state = $injector.get('$state')
$document = $injector.get('$document')
$window = $injector.get('$window')
config = $injector.get('config')
elem = angular.element('<div></div>')
$document.find('body').append(elem)
elem.append($compile('<ui-view></ui-view>')(scope))
Expand All @@ -30,11 +32,22 @@ describe 'Waterfall view controller', ->
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).not.toBe(0)
expect(w.builds.length).toBe(limit)
expect(w.builders).toBeDefined()
expect(w.builders.length).not.toBe(0)

it 'should create 2 svg elements and a lot of svg groups', ->
it 'should create svg elements', ->
expect(elem.find('svg').length).toBeGreaterThan(1)
expect(elem.find('g').length).toBeGreaterThan(10)
expect(elem.find('.builder').length).toBeGreaterThan(1)
expect(elem.find('.build').length).toBeGreaterThan(1)

it 'should trigger mouse events on builds', ->


it 'should rerender the waterfall on resize', ->
spyOn(w, 'render')
expect(w.render).not.toHaveBeenCalled()
angular.element($window).triggerHandler('resize')
expect(w.render).toHaveBeenCalled()
46 changes: 46 additions & 0 deletions www/waterfall_view/src/module/modal/modal.controller.spec.coffee
@@ -0,0 +1,46 @@
beforeEach ->
module 'waterfall_view'
# Mock modalService
module ($provide) ->
$provide.service '$modal', ->
$provide.service '$modalInstance', -> close: ->
null

describe 'Waterfall modal controller', ->
createController = $rootScope = $modalInstance = scope = null

injected = ($injector) ->
$controller = $injector.get('$controller')
$rootScope = $injector.get('$rootScope')
$modalInstance = $injector.get('$modalInstance')
scope = $rootScope.$new()

createController = ->
$controller 'waterfallModalController as m',
$scope: scope
selectedBuild: {}

beforeEach(inject(injected))

it 'should be defined', ->
createController()
m = scope.m
expect(m).toBeDefined()
# close function should be to defined
expect(m.close).toBeDefined()
expect(typeof m.close).toBe('function')

it 'should call close() on stateChangeStart event', ->
createController()
m = scope.m
spyOn(m, 'close')
$rootScope.$broadcast('$stateChangeStart')
expect(m.close).toHaveBeenCalled()

it 'should call $modalInstance.close on close()', ->
createController()
m = scope.m
spyOn($modalInstance, 'close')
expect($modalInstance.close).not.toHaveBeenCalled()
m.close()
expect($modalInstance.close).toHaveBeenCalled()
2 changes: 1 addition & 1 deletion www/waterfall_view/src/module/scale/scale.service.coffee
Expand Up @@ -40,7 +40,7 @@ class ScaleService extends Factory
if group.min <= date <= group.max
return date
periods.push(group.max - group.min)
return 0
return undefined

# Returns an id to name scale
getBuilderName: (builders) ->
Expand Down
28 changes: 9 additions & 19 deletions www/waterfall_view/src/module/scale/scale.service.spec.coffee
Expand Up @@ -3,23 +3,6 @@ beforeEach ->

describe 'Scale service', ->

###
# Test data
###
builders = [
builderid: 1
name: 'builder1'
,
builderid: 2
name: 'builder2'
,
builderid: 3
name: 'builder3'
,
builderid: 4
name: 'builder4'
]

groups = [
# Y.M.D - h:m:s
min: 1325376000 # 2012.01.01 - 0:0:0
Expand All @@ -29,15 +12,21 @@ describe 'Scale service', ->
max: 1396450952 # 2014.04.02 - 15:2:32
]

scaleService = scale = null
scaleService = scale = builders = null

injected = ($injector) ->
$rootScope = $injector.get('$rootScope')
#d3Service = $injector.get('d3Service')
scaleService = $injector.get('scaleService')
buildbotServiceMock = $injector.get('buildbotService')

scale = new scaleService(window.d3)

# Use mocked buildbotService to get the sample data
buildbotServiceMock.all('builders').getList().then (b) ->
builders = b
$rootScope.$digest()


beforeEach(inject(injected))

it 'should be defined', ->
Expand Down Expand Up @@ -82,6 +71,7 @@ describe 'Scale service', ->
expect(idToY(date)).toBeGreaterThan(idToY(date + 10000))
# Out of domain
expect(idToY(1359731102)).toBeUndefined()
expect(idToY.invert(120)).toBeUndefined()

it 'should return a builderid to name scale', ->
# Get new scale
Expand Down
6 changes: 0 additions & 6 deletions www/waterfall_view/src/module/waterfall.route.spec.coffee
@@ -1,10 +1,4 @@
beforeEach ->
# Mock modalService
module ($provide) ->
$provide.service '$modal', ->
$provide.service '$modalInstance', ->
null

module 'waterfall_view'

describe 'Waterfall view', ->
Expand Down
25 changes: 17 additions & 8 deletions www/waterfall_view/test/buildbot/buildbot.service.coffee
@@ -1,14 +1,18 @@
###
# Test data
###
# Test data
###
builders = [
builderid: 1
name: 'builder1'
,
builderid: 2
name: 'builder2'
,
builderid: 3
name: 'builder3'
,
builderid: 4
name: 'builder4'
]

builds = [
Expand All @@ -17,25 +21,28 @@ builds = [
started_at: 1403059709
complete_at: 1403059772
complete: true
results: 'success'
,
buildid: 2
builderid: 2
buildrequestid: 1
started_at: 1403059711
started_at: 1403059802
complete_at: 1403060287
complete: true
results: 'success'
,
buildid: 3
builderid: 4
builderid: 2
buildrequestid: 2
started_at: 1403059710
complete_at: 1403060278
complete: true
results: 'failure'
,
buildid: 4
builderid: 3
buildrequestid: 2
started_at: 1403059710
started_at: 1403060250
complete_at: 0
complete: false
]
Expand All @@ -60,13 +67,15 @@ class Buildbot extends Service('common')
@some = (string, options) ->
deferred = $q.defer()
switch string
when 'builds' then deferred.resolve builds[0..options.limit]
when 'builders' then deferred.resolve builders[0..options.limit]
when 'buildrequests' then deferred.resolve buildrequests[0..options.limit]
when 'builds' then deferred.resolve builds[0..options.limit-1]
when 'builders' then deferred.resolve builders[0..options.limit-1]
when 'buildrequests' then deferred.resolve buildrequests[0..options.limit-1]
else
deferred.resolve []
bind: ->
deferred.promise
getSome: ->
deferred.promise
@all = (string) =>
deferred = $q.defer()
switch string
Expand Down

0 comments on commit f1f07ed

Please sign in to comment.