Skip to content

Commit

Permalink
tests for build-item
Browse files Browse the repository at this point in the history
  • Loading branch information
shanzi committed Jun 1, 2015
1 parent 5fe8447 commit a192721
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
Expand Up @@ -15,6 +15,7 @@ class BuildItem extends Directive

class _BuildItem extends Controller
constructor: (buildbotService) ->
# TODO: add links to builders and builds after the corresponding pages has finished
if @outBuilder
@builder = outBuilder
else if @showBuilder
Expand Down
@@ -1,12 +1,63 @@
beforeEach module 'app'

describe 'panel', ->
describe 'builditem', ->

$rootScope = $compile = null
$rootScope = $compile = $httpBackend = buildbotService = null

injected = ($injector) ->
$compile = $injector.get('$compile')
$rootScope = $injector.get('$rootScope')
$httpBackend = $injector.get('$httpBackend')
decorateHttpBackend($httpBackend)
mqService = $injector.get('mqService')
$q = $injector.get('$q')
spyOn(mqService,"setBaseUrl").and.returnValue(null)
spyOn(mqService,"startConsuming").and.returnValue($q.when( -> ))
spyOn(mqService,"stopConsuming").and.returnValue(null)
buildbotService = $injector.get('buildbotService')

beforeEach inject injected

it 'should display a build correctly', ->
$rootScope.showBuilder = true

$httpBackend.expectDataGET('builds/1')
buildbotService.one('builds', 1).bind($rootScope)
$httpBackend.flush()

build = $rootScope.build
build.started_at = (new Date()).getTime() / 1000 - 3600

$httpBackend.expectDataGET('builders/1')
$httpBackend.expectGETSVGIcons()
elem = $compile('<build-item build="build" show-builder="showBuilder">')($rootScope)
$rootScope.$digest()
$httpBackend.flush()

innerRow = elem.children().eq(0)
expect(innerRow.children().length).toBe(4)

builderName = innerRow.children().eq(1).text().trim()
buildNumber = innerRow.children().eq(2).text().trim()
date = innerRow.children().eq(3).text().trim()

expect(builderName).toBe('11')
expect(buildNumber).toBe('#' + $rootScope.build.number)
expect(date).toBe('an hour ago')

it 'should able to hide builder name', ->
$rootScope.showBuilder = false

$httpBackend.expectDataGET('builds/1')
buildbotService.one('builds', 1).bind($rootScope)
$httpBackend.flush()

$httpBackend.expectGETSVGIcons()
elem = $compile('<build-item build="build" show-builder="showBuilder">')($rootScope)
$rootScope.$digest()

innerRow = elem.children().eq(0)
expect(innerRow.children().length).toBe(3)
expect(innerRow.children()[0].tagName.toLowerCase()).toBe('build-status')
expect(innerRow.children().eq(1).hasClass('number')).toBe(true)
expect(innerRow.children().eq(2).hasClass('time')).toBe(true)
@@ -1,6 +1,6 @@
beforeEach module 'app'

describe 'panel', ->
describe 'buildstatus', ->

$rootScope = $compile = $httpBackend = null

Expand Down
@@ -0,0 +1,46 @@
beforeEach module 'app'

describe 'recent builds', ->

$rootScope = $compile = $httpBackend = null

injected = ($injector) ->
$compile = $injector.get('$compile')
$rootScope = $injector.get('$rootScope')
$httpBackend = $injector.get('$httpBackend')
$q = $injector.get('$q')
mqService = $injector.get('mqService')
spyOn(mqService,"setBaseUrl").and.returnValue(null)
spyOn(mqService,"startConsuming").and.returnValue($q.when( -> ))
spyOn(mqService,"stopConsuming").and.returnValue(null)
decorateHttpBackend($httpBackend)

beforeEach inject injected

it 'should display tiles normally', ->
$httpBackend.expectDataGET('masters')
$httpBackend.expectDataGET('buildslaves')
$httpBackend.expectDataGET('builders')
$httpBackend.expectDataGET('schedulers')
elem = $compile('<overview></overview>')($rootScope)
$httpBackend.flush()

mastertile = elem.children().eq(0)
count = mastertile.children().eq(1).text().trim()
expect(count).toBe('1')
extra = mastertile.children().eq(2).text().trim()
expect(extra).toBe('0 active.')

slavetile = elem.children().eq(1)
count = slavetile.children().eq(1).text().trim()
expect(count).toBe('1')
extra = slavetile.children().eq(2).text().trim()
expect(extra).toBe('1 connection.')

builderstile = elem.children().eq(2)
count = builderstile.children().eq(1).text().trim()
expect(count).toBe('1')

schedulerstile = elem.children().eq(3)
count = schedulerstile.children().eq(1).text().trim()
expect(count).toBe('1')

0 comments on commit a192721

Please sign in to comment.