Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shanzi committed Jun 2, 2015
1 parent 4b5399e commit df660b2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
Expand Up @@ -35,11 +35,11 @@ describe 'builditem', ->
$httpBackend.flush()

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

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

expect(builderName).toBe('11')
expect(buildNumber).toBe('#' + $rootScope.build.number)
Expand All @@ -57,7 +57,7 @@ describe 'builditem', ->
$rootScope.$digest()

innerRow = elem.children().eq(0)
expect(innerRow.children().length).toBe(3)
expect(innerRow.children().length).toBe(4)
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)
expect(innerRow.children().eq(3).hasClass('time')).toBe(true)
Expand Up @@ -19,21 +19,22 @@ class _BuildStatus extends Controller

updateBuild = =>
build = @build
@status_text = RESULTS_TEXT[build.results]
@status_text ?= 'UNKNOWN'

if build.complete is false and build.started_at > 0
@status_class = 'pending'
@status_text = 'PENDING'
@icon = 'build-pending'
else if build.results == 0
@status_class = 'success'
@icon = 'build-success'
else if build.results == 2 or build.results == 4
else if build.results >= 1 and build.results <= 6
@status_class = 'fail'
@icon = 'build-fail'
else
@status_class = 'unknown'
@icon = 'build-pending'

@status_text = RESULTS_TEXT[build.results]
@status_text ?= 'UNKNOWN'

$scope.$watch 'status.build', updateBuild, true

Expand Up @@ -2,12 +2,13 @@ beforeEach module 'app'

describe 'buildstatus', ->

$rootScope = $compile = $httpBackend = null
$rootScope = $compile = $httpBackend = RESULTS_TEXT = null

injected = ($injector) ->
$compile = $injector.get('$compile')
$rootScope = $injector.get('$rootScope')
$httpBackend = $injector.get('$httpBackend')
RESULTS_TEXT = $injector.get('RESULTS_TEXT')
decorateHttpBackend($httpBackend)

beforeEach inject injected
Expand Down Expand Up @@ -56,3 +57,48 @@ describe 'buildstatus', ->
expect(icon.hasClass('pending')).toBe(false)
expect(icon.hasClass('success')).toBe(false)
expect(icon.hasClass('fail')).toBe(true)

it 'should show build status(text mode) correctly', ->
$rootScope.build =
complete: false
started_at: 0
results: -1
elem = $compile('<build-status build="build" type="text">')($rootScope)
$rootScope.$digest()
span = elem.children().eq(0)

# unknown status
expect(span.hasClass('unknown')).toBe(true)
expect(span.hasClass('pending')).toBe(false)
expect(span.hasClass('success')).toBe(false)
expect(span.hasClass('fail')).toBe(false)
expect(span.text().trim()).toBe('UNKNOWN')

# pending status
$rootScope.build.started_at = (new Date()).valueOf()
$rootScope.$digest()
expect(span.hasClass('unknown')).toBe(false)
expect(span.hasClass('pending')).toBe(true)
expect(span.hasClass('success')).toBe(false)
expect(span.hasClass('fail')).toBe(false)
expect(span.text().trim()).toBe('PENDING')

# success status
$rootScope.build.complete = true
$rootScope.build.results = 0
$rootScope.$digest()
expect(span.hasClass('unknown')).toBe(false)
expect(span.hasClass('pending')).toBe(false)
expect(span.hasClass('success')).toBe(true)
expect(span.hasClass('fail')).toBe(false)
expect(span.text().trim()).toBe('SUCCESS')

# fail status
for i in [1..6]
$rootScope.build.results = i
$rootScope.$digest()
expect(span.hasClass('unknown')).toBe(false)
expect(span.hasClass('pending')).toBe(false)
expect(span.hasClass('success')).toBe(false)
expect(span.hasClass('fail')).toBe(true)
expect(span.text().trim()).toBe(RESULTS_TEXT[i])

0 comments on commit df660b2

Please sign in to comment.