Rewrite specs from jasmine to qunit
This commit is contained in:
parent
5fea9d1d7b
commit
359c97cad0
|
@ -1,189 +0,0 @@
|
||||||
describe 'events', ->
|
|
||||||
describe 'an event adding a repository', ->
|
|
||||||
beforeEach ->
|
|
||||||
app 'travis-ci/travis-core'
|
|
||||||
waitFor jobsRendered
|
|
||||||
|
|
||||||
it 'adds a repository to the list', ->
|
|
||||||
waitFor reposRendered
|
|
||||||
|
|
||||||
runs ->
|
|
||||||
payload =
|
|
||||||
repository:
|
|
||||||
id: 10
|
|
||||||
build:
|
|
||||||
id: 10
|
|
||||||
repository_id: 10
|
|
||||||
|
|
||||||
$.mockjax
|
|
||||||
url: '/builds/10'
|
|
||||||
responseTime: 0
|
|
||||||
responseText: payload
|
|
||||||
|
|
||||||
Em.run ->
|
|
||||||
Travis.receive 'build:started',
|
|
||||||
build:
|
|
||||||
id: 10
|
|
||||||
repository:
|
|
||||||
id: 10
|
|
||||||
slug: 'travis-ci/travis-support'
|
|
||||||
last_build_id: 10
|
|
||||||
last_build_number: 10
|
|
||||||
last_build_started_at: '2012-07-02T00:01:00Z'
|
|
||||||
last_build_finished_at: '2012-07-02T00:02:30Z'
|
|
||||||
|
|
||||||
waits(100)
|
|
||||||
runs ->
|
|
||||||
listsRepo
|
|
||||||
row: 2
|
|
||||||
item: { slug: 'travis-ci/travis-support', build: { number: 4, url: '/travis-ci/travis-support/builds/10', duration: '1 min 30 sec', finishedAt: 'less than a minute ago' } }
|
|
||||||
|
|
||||||
describe 'an event adding a build', ->
|
|
||||||
beforeEach ->
|
|
||||||
app 'travis-ci/travis-core/builds'
|
|
||||||
waitFor buildsRendered
|
|
||||||
|
|
||||||
it 'adds a build to the builds list', ->
|
|
||||||
payload =
|
|
||||||
build:
|
|
||||||
id: 11
|
|
||||||
repository_id: 1
|
|
||||||
commit_id: 1
|
|
||||||
number: '3'
|
|
||||||
duration: 55
|
|
||||||
started_at: '2012-07-02T00:02:00Z'
|
|
||||||
finished_at: '2012-07-02T00:02:55Z'
|
|
||||||
event_type: 'push'
|
|
||||||
message: 'commit message 3'
|
|
||||||
commit: '1234567'
|
|
||||||
state: 'failed'
|
|
||||||
|
|
||||||
Em.run ->
|
|
||||||
Travis.receive 'build:started', payload
|
|
||||||
|
|
||||||
waits(100)
|
|
||||||
runs ->
|
|
||||||
listsBuild
|
|
||||||
row: 1
|
|
||||||
item: { id: 11, slug: 'travis-ci/travis-core', number: '3', sha: '1234567', branch: 'master', message: 'commit message 3', finishedAt: 'less than a minute ago', duration: '55 sec', color: 'red' }
|
|
||||||
|
|
||||||
describe 'an event adding a job', ->
|
|
||||||
beforeEach ->
|
|
||||||
app 'travis-ci/travis-core'
|
|
||||||
waitFor jobsRendered, 'jobs should be rendered'
|
|
||||||
#runs ->
|
|
||||||
# waitFor queuesRendered, 'queues should be rendered'
|
|
||||||
|
|
||||||
#it 'adds a job to the jobs queue', ->
|
|
||||||
# payload =
|
|
||||||
# job:
|
|
||||||
# id: 12
|
|
||||||
# repository_id: 1
|
|
||||||
# number: '1.4'
|
|
||||||
# queue: 'builds.linux'
|
|
||||||
|
|
||||||
# $.mockjax
|
|
||||||
# url: '/jobs/12'
|
|
||||||
# responseTime: 0
|
|
||||||
# responseText: payload
|
|
||||||
|
|
||||||
# Em.run ->
|
|
||||||
# Travis.receive 'job:started',
|
|
||||||
# job:
|
|
||||||
# id: 12
|
|
||||||
# repository_id: 1
|
|
||||||
# repository_slug: 'travis-ci/travis-core'
|
|
||||||
# number: '1.4'
|
|
||||||
# queue: 'builds.linux'
|
|
||||||
# state: 'created'
|
|
||||||
|
|
||||||
# waits(1000)
|
|
||||||
# runs ->
|
|
||||||
# listsQueuedJob
|
|
||||||
# name: 'linux'
|
|
||||||
# row: 3
|
|
||||||
# item: { number: '1.4', repo: 'travis-ci/travis-core' }
|
|
||||||
|
|
||||||
it 'updates only keys that are available', ->
|
|
||||||
Em.run ->
|
|
||||||
Travis.receive 'job:started',
|
|
||||||
job:
|
|
||||||
id: 1
|
|
||||||
build_id: 1
|
|
||||||
|
|
||||||
waits(100)
|
|
||||||
runs ->
|
|
||||||
listsJob
|
|
||||||
table: $('#jobs')
|
|
||||||
row: 1
|
|
||||||
item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' }
|
|
||||||
|
|
||||||
#describe 'an event adding a worker', ->
|
|
||||||
# beforeEach ->
|
|
||||||
# app ''
|
|
||||||
# waitFor sidebarTabsRendered
|
|
||||||
# runs ->
|
|
||||||
# $('#right #tab_workers a').trigger('click')
|
|
||||||
# waitFor workersRendered
|
|
||||||
|
|
||||||
# it 'adds a worker to the workers list', ->
|
|
||||||
# payload =
|
|
||||||
# worker:
|
|
||||||
# id: 10
|
|
||||||
# host: 'worker.travis-ci.org'
|
|
||||||
# name: 'ruby-3'
|
|
||||||
# state: 'ready'
|
|
||||||
|
|
||||||
# $.mockjax
|
|
||||||
# url: '/workers/10'
|
|
||||||
# responseTime: 0
|
|
||||||
# responseText: payload
|
|
||||||
|
|
||||||
# Em.run ->
|
|
||||||
# Travis.receive 'worker:created',
|
|
||||||
# worker:
|
|
||||||
# id: 10
|
|
||||||
# name: 'ruby-3'
|
|
||||||
# host: 'worker.travis-ci.org'
|
|
||||||
# state: 'ready'
|
|
||||||
|
|
||||||
# waits(100)
|
|
||||||
# runs ->
|
|
||||||
# listsWorker
|
|
||||||
# group: 'worker.travis-ci.org'
|
|
||||||
# row: 3
|
|
||||||
# item: { name: 'ruby-3', state: 'ready' }
|
|
||||||
|
|
||||||
|
|
||||||
#describe 'an event updating a worker', ->
|
|
||||||
# beforeEach ->
|
|
||||||
# app '/travis-ci/travis-core'
|
|
||||||
# waitFor sidebarTabsRendered
|
|
||||||
# runs ->
|
|
||||||
# $('#right #tab_workers a').trigger('click')
|
|
||||||
# waitFor workersRendered
|
|
||||||
|
|
||||||
# it 'does not update repository if it\'s already in the store', ->
|
|
||||||
# payload =
|
|
||||||
# worker:
|
|
||||||
# id: 1
|
|
||||||
# host: 'worker.travis-ci.org'
|
|
||||||
# name: 'ruby-2'
|
|
||||||
# state: 'working'
|
|
||||||
# payload:
|
|
||||||
# repository:
|
|
||||||
# id: 1
|
|
||||||
# last_build_id: 999
|
|
||||||
# last_build_number: '999'
|
|
||||||
|
|
||||||
# Em.run ->
|
|
||||||
# Travis.receive 'worker:updated', payload
|
|
||||||
|
|
||||||
# waits(100)
|
|
||||||
# runs ->
|
|
||||||
# listsRepo
|
|
||||||
# row: 2
|
|
||||||
# item: { slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
describe 'on the "build" state', ->
|
module "Build page",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
app '/travis-ci/travis-core/builds/1'
|
Ember.run -> Travis.advanceReadiness()
|
||||||
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
waitFor reposRendered
|
test "displaying information on build page", ->
|
||||||
runs ->
|
visit('/travis-ci/travis-core/builds/1').then ->
|
||||||
waitFor buildRendered
|
|
||||||
|
|
||||||
it 'displays the expected stuff', ->
|
|
||||||
listsRepos [
|
listsRepos [
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
@ -48,14 +47,8 @@ describe 'on the "build" state', ->
|
||||||
{ color: '', id: 3, number: '1.3', repo: 'travis-ci/travis-core', finishedAt: '-', duration: '-', rvm: 'jruby' }
|
{ color: '', id: 3, number: '1.3', repo: 'travis-ci/travis-core', finishedAt: '-', duration: '-', rvm: 'jruby' }
|
||||||
]
|
]
|
||||||
|
|
||||||
describe 'on the "current" state', ->
|
test "updating current build", ->
|
||||||
beforeEach ->
|
visit('/travis-ci/travis-core').then ->
|
||||||
app '/travis-ci/travis-core'
|
|
||||||
waitFor reposRendered
|
|
||||||
runs ->
|
|
||||||
waitFor buildRendered
|
|
||||||
|
|
||||||
it 'correctly updates values on pusher build:started event', ->
|
|
||||||
payload =
|
payload =
|
||||||
build:
|
build:
|
||||||
id: 11
|
id: 11
|
||||||
|
@ -69,7 +62,11 @@ describe 'on the "current" state', ->
|
||||||
result: 1
|
result: 1
|
||||||
message: 'commit message 3'
|
message: 'commit message 3'
|
||||||
commit: 'foo1234'
|
commit: 'foo1234'
|
||||||
|
branch: 'master'
|
||||||
state: 'started'
|
state: 'started'
|
||||||
|
config: {}
|
||||||
|
pull_request: false
|
||||||
|
compare_url: 'http://github.com/compare/0123456..1234567'
|
||||||
repository:
|
repository:
|
||||||
id: 1
|
id: 1
|
||||||
last_build_number: '3'
|
last_build_number: '3'
|
||||||
|
@ -78,8 +75,7 @@ describe 'on the "current" state', ->
|
||||||
Em.run ->
|
Em.run ->
|
||||||
Travis.receive 'build:started', payload
|
Travis.receive 'build:started', payload
|
||||||
|
|
||||||
waits 10
|
wait().then ->
|
||||||
runs ->
|
|
||||||
displaysSummaryBuildLink '/travis-ci/travis-core/builds/11', '3'
|
displaysSummaryBuildLink '/travis-ci/travis-core/builds/11', '3'
|
||||||
|
|
||||||
displaysSummary
|
displaysSummary
|
||||||
|
@ -92,4 +88,3 @@ describe 'on the "current" state', ->
|
||||||
finishedAt: 'less than a minute ago'
|
finishedAt: 'less than a minute ago'
|
||||||
duration: '55 sec'
|
duration: '55 sec'
|
||||||
message: 'commit message 3'
|
message: 'commit message 3'
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
describe 'on the "builds" state', ->
|
module "Builds page",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
app '/travis-ci/travis-core/builds'
|
Ember.run -> Travis.advanceReadiness()
|
||||||
waitFor buildsRendered
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
it 'displays the expected stuff', ->
|
test "displaying information on builds page", ->
|
||||||
|
visit('/travis-ci/travis-core/builds').then ->
|
||||||
listsRepos [
|
listsRepos [
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
@ -1,9 +1,11 @@
|
||||||
describe 'on the "current" state', ->
|
module "Repo page",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
app 'travis-ci/travis-core'
|
Ember.run -> Travis.advanceReadiness()
|
||||||
waitFor buildRendered
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
it 'displays the expected stuff', ->
|
test "displaying information on repo page", ->
|
||||||
|
visit('travis-ci/travis-core').then ->
|
||||||
listsRepos [
|
listsRepos [
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
174
assets/scripts/spec/integration/event_spec.coffee
Normal file
174
assets/scripts/spec/integration/event_spec.coffee
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
module "Events",
|
||||||
|
setup: ->
|
||||||
|
Ember.run -> Travis.advanceReadiness()
|
||||||
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
|
test "event containing a repository, adds repository to repos list", ->
|
||||||
|
visit('travis-ci/travis-core').then ->
|
||||||
|
payload =
|
||||||
|
repository:
|
||||||
|
id: 10
|
||||||
|
build:
|
||||||
|
id: 10
|
||||||
|
repository_id: 10
|
||||||
|
|
||||||
|
$.mockjax
|
||||||
|
url: '/builds/10'
|
||||||
|
responseTime: 0
|
||||||
|
responseText: payload
|
||||||
|
|
||||||
|
Em.run ->
|
||||||
|
Travis.receive 'build:started',
|
||||||
|
build:
|
||||||
|
id: 10
|
||||||
|
repository:
|
||||||
|
id: 10
|
||||||
|
slug: 'travis-ci/travis-support'
|
||||||
|
last_build_id: 10
|
||||||
|
last_build_number: 10
|
||||||
|
last_build_started_at: '2012-07-02T00:01:00Z'
|
||||||
|
last_build_finished_at: '2012-07-02T00:02:30Z'
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
listsRepo
|
||||||
|
row: 2
|
||||||
|
item: { slug: 'travis-ci/travis-support', build: { number: 4, url: '/travis-ci/travis-support/builds/10', duration: '1 min 30 sec', finishedAt: 'less than a minute ago' } }
|
||||||
|
|
||||||
|
test "an event with a build adds a build to a builds list", ->
|
||||||
|
visit('travis-ci/travis-core/builds').then ->
|
||||||
|
payload =
|
||||||
|
build:
|
||||||
|
id: 11
|
||||||
|
repository_id: 1
|
||||||
|
commit_id: 1
|
||||||
|
number: '3'
|
||||||
|
duration: 55
|
||||||
|
started_at: '2012-07-02T00:02:00Z'
|
||||||
|
finished_at: '2012-07-02T00:02:55Z'
|
||||||
|
event_type: 'push'
|
||||||
|
message: 'commit message 3'
|
||||||
|
commit: '1234567'
|
||||||
|
state: 'failed'
|
||||||
|
|
||||||
|
Em.run ->
|
||||||
|
Travis.receive 'build:started', payload
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
listsBuild
|
||||||
|
row: 1
|
||||||
|
item: { id: 11, slug: 'travis-ci/travis-core', number: '3', sha: '1234567', branch: 'master', message: 'commit message 3', finishedAt: 'less than a minute ago', duration: '55 sec', color: 'red' }
|
||||||
|
|
||||||
|
#test "event containing a job, adds job to jobs list", ->
|
||||||
|
# visit('travis-ci/travis-core').then ->
|
||||||
|
# payload =
|
||||||
|
# job:
|
||||||
|
# id: 12
|
||||||
|
# repository_id: 1
|
||||||
|
# number: '1.4'
|
||||||
|
# queue: 'builds.linux'
|
||||||
|
#
|
||||||
|
# $.mockjax
|
||||||
|
# url: '/jobs/12'
|
||||||
|
# responseTime: 0
|
||||||
|
# responseText: payload
|
||||||
|
#
|
||||||
|
# Em.run ->
|
||||||
|
# Travis.receive 'job:started',
|
||||||
|
# job:
|
||||||
|
# id: 12
|
||||||
|
# repository_id: 1
|
||||||
|
# repository_slug: 'travis-ci/travis-core'
|
||||||
|
# number: '1.4'
|
||||||
|
# queue: 'builds.linux'
|
||||||
|
# state: 'created'
|
||||||
|
#
|
||||||
|
# wait().then ->
|
||||||
|
# listsQueuedJob
|
||||||
|
# name: 'linux'
|
||||||
|
# row: 3
|
||||||
|
# item: { number: '1.4', repo: 'travis-ci/travis-core' }
|
||||||
|
#
|
||||||
|
# it 'updates only keys that are available', ->
|
||||||
|
# Em.run ->
|
||||||
|
# Travis.receive 'job:started',
|
||||||
|
# job:
|
||||||
|
# id: 1
|
||||||
|
# build_id: 1
|
||||||
|
#
|
||||||
|
# waits(100)
|
||||||
|
# runs ->
|
||||||
|
# listsJob
|
||||||
|
# table: $('#jobs')
|
||||||
|
# row: 1
|
||||||
|
# item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' }
|
||||||
|
#
|
||||||
|
# #describe 'an event adding a worker', ->
|
||||||
|
# # beforeEach ->
|
||||||
|
# # app ''
|
||||||
|
# # waitFor sidebarTabsRendered
|
||||||
|
# # runs ->
|
||||||
|
# # $('#right #tab_workers a').trigger('click')
|
||||||
|
# # waitFor workersRendered
|
||||||
|
#
|
||||||
|
# # it 'adds a worker to the workers list', ->
|
||||||
|
# # payload =
|
||||||
|
# # worker:
|
||||||
|
# # id: 10
|
||||||
|
# # host: 'worker.travis-ci.org'
|
||||||
|
# # name: 'ruby-3'
|
||||||
|
# # state: 'ready'
|
||||||
|
#
|
||||||
|
# # $.mockjax
|
||||||
|
# # url: '/workers/10'
|
||||||
|
# # responseTime: 0
|
||||||
|
# # responseText: payload
|
||||||
|
#
|
||||||
|
# # Em.run ->
|
||||||
|
# # Travis.receive 'worker:created',
|
||||||
|
# # worker:
|
||||||
|
# # id: 10
|
||||||
|
# # name: 'ruby-3'
|
||||||
|
# # host: 'worker.travis-ci.org'
|
||||||
|
# # state: 'ready'
|
||||||
|
#
|
||||||
|
# # waits(100)
|
||||||
|
# # runs ->
|
||||||
|
# # listsWorker
|
||||||
|
# # group: 'worker.travis-ci.org'
|
||||||
|
# # row: 3
|
||||||
|
# # item: { name: 'ruby-3', state: 'ready' }
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# #describe 'an event updating a worker', ->
|
||||||
|
# # beforeEach ->
|
||||||
|
# # app '/travis-ci/travis-core'
|
||||||
|
# # waitFor sidebarTabsRendered
|
||||||
|
# # runs ->
|
||||||
|
# # $('#right #tab_workers a').trigger('click')
|
||||||
|
# # waitFor workersRendered
|
||||||
|
#
|
||||||
|
# # it 'does not update repository if it\'s already in the store', ->
|
||||||
|
# # payload =
|
||||||
|
# # worker:
|
||||||
|
# # id: 1
|
||||||
|
# # host: 'worker.travis-ci.org'
|
||||||
|
# # name: 'ruby-2'
|
||||||
|
# # state: 'working'
|
||||||
|
# # payload:
|
||||||
|
# # repository:
|
||||||
|
# # id: 1
|
||||||
|
# # last_build_id: 999
|
||||||
|
# # last_build_number: '999'
|
||||||
|
#
|
||||||
|
# # Em.run ->
|
||||||
|
# # Travis.receive 'worker:updated', payload
|
||||||
|
#
|
||||||
|
# # waits(100)
|
||||||
|
# # runs ->
|
||||||
|
# # listsRepo
|
||||||
|
# # row: 2
|
||||||
|
# # item: { slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
|
@ -1,9 +1,11 @@
|
||||||
describe 'on the "index" state', ->
|
module "Index page",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
app 'travis-ci/travis-core'
|
Ember.run -> Travis.advanceReadiness()
|
||||||
waitFor buildRendered
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
it 'displays the expected stuff', ->
|
test "displaying information on index page", ->
|
||||||
|
visit('travis-ci/travis-core').then ->
|
||||||
listsRepos [
|
listsRepos [
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
81
assets/scripts/spec/integration/job_spec.coffee
Normal file
81
assets/scripts/spec/integration/job_spec.coffee
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
module "Job page",
|
||||||
|
setup: ->
|
||||||
|
Ember.run -> Travis.advanceReadiness()
|
||||||
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
|
|
||||||
|
test 'displaying information on job page', ->
|
||||||
|
$.mockjax
|
||||||
|
url: '/jobs/1/log?cors_hax=true'
|
||||||
|
responseTime: 0
|
||||||
|
responseText: "First line\ncontent:travis_fold:start:install\r$ Install something\nInstalling something\ncontent:travis_fold:end:install\r$ End"
|
||||||
|
|
||||||
|
visit('travis-ci/travis-core/jobs/1').then ->
|
||||||
|
listsRepos [
|
||||||
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
{ slug: 'travis-ci/travis-assets', build: { number: 3, url: '/travis-ci/travis-assets/builds/3', duration: '30 sec', finishedAt: 'a day ago' } }
|
||||||
|
]
|
||||||
|
|
||||||
|
displaysRepository
|
||||||
|
href: '/travis-ci/travis-core'
|
||||||
|
|
||||||
|
displaysSummary
|
||||||
|
id: 1
|
||||||
|
type: 'job'
|
||||||
|
repo: 'travis-ci/travis-core'
|
||||||
|
commit: '1234567'
|
||||||
|
branch: 'master'
|
||||||
|
compare: '0123456..1234567'
|
||||||
|
finishedAt: '3 minutes ago'
|
||||||
|
duration: '30 sec'
|
||||||
|
message: 'commit message 1'
|
||||||
|
|
||||||
|
displaysTabs
|
||||||
|
current: { href: '/travis-ci/travis-core' }
|
||||||
|
builds: { href: '/travis-ci/travis-core/builds' }
|
||||||
|
build: { href: '/travis-ci/travis-core/builds/1' }
|
||||||
|
job: { href: '/travis-ci/travis-core/jobs/1', active: true }
|
||||||
|
|
||||||
|
displaysLog [
|
||||||
|
'First line',
|
||||||
|
'$ Install something',
|
||||||
|
'Installing something',
|
||||||
|
'$ End'
|
||||||
|
]
|
||||||
|
|
||||||
|
# it 'allows to expand folds', ->
|
||||||
|
# waits 100
|
||||||
|
# runs ->
|
||||||
|
# expect($('#fold-start-install').hasClass('open')).toBeFalsy()
|
||||||
|
# $('#fold-start-install').click()
|
||||||
|
# waits 20
|
||||||
|
# runs ->
|
||||||
|
# expect($('#fold-start-install').hasClass('open')).toBeTruthy()
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#describe 'too long log', ->
|
||||||
|
# beforeEach ->
|
||||||
|
# $.mockjax
|
||||||
|
# url: '/jobs/2/log?cors_hax=true'
|
||||||
|
# responseTime: 0
|
||||||
|
# responseText: '1\n2\n3\n4\n5\n6\n7\n8\n9\n10'
|
||||||
|
#
|
||||||
|
# Log.LIMIT = 5
|
||||||
|
#
|
||||||
|
# app 'travis-ci/travis-core/jobs/2'
|
||||||
|
# waitFor logRendered
|
||||||
|
#
|
||||||
|
# afterEach ->
|
||||||
|
# Log.LIMIT = 10000
|
||||||
|
#
|
||||||
|
# it 'is cut after given limit', ->
|
||||||
|
# displaysLog [
|
||||||
|
# '12345'
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# expect( $('#log-container .warning').text() ).toMatch /This log is too long to be displayed/
|
||||||
|
# expect( $('#log-container .warning a').attr('href') ).toEqual '/jobs/2/log.txt?deansi=true'
|
||||||
|
#
|
||||||
|
#
|
45
assets/scripts/spec/integration/my_repos_spec.coffee
Normal file
45
assets/scripts/spec/integration/my_repos_spec.coffee
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
module "My repos",
|
||||||
|
setup: ->
|
||||||
|
Ember.run -> Travis.advanceReadiness()
|
||||||
|
teardown: ->
|
||||||
|
Ember.run -> Travis.reset()
|
||||||
|
|
||||||
|
test "my repos is active by default when user is signed in", ->
|
||||||
|
|
||||||
|
Ember.run -> signInUser()
|
||||||
|
visit('/').then ->
|
||||||
|
wait().then ->
|
||||||
|
listsRepos [
|
||||||
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
]
|
||||||
|
|
||||||
|
displaysRepository
|
||||||
|
href: '/travis-ci/travis-hub'
|
||||||
|
|
||||||
|
displaysSummary
|
||||||
|
type: 'build'
|
||||||
|
id: 4
|
||||||
|
repo: 'travis-ci/travis-hub'
|
||||||
|
commit: '4567890'
|
||||||
|
branch: 'master'
|
||||||
|
compare: '0123456..4567890'
|
||||||
|
finishedAt: '-'
|
||||||
|
duration: '1 min'
|
||||||
|
message: 'commit message 4'
|
||||||
|
|
||||||
|
test "my repos is activated when user signs in", ->
|
||||||
|
visit('/').then ->
|
||||||
|
listsRepos [
|
||||||
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
{ slug: 'travis-ci/travis-assets', build: { number: 3, url: '/travis-ci/travis-assets/builds/3', duration: '30 sec', finishedAt: 'a day ago' } }
|
||||||
|
]
|
||||||
|
|
||||||
|
Ember.run -> signInUser()
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
listsRepos [
|
||||||
|
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
||||||
|
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
||||||
|
]
|
9
assets/scripts/spec/integration/routes_spec.coffee
Normal file
9
assets/scripts/spec/integration/routes_spec.coffee
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#module "Router",
|
||||||
|
# setup: ->
|
||||||
|
# Ember.run -> Travis.advanceReadiness()
|
||||||
|
# teardown: ->
|
||||||
|
# Ember.run -> Travis.reset()
|
||||||
|
#
|
||||||
|
#test 'renders notFound template when URL can\t be found', ->
|
||||||
|
# visit('/somehing/something/something/.../dark/side/..../something/something/something/.../complete').then ->
|
||||||
|
# equal('The requested page was not found.', $('#main').text().trim())
|
|
@ -1,83 +0,0 @@
|
||||||
describe 'on the "job" state', ->
|
|
||||||
beforeEach ->
|
|
||||||
$.mockjax
|
|
||||||
url: '/jobs/1/log?cors_hax=true'
|
|
||||||
responseTime: 0
|
|
||||||
responseText: "First line\ncontent:travis_fold:start:install\r$ Install something\nInstalling something\ncontent:travis_fold:end:install\r$ End"
|
|
||||||
|
|
||||||
|
|
||||||
app 'travis-ci/travis-core/jobs/1'
|
|
||||||
waitFor jobRendered
|
|
||||||
runs ->
|
|
||||||
waitFor hasText('#tab_build', 'Build #1')
|
|
||||||
|
|
||||||
it 'displays the expected stuff', ->
|
|
||||||
listsRepos [
|
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
||||||
{ slug: 'travis-ci/travis-assets', build: { number: 3, url: '/travis-ci/travis-assets/builds/3', duration: '30 sec', finishedAt: 'a day ago' } }
|
|
||||||
]
|
|
||||||
|
|
||||||
waits 100
|
|
||||||
runs ->
|
|
||||||
displaysRepository
|
|
||||||
href: '/travis-ci/travis-core'
|
|
||||||
|
|
||||||
displaysSummary
|
|
||||||
id: 1
|
|
||||||
type: 'job'
|
|
||||||
repo: 'travis-ci/travis-core'
|
|
||||||
commit: '1234567'
|
|
||||||
branch: 'master'
|
|
||||||
compare: '0123456..1234567'
|
|
||||||
finishedAt: '3 minutes ago'
|
|
||||||
duration: '30 sec'
|
|
||||||
message: 'commit message 1'
|
|
||||||
|
|
||||||
displaysTabs
|
|
||||||
current: { href: '/travis-ci/travis-core' }
|
|
||||||
builds: { href: '/travis-ci/travis-core/builds' }
|
|
||||||
build: { href: '/travis-ci/travis-core/builds/1' }
|
|
||||||
job: { href: '/travis-ci/travis-core/jobs/1', active: true }
|
|
||||||
|
|
||||||
displaysLog [
|
|
||||||
'First line',
|
|
||||||
'$ Install something',
|
|
||||||
'Installing something',
|
|
||||||
'$ End'
|
|
||||||
]
|
|
||||||
|
|
||||||
it 'allows to expand folds', ->
|
|
||||||
waits 100
|
|
||||||
runs ->
|
|
||||||
expect($('#fold-start-install').hasClass('open')).toBeFalsy()
|
|
||||||
$('#fold-start-install').click()
|
|
||||||
waits 20
|
|
||||||
runs ->
|
|
||||||
expect($('#fold-start-install').hasClass('open')).toBeTruthy()
|
|
||||||
|
|
||||||
|
|
||||||
describe 'too long log', ->
|
|
||||||
beforeEach ->
|
|
||||||
$.mockjax
|
|
||||||
url: '/jobs/2/log?cors_hax=true'
|
|
||||||
responseTime: 0
|
|
||||||
responseText: '1\n2\n3\n4\n5\n6\n7\n8\n9\n10'
|
|
||||||
|
|
||||||
Log.LIMIT = 5
|
|
||||||
|
|
||||||
app 'travis-ci/travis-core/jobs/2'
|
|
||||||
waitFor logRendered
|
|
||||||
|
|
||||||
afterEach ->
|
|
||||||
Log.LIMIT = 10000
|
|
||||||
|
|
||||||
it 'is cut after given limit', ->
|
|
||||||
displaysLog [
|
|
||||||
'12345'
|
|
||||||
]
|
|
||||||
|
|
||||||
expect( $('#log-container .warning').text() ).toMatch /This log is too long to be displayed/
|
|
||||||
expect( $('#log-container .warning a').attr('href') ).toEqual '/jobs/2/log.txt?deansi=true'
|
|
||||||
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
describe 'my repos tab', ->
|
|
||||||
describe 'when user is signed in', ->
|
|
||||||
beforeEach ->
|
|
||||||
app '/', user: true
|
|
||||||
waitFor myReposRendered, 'my repositories'
|
|
||||||
runs ->
|
|
||||||
waitFor buildRendered, 'build view'
|
|
||||||
|
|
||||||
it 'is active', ->
|
|
||||||
listsRepos [
|
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
|
||||||
]
|
|
||||||
|
|
||||||
displaysRepository
|
|
||||||
href: '/travis-ci/travis-core'
|
|
||||||
|
|
||||||
displaysSummary
|
|
||||||
type: 'build'
|
|
||||||
id: 1
|
|
||||||
repo: 'travis-ci/travis-core'
|
|
||||||
commit: '1234567'
|
|
||||||
branch: 'master'
|
|
||||||
compare: '0123456..1234567'
|
|
||||||
finishedAt: '3 minutes ago'
|
|
||||||
duration: '30 sec'
|
|
||||||
message: 'commit message 1'
|
|
||||||
|
|
||||||
describe 'when user is not signed in', ->
|
|
||||||
beforeEach ->
|
|
||||||
app '/'
|
|
||||||
waitFor reposRendered, 'repositories list'
|
|
||||||
runs ->
|
|
||||||
waitFor buildRendered, 'build view'
|
|
||||||
|
|
||||||
it 'is activated when user signs in', ->
|
|
||||||
listsRepos [
|
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
||||||
{ slug: 'travis-ci/travis-assets', build: { number: 3, url: '/travis-ci/travis-assets/builds/3', duration: '30 sec', finishedAt: 'a day ago' } }
|
|
||||||
]
|
|
||||||
|
|
||||||
signInUser()
|
|
||||||
|
|
||||||
waitFor myReposRendered, 'my repositories'
|
|
||||||
runs ->
|
|
||||||
waitFor buildRendered, 'build view'
|
|
||||||
runs ->
|
|
||||||
listsRepos [
|
|
||||||
{ slug: 'travis-ci/travis-core', build: { number: 1, url: '/travis-ci/travis-core/builds/1', duration: '30 sec', finishedAt: '3 minutes ago' } }
|
|
||||||
{ slug: 'travis-ci/travis-hub', build: { number: 4, url: '/travis-ci/travis-hub/builds/4', duration: '1 min', finishedAt: '-' } }
|
|
||||||
]
|
|
|
@ -1,7 +0,0 @@
|
||||||
describe 'router', ->
|
|
||||||
it 'renders notFound template when URL can\t be found', ->
|
|
||||||
app '/somehing/something/something/.../dark/side/..../something/something/something/.../complete'
|
|
||||||
waitFor appRendered
|
|
||||||
runs ->
|
|
||||||
expect( $('#main').text().trim() ).toEqual('The requested page was not found.')
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#describe 'the sidebar', ->
|
|
||||||
# beforeEach ->
|
|
||||||
# app 'travis-ci/travis-core/jobs/1'
|
|
||||||
# waitFor jobRendered
|
|
||||||
# runs ->
|
|
||||||
# waitFor hasText('#tab_build', 'Build #1')
|
|
||||||
#
|
|
||||||
# it 'displays the expected stuff', ->
|
|
||||||
# listsQueues [
|
|
||||||
# { name: 'linux', item: { number: '5.1', repo: 'travis-ci/travis-core' } }
|
|
||||||
# { name: 'linux', item: { number: '5.2', repo: 'travis-ci/travis-core' } }
|
|
||||||
# ]
|
|
|
@ -1,6 +1,22 @@
|
||||||
minispade.require 'app'
|
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
|
||||||
|
|
||||||
@signInUser = ->
|
Travis.rootElement = '#ember-testing';
|
||||||
|
Travis.setupForTesting();
|
||||||
|
Travis.injectTestHelpers();
|
||||||
|
|
||||||
|
oldSetup = Travis.setup
|
||||||
|
Travis.ready = ->
|
||||||
|
oldSetup.apply(this, arguments)
|
||||||
|
Travis.auth.signOut()
|
||||||
|
|
||||||
|
window.exists = (selector) ->
|
||||||
|
return !!find(selector).length
|
||||||
|
|
||||||
|
Ember.Container.prototype.stub = (fullName, instance) ->
|
||||||
|
instance.destroy = instance.destroy || (->)
|
||||||
|
this.cache.dict[fullName] = instance
|
||||||
|
|
||||||
|
window.signInUser = ->
|
||||||
# for now let's just use harcoded data to log in the user,
|
# for now let's just use harcoded data to log in the user,
|
||||||
# we may extend it in the future to pass specific user data
|
# we may extend it in the future to pass specific user data
|
||||||
Travis.auth.signIn
|
Travis.auth.signIn
|
||||||
|
@ -11,20 +27,19 @@ minispade.require 'app'
|
||||||
token: 'abcdef'
|
token: 'abcdef'
|
||||||
token: 'abcdef'
|
token: 'abcdef'
|
||||||
|
|
||||||
@app = (url, options = {}) ->
|
#@app = (url, options = {}) ->
|
||||||
# TODO: this should wait till app is initialized, not some
|
# # TODO: this should wait till app is initialized, not some
|
||||||
# arbitrary amount of time
|
# # arbitrary amount of time
|
||||||
waits(50)
|
# waits(50)
|
||||||
runs ->
|
# runs ->
|
||||||
Travis.reset()
|
# Travis.reset()
|
||||||
Travis.auth.signOut()
|
# Travis.auth.signOut()
|
||||||
|
#
|
||||||
if options.user
|
# if options.user
|
||||||
signInUser()
|
# signInUser()
|
||||||
url = "/#{url}" unless url.match /^\//
|
# url = "/#{url}" unless url.match /^\//
|
||||||
visit(url)
|
# visit(url)
|
||||||
|
|
||||||
now = -> new Date('2012-07-02T00:03:00Z')
|
now = -> new Date('2012-07-02T00:03:00Z')
|
||||||
$.timeago.settings.nowFunction = -> now().getTime()
|
$.timeago.settings.nowFunction = -> now().getTime()
|
||||||
Travis.currentDate = now
|
Travis.currentDate = now
|
||||||
Travis.testing = true
|
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
@displaysRepository = (repo) ->
|
@displaysRepository = (repo) ->
|
||||||
expect($('#repo h3 a').attr('href')).toEqual (repo.href)
|
equal($('#repo h3 a').attr('href'), repo.href, 'repository title should link to repo page')
|
||||||
expect($('#repo .github-icon a').attr('href')).toEqual ("http://github.com#{repo.href}")
|
equal($('#repo .github-icon a').attr('href'), "http://github.com#{repo.href}", 'github icon should link to repo on github')
|
||||||
|
|
||||||
@displaysTabs = (tabs) ->
|
@displaysTabs = (tabs) ->
|
||||||
for name, tab of tabs
|
for name, tab of tabs
|
||||||
expect($("#tab_#{name} a").attr('href')).toEqual tab.href unless tab.hidden
|
equal($("#tab_#{name} a").attr('href'), tab.href, "#{name} tab should link to #{tab.href}") unless tab.hidden
|
||||||
expect($("#tab_#{name}").hasClass('active')).toEqual !!tab.active
|
equal($("#tab_#{name}").hasClass('active'), !!tab.active, "#{name} tab should be active")
|
||||||
expect($("#tab_#{name}").hasClass('display-inline')).toEqual !tab.hidden if name in ['build', 'job']
|
equal($("#tab_#{name}").hasClass('display-inline'), !tab.hidden, "#{name} tab should has class display-inline") if name in ['build', 'job']
|
||||||
|
|
||||||
@displaysSummaryBuildLink = (link, number) ->
|
@displaysSummaryBuildLink = (link, number) ->
|
||||||
element = $('#summary .number a')
|
element = $('#summary .number a')
|
||||||
expect( element.attr('href') ).toEqual link
|
equal( element.attr('href') , link)
|
||||||
expect( element.text().trim() ).toEqual "#{number}"
|
equal( element.text().trim() , "#{number}")
|
||||||
|
|
||||||
@displaysSummary = (data) ->
|
@displaysSummary = (data) ->
|
||||||
element = $('#summary .left:first-child dt:first-child')
|
element = $('#summary .left:first-child dt:first-child')
|
||||||
expect(element.text()).toEqual $.camelize(data.type)
|
equal(element.text(), $.camelize(data.type))
|
||||||
|
|
||||||
element = $('#summary .number a')
|
element = $('#summary .number a')
|
||||||
expect(element.attr('href')).toEqual "/#{data.repo}/#{data.type}s/#{data.id}"
|
equal(element.attr('href'), "/#{data.repo}/#{data.type}s/#{data.id}")
|
||||||
|
|
||||||
element = $('#summary .finished_at')
|
element = $('#summary .finished_at')
|
||||||
expect(element.text()).toEqual data.finishedAt
|
equal(element.text(), data.finishedAt)
|
||||||
|
|
||||||
element = $('#summary .duration')
|
element = $('#summary .duration')
|
||||||
expect(element.text()).toEqual data.duration
|
equal(element.text(), data.duration)
|
||||||
|
|
||||||
element = $('#summary .commit a')
|
element = $('#summary .commit a')
|
||||||
expect(element.attr('href')).toEqual "http://github.com/#{data.repo}/commit/#{data.commit}"
|
equal(element.attr('href'), "http://github.com/#{data.repo}/commit/#{data.commit}")
|
||||||
|
|
||||||
element = $('#summary .commit a')
|
element = $('#summary .commit a')
|
||||||
expect(element.text()).toEqual "#{data.commit} (#{data.branch})"
|
equal(element.text(), "#{data.commit} (#{data.branch})")
|
||||||
|
|
||||||
element = $('#summary .compare a')
|
element = $('#summary .compare a')
|
||||||
expect(element.attr('href')).toEqual "http://github.com/compare/#{data.compare}"
|
equal(element.attr('href'), "http://github.com/compare/#{data.compare}")
|
||||||
|
|
||||||
element = $('#summary .compare a')
|
element = $('#summary .compare a')
|
||||||
expect(element.text()).toEqual data.compare
|
equal(element.text(), data.compare)
|
||||||
|
|
||||||
element = $('#summary .message')
|
element = $('#summary .message')
|
||||||
expect(element.text()).toEqual data.message
|
equal(element.text(), data.message)
|
||||||
|
|
||||||
@displaysLog = (lines) ->
|
@displaysLog = (lines) ->
|
||||||
log = lines.join('')
|
log = lines.join('')
|
||||||
expect($('#log p').text().trim()).toEqual log
|
equal($('#log p').text().trim(), log)
|
||||||
|
|
||||||
@listsRepos = (items) ->
|
@listsRepos = (items) ->
|
||||||
listsItems('repo', items)
|
listsItems('repo', items)
|
||||||
|
@ -52,10 +52,10 @@
|
||||||
row = $('#repos li')[data.row - 1]
|
row = $('#repos li')[data.row - 1]
|
||||||
repo = data.item
|
repo = data.item
|
||||||
|
|
||||||
expect($('a.slug', row).attr('href')).toEqual "/#{repo.slug}"
|
equal($('a.slug', row).attr('href'), "/#{repo.slug}")
|
||||||
expect($('a.last_build', row).attr('href')).toEqual repo.build.url
|
equal($('a.last_build', row).attr('href'), repo.build.url)
|
||||||
expect($('.duration', row).text()).toEqual repo.build.duration
|
equal($('.duration', row).text(), repo.build.duration)
|
||||||
expect($('.finished_at', row).text()).toEqual repo.build.finishedAt
|
equal($('.finished_at', row).text(), repo.build.finishedAt)
|
||||||
|
|
||||||
@listsBuilds = (builds) ->
|
@listsBuilds = (builds) ->
|
||||||
listsItems('build', builds)
|
listsItems('build', builds)
|
||||||
|
@ -64,17 +64,17 @@
|
||||||
row = $('#builds tbody tr')[data.row - 1]
|
row = $('#builds tbody tr')[data.row - 1]
|
||||||
build = data.item
|
build = data.item
|
||||||
|
|
||||||
expect($('.number a', row).attr('href')).toEqual "/#{build.slug}/builds/#{build.id}"
|
equal($('.number a', row).attr('href'), "/#{build.slug}/builds/#{build.id}")
|
||||||
expect($('.number a', row).text().trim()).toEqual build.number
|
equal($('.number a', row).text().trim(), build.number)
|
||||||
expect($('.message', row).text().trim()).toEqual build.message
|
equal($('.message', row).text().trim(), build.message)
|
||||||
expect($('.duration', row).text().trim()).toEqual build.duration
|
equal($('.duration', row).text().trim(), build.duration)
|
||||||
expect($('.finished_at', row).text().trim()).toEqual build.finishedAt
|
equal($('.finished_at', row).text().trim(), build.finishedAt)
|
||||||
expect($(row).attr('class')).toMatch build.color
|
ok($(row).attr('class').match(build.color))
|
||||||
|
|
||||||
@listsJobs = (data) ->
|
@listsJobs = (data) ->
|
||||||
table = $(data.table)
|
table = $(data.table)
|
||||||
headers = ($(element).text() for element in $("thead th", table))
|
headers = ($(element).text() for element in $("thead th", table))
|
||||||
expect(headers).toEqual(data.headers)
|
deepEqual(headers, data.headers)
|
||||||
|
|
||||||
$.each data.jobs, (row, job) -> listsJob(table: data.table, row: row + 1, item: job)
|
$.each data.jobs, (row, job) -> listsJob(table: data.table, row: row + 1, item: job)
|
||||||
|
|
||||||
|
@ -83,22 +83,22 @@
|
||||||
job = data.item
|
job = data.item
|
||||||
|
|
||||||
element = $(row)
|
element = $(row)
|
||||||
expect(element.attr('class')).toMatch job.color
|
ok(element.attr('class').match(job.color))
|
||||||
|
|
||||||
element = $("td.number", row)
|
element = $("td.number", row)
|
||||||
expect(element.text().trim()).toEqual job.number
|
equal(element.text().trim(), job.number)
|
||||||
|
|
||||||
element = $("td.number a", row)
|
element = $("td.number a", row)
|
||||||
expect(element.attr('href')).toEqual "/#{job.repo}/jobs/#{job.id}"
|
equal(element.attr('href'), "/#{job.repo}/jobs/#{job.id}")
|
||||||
|
|
||||||
element = $("td.duration", row)
|
element = $("td.duration", row)
|
||||||
expect(element.text().trim()).toEqual job.duration
|
equal(element.text().trim(), job.duration)
|
||||||
|
|
||||||
element = $("td.finished_at", row)
|
element = $("td.finished_at", row)
|
||||||
expect(element.text().trim()).toEqual job.finishedAt
|
equal(element.text().trim(), job.finishedAt)
|
||||||
|
|
||||||
element = $("td:nth-child(6)", row)
|
element = $("td:nth-child(6)", row)
|
||||||
expect(element.text().trim()).toEqual job.rvm
|
equal(element.text().trim(), job.rvm)
|
||||||
|
|
||||||
@listsQueuedJobs = (jobs) ->
|
@listsQueuedJobs = (jobs) ->
|
||||||
listsItems('queuedJob', jobs)
|
listsItems('queuedJob', jobs)
|
||||||
|
@ -106,19 +106,19 @@
|
||||||
@listsQueuedJob = (data) ->
|
@listsQueuedJob = (data) ->
|
||||||
job = data.item
|
job = data.item
|
||||||
text = $($("#queue_#{data.name} li")[data.row - 1]).text()
|
text = $($("#queue_#{data.name} li")[data.row - 1]).text()
|
||||||
expect(text).toContain job.repo
|
ok(text.match(job.repo), "#{text} should contain #{job.repo}")
|
||||||
expect(text).toContain "##{job.number}"
|
ok(text.match(job.repo), "#{text} should contain #{job.number}")
|
||||||
|
|
||||||
@listsQueue = (data) ->
|
@listsQueue = (data) ->
|
||||||
name = data.item.name
|
name = data.item.name
|
||||||
job = data.item.item
|
job = data.item.item
|
||||||
text = $($("#queue_#{name} li")[data.row - 1]).text()
|
text = $($("#queue_#{name} li")[data.row - 1]).text()
|
||||||
expect(text).toContain job.repo
|
ok(text.match(job.repo), "#{text} should contain #{job.repo}")
|
||||||
expect(text).toContain "##{job.number}"
|
ok(text.match(job.repo), "#{text} should contain #{job.number}")
|
||||||
|
|
||||||
@listsItems = (type, items) ->
|
@listsItems = (type, items) ->
|
||||||
$.each items, (row, item) =>
|
$.each items, (row, item) =>
|
||||||
this["lists#{$.camelize(type)}"](item: item, row: row + 1)
|
window["lists#{$.camelize(type)}"](item: item, row: row + 1)
|
||||||
|
|
||||||
@listsQueues = (queues) ->
|
@listsQueues = (queues) ->
|
||||||
listsItems('queue', queues)
|
listsItems('queue', queues)
|
||||||
|
@ -128,5 +128,5 @@
|
||||||
element = $($('ul li', group)[data.row - 1])
|
element = $($('ul li', group)[data.row - 1])
|
||||||
worker = data.item
|
worker = data.item
|
||||||
|
|
||||||
expect(element.text()).toContain worker.name
|
ok(element.text().match(worker.name))
|
||||||
expect(element.text()).toContain worker.state
|
ok(element.text().match(worker.state))
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
@after = (time, func) ->
|
#@after = (time, func) ->
|
||||||
waits(time)
|
# waits(time)
|
||||||
jasmine.getEnv().currentSpec.runs(func)
|
# jasmine.getEnv().currentSpec.runs(func)
|
||||||
|
#
|
||||||
@once = (condition, func) ->
|
#@once = (condition, func) ->
|
||||||
waitsFor(condition)
|
# waitsFor(condition)
|
||||||
jasmine.getEnv().currentSpec.runs(func)
|
# jasmine.getEnv().currentSpec.runs(func)
|
||||||
|
#
|
||||||
@waitFor = waitsFor
|
#@waitFor = waitsFor
|
||||||
|
#
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
minispade.require 'ext/jquery'
|
||||||
|
|
||||||
responseTime = 0
|
responseTime = 0
|
||||||
|
|
||||||
repos = [
|
repos = [
|
||||||
{ id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_result: 0, last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core' },
|
{ id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_state: 'passed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core' },
|
||||||
{ id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_result: 1, last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets'},
|
{ id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_state: 'failed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets'},
|
||||||
{ id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_result: undefined, last_build_duration: undefined, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: undefined, description: 'Description of travis-hub'},
|
{ id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_state: null, last_build_duration: null, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: null, description: 'Description of travis-hub'},
|
||||||
]
|
]
|
||||||
|
|
||||||
reposByName = (name) ->
|
reposByName = (name) ->
|
||||||
|
@ -16,9 +18,9 @@ reposByName = (name) ->
|
||||||
|
|
||||||
builds = [
|
builds = [
|
||||||
{ id: '1', repository_id: '1', commit_id: 1, job_ids: [1, 2, 3], number: 1, pull_request: false, config: { rvm: ['rbx', '1.9.3', 'jruby'] }, duration: 30, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:30Z', state: 'passed' },
|
{ id: '1', repository_id: '1', commit_id: 1, job_ids: [1, 2, 3], number: 1, pull_request: false, config: { rvm: ['rbx', '1.9.3', 'jruby'] }, duration: 30, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:30Z', state: 'passed' },
|
||||||
{ id: '2', repository_id: '1', commit_id: 2, job_ids: [4], number: 2, pull_request: false, config: { rvm: ['rbx'] } },
|
{ id: '2', repository_id: '1', commit_id: 2, job_ids: [4], number: 2, pull_request: false, config: { rvm: ['rbx'] }, duration: null },
|
||||||
{ id: '3', repository_id: '2', commit_id: 3, job_ids: [5], number: 3, pull_request: false, config: { rvm: ['rbx'] }, duration: 30, started_at: '2012-07-02T00:01:00Z', finished_at: '2012-07-01T00:01:30Z', state: 'failed' },
|
{ id: '3', repository_id: '2', commit_id: 3, job_ids: [5], number: 3, pull_request: false, config: { rvm: ['rbx'] }, duration: 30, started_at: '2012-07-02T00:01:00Z', finished_at: '2012-07-01T00:01:30Z', state: 'failed' },
|
||||||
{ id: '4', repository_id: '3', commit_id: 4, job_ids: [6], number: 4, pull_request: false, config: { rvm: ['rbx'] }, started_at: '2012-07-02T00:02:00Z' },
|
{ id: '4', repository_id: '3', commit_id: 4, job_ids: [6], number: 4, pull_request: false, config: { rvm: ['rbx'] }, duration: null, started_at: '2012-07-02T00:02:00Z' },
|
||||||
]
|
]
|
||||||
|
|
||||||
commits = [
|
commits = [
|
||||||
|
@ -29,14 +31,14 @@ commits = [
|
||||||
]
|
]
|
||||||
|
|
||||||
jobs = [
|
jobs = [
|
||||||
{ id: '1', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 1, number: '1.1', config: { rvm: 'rbx' }, duration: 30, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:30Z', state: 'passed' }
|
{ id: '1', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 1, number: '1.1', config: { rvm: 'rbx' }, duration: 30, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:30Z', state: 'passed', allow_failure: false }
|
||||||
{ id: '2', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 2, number: '1.2', config: { rvm: '1.9.3' }, duration: 40, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:40Z', state: 'failed' }
|
{ id: '2', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 2, number: '1.2', config: { rvm: '1.9.3' }, duration: 40, started_at: '2012-07-02T00:00:00Z', finished_at: '2012-07-02T00:00:40Z', state: 'failed', allow_failure: false }
|
||||||
{ id: '3', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 3, number: '1.3', config: { rvm: 'jruby' }, allow_failure: true }
|
{ id: '3', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 1, commit_id: 1, log_id: 3, number: '1.3', config: { rvm: 'jruby' }, duration: null, started_at: null, finished_at: null, allow_failure: true, state: null }
|
||||||
{ id: '4', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 2, commit_id: 2, log_id: 4, number: '2.1', config: { rvm: 'rbx' } }
|
{ id: '4', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 2, commit_id: 2, log_id: 4, number: '2.1', config: { rvm: 'rbx' }, duration: null, started_at: null, finished_at: null, allow_failure: false, state: null }
|
||||||
{ id: '5', repository_id: 2, repository_slug: 'travis-ci/travis-assets', build_id: 3, commit_id: 3, log_id: 5, number: '3.1', config: { rvm: 'rbx' }, duration: 30, started_at: '2012-07-02T00:01:00Z', finished_at: '2012-07-02T00:01:30Z', state: 'failed' }
|
{ id: '5', repository_id: 2, repository_slug: 'travis-ci/travis-assets', build_id: 3, commit_id: 3, log_id: 5, number: '3.1', config: { rvm: 'rbx' }, duration: 30, started_at: '2012-07-02T00:01:00Z', finished_at: '2012-07-02T00:01:30Z', state: 'failed', allow_failure: false }
|
||||||
{ id: '6', repository_id: 3, repository_slug: 'travis-ci/travis-hub', build_id: 4, commit_id: 4, log_id: 6, number: '4.1', config: { rvm: 'rbx' }, started_at: '2012-07-02T00:02:00Z' }
|
{ id: '6', repository_id: 3, repository_slug: 'travis-ci/travis-hub', build_id: 4, commit_id: 4, log_id: 6, number: '4.1', config: { rvm: 'rbx' }, started_at: '2012-07-02T00:02:00Z', allow_failure: false, state: null }
|
||||||
{ id: '7', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 5, commit_id: 5, log_id: 7, number: '5.1', config: { rvm: 'rbx' }, state: 'created', queue: 'builds.linux' }
|
{ id: '7', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 5, commit_id: 5, log_id: 7, number: '5.1', config: { rvm: 'rbx' }, duration: null, started_at: null, finished_at: null, state: 'created', queue: 'builds.linux', allow_failure: false }
|
||||||
{ id: '8', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 5, commit_id: 5, log_id: 8, number: '5.2', config: { rvm: 'rbx' }, state: 'created', queue: 'builds.linux' }
|
{ id: '8', repository_id: 1, repository_slug: 'travis-ci/travis-core', build_id: 5, commit_id: 5, log_id: 8, number: '5.2', config: { rvm: 'rbx' }, duration: null, started_at: null, finished_at: null, state: 'created', queue: 'builds.linux', allow_failure: false }
|
||||||
]
|
]
|
||||||
|
|
||||||
artifacts = [
|
artifacts = [
|
||||||
|
@ -139,6 +141,16 @@ $.mockjax
|
||||||
responseText:
|
responseText:
|
||||||
jobs: $.select(jobs, (job) -> job.state == 'created')
|
jobs: $.select(jobs, (job) -> job.state == 'created')
|
||||||
|
|
||||||
|
$.mockjax
|
||||||
|
url: '/builds*'
|
||||||
|
responseTime: responseTime
|
||||||
|
response: (settings) ->
|
||||||
|
if match = settings.url.match('/builds\\?(ids.*)')
|
||||||
|
ids = match[1].split(new RegExp('&?ids\\[\\]=')).filter (str) -> str != ''
|
||||||
|
this.responseText = { builds: $.select(builds, (build) -> ids.contains(build.id) ) }
|
||||||
|
else
|
||||||
|
throw "can't handle mocked request"
|
||||||
|
|
||||||
for data in branches
|
for data in branches
|
||||||
$.mockjax
|
$.mockjax
|
||||||
url: '/branches'
|
url: '/branches'
|
||||||
|
|
|
@ -1,46 +1,57 @@
|
||||||
store = null
|
|
||||||
record = null
|
record = null
|
||||||
|
|
||||||
describe 'Travis.Build', ->
|
module "Travis.Build",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
store = Travis.Store.create()
|
teardown: ->
|
||||||
|
Travis.Build.resetData()
|
||||||
|
Travis.Job.resetData()
|
||||||
|
|
||||||
afterEach ->
|
test 'it does not load record on duration, finishedAt and result if job is not in finished state', ->
|
||||||
store.destroy()
|
Travis.Build.load [{ id: 1, state: 'started' }]
|
||||||
|
|
||||||
describe 'incomplete attributes', ->
|
Ember.run ->
|
||||||
beforeEach ->
|
record = Travis.Build.find 1
|
||||||
store.loadIncomplete Travis.Build, { id: 1, state: 'started' }
|
|
||||||
record = store.find Travis.Build, 1
|
|
||||||
|
|
||||||
it 'does not load record on duration, finishedAt and result if job is not in finished state', ->
|
record.loadTheRest = ->
|
||||||
record.get('_duration')
|
ok(false, 'loadTheRest should not be called')
|
||||||
record.get('finishedAt')
|
|
||||||
record.get('result')
|
|
||||||
|
|
||||||
waits 50
|
record.get('_duration')
|
||||||
runs ->
|
record.get('finishedAt')
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
record.get('result')
|
||||||
|
|
||||||
it 'loads the rest of the record if it\'s in finished state', ->
|
wait().then ->
|
||||||
store.loadIncomplete Travis.Build, { id: 1, state: 'passed' }
|
ok(true, 'loadTheRest was not called')
|
||||||
record = store.find Travis.Build, 1
|
|
||||||
record.get('finishedAt')
|
|
||||||
|
|
||||||
waits 50
|
test 'it loads record on duration, finishedAt and result if job is in finished state', ->
|
||||||
runs ->
|
expect(1)
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
describe 'configKeys', ->
|
Travis.Build.load [{ id: 1, state: 'passed' }]
|
||||||
it 'takes into account all the jobs when getting config keys', ->
|
|
||||||
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
|
||||||
store.load Travis.Build, { id: '1', job_ids: ['1', '2', '3'], config: buildConfig }, { id: '1' }
|
|
||||||
|
|
||||||
store.load Travis.Job, { id: '1', config: { rvm: '1.9.3', env: 'FOO=foo' } }, { id: '1' }
|
Ember.run ->
|
||||||
store.load Travis.Job, { id: '2', config: { rvm: '2.0.0', gemfile: 'Gemfile.1' } }, { id: '2' }
|
record = Travis.Build.find 1
|
||||||
store.load Travis.Job, { id: '3', config: { rvm: '1.9.3', jdk: 'OpenJDK' } }, { id: '3' }
|
|
||||||
|
|
||||||
build = store.find(Travis.Build, '1')
|
record.loadTheRest = ->
|
||||||
|
ok(true, 'loadTheRest should be called')
|
||||||
|
|
||||||
expect( build.get('rawConfigKeys') ).toEqual( ['rvm', 'env', 'gemfile', 'jdk' ] )
|
record.get('finishedAt')
|
||||||
expect( build.get('configKeys') ).toEqual( [ 'Job', 'Duration', 'Finished', 'Rvm', 'Env', 'Gemfile', 'Jdk' ] )
|
|
||||||
|
wait()
|
||||||
|
|
||||||
|
test 'it takes into account all the jobs when getting config keys', ->
|
||||||
|
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
||||||
|
Travis.Build.load [{ id: '1', job_ids: ['1', '2', '3'], config: buildConfig }]
|
||||||
|
|
||||||
|
Travis.Job.load [{ id: '1', config: { rvm: '1.9.3', env: 'FOO=foo' } }]
|
||||||
|
Travis.Job.load [{ id: '2', config: { rvm: '2.0.0', gemfile: 'Gemfile.1' } }]
|
||||||
|
Travis.Job.load [{ id: '3', config: { rvm: '1.9.3', jdk: 'OpenJDK' } }]
|
||||||
|
|
||||||
|
build = null
|
||||||
|
rawConfigKeys = null
|
||||||
|
configKeys = null
|
||||||
|
Ember.run ->
|
||||||
|
build = Travis.Build.find '1'
|
||||||
|
rawConfigKeys = build.get('rawConfigKeys')
|
||||||
|
configKeys = build.get('configKeys')
|
||||||
|
|
||||||
|
deepEqual(rawConfigKeys, ['rvm', 'env', 'gemfile', 'jdk' ])
|
||||||
|
deepEqual(configKeys, [ 'Job', 'Duration', 'Finished', 'Rvm', 'Env', 'Gemfile', 'Jdk' ])
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
createChunk = (number, content, options) ->
|
|
||||||
Em.Object.create(number: number, content: content, final: options?.final)
|
|
||||||
|
|
||||||
describe 'Travis.ChunkBuffer', ->
|
|
||||||
it 'waits for parts to be in order before revealing them', ->
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: [])
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(3, "baz")
|
|
||||||
buffer.pushObject createChunk(2, "bar")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(0)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(3)
|
|
||||||
|
|
||||||
expect(buffer.toArray()).toEqual(['foo', 'bar', 'baz'])
|
|
||||||
|
|
||||||
it 'ignores a part if it fails to be delivered within timeout', ->
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: [], timeout: 20, checkTimeoutFrequency: 5)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(3, "baz")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(0)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(1)
|
|
||||||
|
|
||||||
waits 100
|
|
||||||
runs ->
|
|
||||||
expect(buffer.get('length')).toEqual(2)
|
|
||||||
expect(buffer.toArray()).toEqual(['foo', 'baz'])
|
|
||||||
|
|
||||||
buffer.destroy()
|
|
||||||
|
|
||||||
it 'works correctly when parts are passed as content', ->
|
|
||||||
content = [createChunk(2, 'bar')]
|
|
||||||
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: content)
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(0)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(2)
|
|
||||||
expect(buffer.toArray()).toEqual(['foo', 'bar'])
|
|
||||||
|
|
||||||
it 'works correctly when parts duplicated', ->
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: [])
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
buffer.pushObject createChunk(2, "bar")
|
|
||||||
buffer.pushObject createChunk(3, "baz")
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(2, "bar")
|
|
||||||
buffer.pushObject createChunk(3, "baz")
|
|
||||||
buffer.pushObject createChunk(4, "qux")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(4)
|
|
||||||
expect(buffer.toArray()).toEqual(['foo', 'bar', 'baz', 'qux'])
|
|
||||||
|
|
||||||
it 'fires array observers properly', ->
|
|
||||||
changes = []
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: [])
|
|
||||||
|
|
||||||
observer = Em.Object.extend(
|
|
||||||
init: ->
|
|
||||||
@_super.apply this, arguments
|
|
||||||
|
|
||||||
@get('content').addArrayObserver this,
|
|
||||||
willChange: 'arrayWillChange',
|
|
||||||
didChange: 'arrayDidChange'
|
|
||||||
|
|
||||||
arrayWillChange: (->)
|
|
||||||
arrayDidChange: (array, index, removedCount, addedCount) ->
|
|
||||||
changes.pushObject([index, addedCount])
|
|
||||||
).create(content: buffer)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(2, "baz")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(0)
|
|
||||||
expect(changes.length).toEqual(0)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(2)
|
|
||||||
expect(changes.length).toEqual(1)
|
|
||||||
expect(changes[0]).toEqual([0, 2])
|
|
||||||
|
|
||||||
it 'sets next to start if start is given at init', ->
|
|
||||||
buffer = Travis.ChunkBuffer.create(content: [], start: 5)
|
|
||||||
expect(buffer.get('next')).toEqual(5)
|
|
||||||
|
|
||||||
it 'runs finalize after getting final element', ->
|
|
||||||
finalizeRuns = 0
|
|
||||||
buffer = Travis.ChunkBuffer.extend({
|
|
||||||
finalize: ->
|
|
||||||
@_super.apply this, arguments
|
|
||||||
finalizeRuns += 1
|
|
||||||
}).create(content: [])
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(1, "foo")
|
|
||||||
buffer.pushObject createChunk(2, "bar")
|
|
||||||
buffer.pushObject createChunk(3, "baz")
|
|
||||||
|
|
||||||
expect(finalizeRuns).toEqual(0)
|
|
||||||
|
|
||||||
buffer.pushObject createChunk(4, "qux", final: true)
|
|
||||||
|
|
||||||
expect(buffer.get('length')).toEqual(4)
|
|
||||||
|
|
||||||
expect(finalizeRuns).toEqual(1)
|
|
|
@ -1,188 +1,83 @@
|
||||||
record = null
|
fullPostHash = null
|
||||||
store = null
|
Post = null
|
||||||
adapterClass = null
|
Author = null
|
||||||
|
|
||||||
describe 'Travis.Model - incomplete', ->
|
module "Travis.Model - incomplete",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
$.mockjax
|
fullPostHash = {
|
||||||
url: '/foos/1'
|
id: '1',
|
||||||
responseTime: 1
|
title: 'foo',
|
||||||
responseText: { foo: { id: 1, name: 'foo', description: 'bar' } }
|
published_at: 'today',
|
||||||
|
|
||||||
Travis.Foo = Travis.Model.extend
|
author_id: '1'
|
||||||
name: DS.attr('string')
|
}
|
||||||
description: DS.attr('string')
|
|
||||||
lastName: DS.attr('string')
|
|
||||||
|
|
||||||
bar: DS.belongsTo('Travis.Bar')
|
Author = Travis.Model.extend()
|
||||||
niceBar: DS.belongsTo('Travis.Bar')
|
|
||||||
veryNiceBar: DS.belongsTo('Travis.Bar')
|
|
||||||
|
|
||||||
Travis.Foo.toString = -> 'Travis.Foo'
|
Post = Travis.Model.extend(
|
||||||
|
title: Ember.attr('string'),
|
||||||
|
publishedAt: Ember.attr('string', key: 'published_at'),
|
||||||
|
|
||||||
Travis.Bar = Travis.Model.extend
|
author: Ember.belongsTo(Author, { key: 'author_id' })
|
||||||
name: DS.attr('string')
|
)
|
||||||
foos: DS.hasMany('Travis.Foo')
|
|
||||||
|
|
||||||
Travis.Bar.toString = -> 'Travis.Bar'
|
Post.adapter = Ember.FixtureAdapter.create()
|
||||||
|
|
||||||
adapterClass = Travis.RestAdapter.extend()
|
test "record is marked as incomplete if attributes are missing when loading a record", ->
|
||||||
adapterClass.map 'Travis.Foo',
|
Post.load([{ id: '1', title: 'foo' }])
|
||||||
veryNiceBar: { key: 'very_nice_bar_indeed_id' }
|
|
||||||
niceBar: { key: 'nice_bar_id' }
|
|
||||||
|
|
||||||
store = Travis.Store.create
|
record = Post.find('1')
|
||||||
adapter: adapterClass.create()
|
ok(record.get('incomplete'), 'record should be incomplete')
|
||||||
|
equal(record.get('title'), 'foo', 'attributes should be accessible')
|
||||||
|
|
||||||
afterEach ->
|
test "record is marked as complete if missing attributes are loaded", ->
|
||||||
delete Travis.Foo
|
Post.load([{ id: '1', title: 'foo' }])
|
||||||
delete Travis.Bar
|
|
||||||
store.destroy()
|
|
||||||
|
|
||||||
it 'allows to merge many times', ->
|
record = Post.find('1')
|
||||||
store.load(Travis.Bar, { id: '1', foo_ids: ['1', '2'] }, { id: '1' })
|
ok(record.get('incomplete'), 'record should be complete')
|
||||||
store.load(Travis.Foo, { id: '1', bar_id: '1' }, { id: '1' })
|
equal(record.get('title'), 'foo', 'attributes should be accessible')
|
||||||
store.load(Travis.Foo, { id: '2', bar_id: '1' }, { id: '2' })
|
|
||||||
|
|
||||||
record = store.find(Travis.Bar, 1)
|
record.load('1', fullPostHash)
|
||||||
store.find(Travis.Foo, 1)
|
|
||||||
store.find(Travis.Foo, 2)
|
|
||||||
|
|
||||||
record.get('foos')
|
ok(!record.get('incomplete'), 'record should be complete')
|
||||||
store.loadIncomplete(Travis.Bar, id: 1, name: 'foo')
|
|
||||||
store.loadIncomplete(Travis.Bar, id: 1, name: 'bar')
|
|
||||||
|
|
||||||
expect( record.get('foos.length') ).toEqual(2)
|
test "record is marked as incomplete if belongsTo key is missing", ->
|
||||||
expect( record.get('name') ).toEqual('bar')
|
delete(fullPostHash.author_id)
|
||||||
|
Post.load([fullPostHash])
|
||||||
|
|
||||||
describe 'with incomplete record with loaded associations', ->
|
record = Post.find('1')
|
||||||
beforeEach ->
|
ok(record.get('incomplete'), 'record should be incomplete')
|
||||||
attrs = {
|
|
||||||
id: 1
|
|
||||||
bar_id: 2
|
|
||||||
nice_bar_id: 3
|
|
||||||
very_nice_bar_indeed_id: 4
|
|
||||||
}
|
|
||||||
store.loadIncomplete(Travis.Foo, attrs)
|
|
||||||
record = store.find Travis.Foo, 1
|
|
||||||
store.load(Travis.Bar, id: 2)
|
|
||||||
store.load(Travis.Bar, id: 3)
|
|
||||||
store.load(Travis.Bar, id: 4)
|
|
||||||
|
|
||||||
it 'does not load record on association access', ->
|
test "proeperty can be loaded as null, which means that the property is still loaded", ->
|
||||||
expect( record.get('bar.id') ).toEqual '2'
|
fullPostHash.author_id = null
|
||||||
expect( record.get('niceBar.id') ).toEqual '3'
|
fullPostHash.title = null
|
||||||
expect( record.get('veryNiceBar.id') ).toEqual '4'
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
describe 'with incomplete record without loaded associations', ->
|
Post.load([fullPostHash])
|
||||||
beforeEach ->
|
|
||||||
attrs = {
|
|
||||||
id: 1
|
|
||||||
}
|
|
||||||
store.loadIncomplete(Travis.Foo, attrs)
|
|
||||||
record = store.find Travis.Foo, 1
|
|
||||||
|
|
||||||
it 'loads record based on regular association key', ->
|
record = Post.find('1')
|
||||||
record.get('bar')
|
ok(!record.get('incomplete'), 'record should be complete')
|
||||||
waits 50
|
equal(record.get('title'), null, 'title should be null')
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
it 'loads record based on camel case association key', ->
|
test "when accessing missing property, record is loaded", ->
|
||||||
record.get('niceBar')
|
Post.FIXTURES = [fullPostHash]
|
||||||
waits 50
|
Post.load([{ id: '1' }])
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
it 'loads record based on ssociation with explicit key', ->
|
record = null
|
||||||
record.get('veryNiceBar')
|
Ember.run -> record = Post.find('1')
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
describe 'with incomplete record', ->
|
ok(record.get('incomplete'), 'record should be incomplete')
|
||||||
beforeEach ->
|
|
||||||
attrs = {
|
|
||||||
id: 1
|
|
||||||
name: 'foo'
|
|
||||||
last_name: 'foobar'
|
|
||||||
}
|
|
||||||
store.loadIncomplete(Travis.Foo, attrs)
|
|
||||||
record = store.find Travis.Foo, 1
|
|
||||||
|
|
||||||
it 'shows if attribute is loaded', ->
|
publishedAt = null
|
||||||
expect( record.isAttributeLoaded('name') ).toBeTruthy()
|
Ember.run -> publishedAt = record.get('publishedAt')
|
||||||
expect( record.isAttributeLoaded('description') ).toBeFalsy()
|
|
||||||
|
|
||||||
it 'does not trigger a request when getting known attribute', ->
|
ok(!publishedAt, 'publishedAt should be missing')
|
||||||
expect( record.get('name') ).toEqual 'foo'
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
it 'loads missing data if getPath is used', ->
|
stop()
|
||||||
other = Em.Object.create(record: record)
|
setTimeout( ->
|
||||||
expect( other.get('record.description') ).toBeNull()
|
start()
|
||||||
|
|
||||||
waits 50
|
Ember.run -> publishedAt = record.get('publishedAt')
|
||||||
runs ->
|
equal(publishedAt, 'today', 'publishedAt should be loaded')
|
||||||
expect( other.get('record.description') ).toEqual 'bar'
|
ok(!record.get('incomplete'), 'record should be complete')
|
||||||
expect( record.get('isComplete') ).toBeTruthy()
|
, 50)
|
||||||
|
|
||||||
it 'loads missing data on try to get it', ->
|
|
||||||
expect( record.get('name') ).toEqual 'foo'
|
|
||||||
expect( record.get('description') ).toBeNull()
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('description') ).toEqual 'bar'
|
|
||||||
expect( record.get('isComplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
it 'does not set incomplete on the record twice', ->
|
|
||||||
record.get('description')
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
store.loadIncomplete(Travis.Foo, id: 1)
|
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
it 'does not load data on non attribute', ->
|
|
||||||
record.get('foobarbaz')
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
it 'works with camel case values', ->
|
|
||||||
expect( record.get('lastName') ).toEqual 'foobar'
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
it 'adds takes into account additional data loaded as incomplete', ->
|
|
||||||
store.loadIncomplete(Travis.Foo, { id: 1, description: 'baz' })
|
|
||||||
record = store.find Travis.Foo, 1
|
|
||||||
expect( record.get('description') ).toEqual 'baz'
|
|
||||||
waits 50
|
|
||||||
runs ->
|
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
describe 'with complete record', ->
|
|
||||||
beforeEach ->
|
|
||||||
id = '5'
|
|
||||||
attrs = {
|
|
||||||
id: id
|
|
||||||
name: 'foo'
|
|
||||||
}
|
|
||||||
|
|
||||||
store.load(Travis.Foo, attrs, { id: attrs.id })
|
|
||||||
record = store.find(Travis.Foo, id)
|
|
||||||
|
|
||||||
it 'is marked as completed', ->
|
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
|
||||||
|
|
||||||
it 'allows to get regular attribute', ->
|
|
||||||
expect( record.get('name') ).toEqual 'foo'
|
|
||||||
|
|
||||||
it 'allows to check attribute state', ->
|
|
||||||
expect( record.isAttributeLoaded('name') ).toBeFalsy()
|
|
||||||
|
|
1
assets/scripts/spec/unit/incomplete_spec.js
Normal file
1
assets/scripts/spec/unit/incomplete_spec.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -1,86 +1,113 @@
|
||||||
store = null
|
|
||||||
record = null
|
record = null
|
||||||
|
|
||||||
describe 'Travis.Job', ->
|
module "Travis.Job",
|
||||||
beforeEach ->
|
setup: ->
|
||||||
store = Travis.Store.create()
|
teardown: ->
|
||||||
|
Travis.Job.resetData()
|
||||||
|
Travis.Build.resetData()
|
||||||
|
|
||||||
afterEach ->
|
test 'configKeys takes into account the keys of other jobs', ->
|
||||||
store.destroy()
|
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
||||||
|
Travis.Build.load [{ id: '1', job_ids: ['1', '2', '3'], config: buildConfig }]
|
||||||
|
|
||||||
describe 'configKeys', ->
|
Travis.Job.load [{ id: '1', config: { rvm: '1.9.3', env: 'FOO=foo' }, build_id: '1' }]
|
||||||
it 'takes into account the keys of other jobs', ->
|
Travis.Job.load [{ id: '2', config: { rvm: '2.0.0', gemfile: 'Gemfile.1' }, build_id: '1' }]
|
||||||
buildConfig = { rvm: ['1.9.3', '2.0.0'] }
|
Travis.Job.load [{ id: '3', config: { rvm: '1.9.3', jdk: 'OpenJDK' }, build_id: '1' }]
|
||||||
store.load Travis.Build, { id: '1', job_ids: ['1', '2', '3'], config: buildConfig }, { id: '1' }
|
|
||||||
|
|
||||||
store.load Travis.Job, { id: '1', config: { rvm: '1.9.3', env: 'FOO=foo' }, build_id: '1' }, { id: '1' }
|
configValues1 = null
|
||||||
store.load Travis.Job, { id: '2', config: { rvm: '2.0.0', gemfile: 'Gemfile.1' }, build_id: '1' }, { id: '2' }
|
configValues2 = null
|
||||||
store.load Travis.Job, { id: '3', config: { rvm: '1.9.3', jdk: 'OpenJDK' }, build_id: '1' }, { id: '3' }
|
configValues3 = null
|
||||||
|
job1 = null
|
||||||
|
job2 = null
|
||||||
|
job3 = null
|
||||||
|
|
||||||
job1 = store.find(Travis.Job, '1')
|
Ember.run ->
|
||||||
job2 = store.find(Travis.Job, '2')
|
job1 = Travis.Job.find('1')
|
||||||
job3 = store.find(Travis.Job, '3')
|
job2 = Travis.Job.find('2')
|
||||||
|
job3 = Travis.Job.find('3')
|
||||||
|
|
||||||
expect( job1.get('configValues') ).toEqual( [ '1.9.3', 'FOO=foo', undefined, undefined ] )
|
wait().then ->
|
||||||
expect( job2.get('configValues') ).toEqual( [ '2.0.0', undefined, 'Gemfile.1', undefined ] )
|
Ember.run ->
|
||||||
expect( job3.get('configValues') ).toEqual( [ '1.9.3', undefined, undefined, 'OpenJDK' ] )
|
configValues1 = job1.get('configValues')
|
||||||
|
configValues2 = job2.get('configValues')
|
||||||
|
configValues3 = job3.get('configValues')
|
||||||
|
|
||||||
describe 'incomplete attributes', ->
|
deepEqual( configValues1, [ '1.9.3', 'FOO=foo', undefined, undefined ] )
|
||||||
beforeEach ->
|
deepEqual( configValues2, [ '2.0.0', undefined, 'Gemfile.1', undefined ] )
|
||||||
store.loadIncomplete Travis.Job, { id: 1, state: 'started' }
|
deepEqual( configValues3, [ '1.9.3', undefined, undefined, 'OpenJDK' ] )
|
||||||
record = store.find Travis.Job, 1
|
|
||||||
|
|
||||||
it 'does not load record on duration, finishedAt and result if job is not in finished state', ->
|
test 'it does not load record on duration, finishedAt and result if job is not in finished state', ->
|
||||||
record.get('_duration')
|
Travis.Job.load [{ id: 1, state: 'started' }]
|
||||||
record.get('finishedAt')
|
|
||||||
record.get('result')
|
|
||||||
|
|
||||||
waits 50
|
Ember.run ->
|
||||||
runs ->
|
record = Travis.Job.find 1
|
||||||
expect( record.get('incomplete') ).toBeTruthy()
|
|
||||||
|
|
||||||
it 'loads the rest of the record if it\'s in finished state', ->
|
record.loadTheRest = ->
|
||||||
store.loadIncomplete Travis.Job, { id: 1, state: 'passed' }
|
ok(false, 'loadTheRest should not be called')
|
||||||
record = store.find Travis.Job, 1
|
|
||||||
record.get('finishedAt')
|
|
||||||
|
|
||||||
waits 50
|
record.get('_duration')
|
||||||
runs ->
|
record.get('finishedAt')
|
||||||
expect( record.get('incomplete') ).toBeFalsy()
|
record.get('result')
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
ok(true, 'loadTheRest was not called')
|
||||||
|
|
||||||
describe 'with different number of config keys in sibling jobs', ->
|
test 'it loads record on duration, finishedAt and result if job is in finished state', ->
|
||||||
beforeEach ->
|
expect(1)
|
||||||
buildAttrs =
|
|
||||||
id: 1
|
|
||||||
job_ids: [1, 2]
|
|
||||||
config:
|
|
||||||
jdk: ['oraclejdk7']
|
|
||||||
rvm: ['jruby-head']
|
|
||||||
|
|
||||||
store.load Travis.Build, 1, buildAttrs
|
Travis.Job.load [{ id: 1, state: 'passed' }]
|
||||||
|
|
||||||
jobAttrs =
|
Ember.run ->
|
||||||
id: 1
|
record = Travis.Job.find 1
|
||||||
build_id: 1
|
|
||||||
config:
|
|
||||||
jdk: 'oraclejdk7'
|
|
||||||
rvm: 'jruby-head'
|
|
||||||
|
|
||||||
store.load Travis.Job, 1, jobAttrs
|
record.loadTheRest = ->
|
||||||
|
ok(true, 'loadTheRest should be called')
|
||||||
|
|
||||||
jobAttrs =
|
record.get('finishedAt')
|
||||||
id: 2
|
|
||||||
build_id: 1
|
|
||||||
config:
|
|
||||||
jdk: null
|
|
||||||
rvm: 'jruby-head'
|
|
||||||
|
|
||||||
store.load Travis.Job, 2, jobAttrs
|
wait()
|
||||||
|
|
||||||
it 'returns config values for all keys available on build', ->
|
test 'returns config values for all keys available on build with different number of config keys in sibling jobs', ->
|
||||||
job1 = store.find Travis.Job, 1
|
buildAttrs =
|
||||||
job2 = store.find Travis.Job, 2
|
id: 1
|
||||||
|
job_ids: [1, 2]
|
||||||
|
config:
|
||||||
|
jdk: ['oraclejdk7']
|
||||||
|
rvm: ['jruby-head']
|
||||||
|
|
||||||
expect( job1.get('configValues') ).toEqual ['oraclejdk7', 'jruby-head']
|
Travis.Build.load [buildAttrs]
|
||||||
expect( job2.get('configValues') ).toEqual [undefined, 'jruby-head']
|
|
||||||
|
jobAttrs =
|
||||||
|
id: 1
|
||||||
|
build_id: 1
|
||||||
|
config:
|
||||||
|
jdk: 'oraclejdk7'
|
||||||
|
rvm: 'jruby-head'
|
||||||
|
|
||||||
|
Travis.Job.load [jobAttrs]
|
||||||
|
|
||||||
|
jobAttrs =
|
||||||
|
id: 2
|
||||||
|
build_id: 1
|
||||||
|
config:
|
||||||
|
jdk: null
|
||||||
|
rvm: 'jruby-head'
|
||||||
|
|
||||||
|
Travis.Job.load [jobAttrs]
|
||||||
|
|
||||||
|
configValues1 = null
|
||||||
|
configValues2 = null
|
||||||
|
job1 = null
|
||||||
|
job2 = null
|
||||||
|
|
||||||
|
Ember.run ->
|
||||||
|
job1 = Travis.Job.find(1)
|
||||||
|
job2 = Travis.Job.find(2)
|
||||||
|
|
||||||
|
wait().then ->
|
||||||
|
Ember.run ->
|
||||||
|
configValues1 = job1.get('configValues')
|
||||||
|
configValues2 = job2.get('configValues')
|
||||||
|
|
||||||
|
deepEqual( configValues1, ['oraclejdk7', 'jruby-head'] )
|
||||||
|
deepEqual( configValues2, [undefined, 'jruby-head'] )
|
||||||
|
|
|
@ -1,46 +1,47 @@
|
||||||
describe 'Travis.LimitedArray', ->
|
module 'Travis.LimitedArray'
|
||||||
it 'limits given content', ->
|
|
||||||
content = [1, 2, 3]
|
|
||||||
array = Travis.LimitedArray.create content: content, limit: 2
|
|
||||||
expect( array.get('length') ).toEqual 2
|
|
||||||
expect( array.toArray() ).toEqual [1, 2]
|
|
||||||
|
|
||||||
it 'inserts content at the right place when unshifting', ->
|
test 'limits given content', ->
|
||||||
content = [1, 2, 3]
|
content = [1, 2, 3]
|
||||||
array = Travis.LimitedArray.create content: content, limit: 2
|
array = Travis.LimitedArray.create content: content, limit: 2
|
||||||
content.unshiftObject 0
|
equal( array.get('length'), 2 )
|
||||||
expect( array.get('length') ).toEqual 2
|
deepEqual( array.toArray(), [1, 2] )
|
||||||
expect( array.toArray() ).toEqual [0, 1]
|
|
||||||
|
|
||||||
it 'does not insert content when it\'s inserted not in the limited range', ->
|
test 'inserts content at the right place when unshifting', ->
|
||||||
content = [1, 2, 3]
|
content = [1, 2, 3]
|
||||||
array = Travis.LimitedArray.create content: content, limit: 2
|
array = Travis.LimitedArray.create content: content, limit: 2
|
||||||
content.pushObject 0
|
content.unshiftObject 0
|
||||||
expect( array.get('length') ).toEqual 2
|
equal( array.get('length'), 2 )
|
||||||
expect( array.toArray() ).toEqual [1, 2]
|
deepEqual( array.toArray(), [0, 1] )
|
||||||
|
|
||||||
it 'properly removes items', ->
|
test 'does not insert content when it\'s inserted not in the limited range', ->
|
||||||
content = [1, 2, 3]
|
content = [1, 2, 3]
|
||||||
array = Travis.LimitedArray.create content: content, limit: 2
|
array = Travis.LimitedArray.create content: content, limit: 2
|
||||||
content.shiftObject()
|
content.pushObject 0
|
||||||
|
equal( array.get('length'), 2 )
|
||||||
|
deepEqual( array.toArray(), [1, 2] )
|
||||||
|
|
||||||
expect( array.get('length') ).toEqual 2
|
test 'properly removes items', ->
|
||||||
expect( array.toArray() ).toEqual [2, 3]
|
content = [1, 2, 3]
|
||||||
|
array = Travis.LimitedArray.create content: content, limit: 2
|
||||||
|
content.shiftObject()
|
||||||
|
|
||||||
content.shiftObject()
|
equal( array.get('length'), 2 )
|
||||||
|
deepEqual( array.toArray(), [2, 3] )
|
||||||
|
|
||||||
expect( array.get('length') ).toEqual 1
|
content.shiftObject()
|
||||||
expect( array.toArray() ).toEqual [3]
|
|
||||||
|
|
||||||
content.shiftObject()
|
equal( array.get('length'), 1 )
|
||||||
|
deepEqual( array.toArray(), [3] )
|
||||||
|
|
||||||
expect( array.get('length') ).toEqual 0
|
content.shiftObject()
|
||||||
|
|
||||||
it 'allows to expand array to show all items', ->
|
equal( array.get('length'), 0)
|
||||||
content = [1, 2, 3]
|
|
||||||
array = Travis.LimitedArray.create content: content, limit: 2
|
|
||||||
|
|
||||||
array.showAll()
|
test 'allows to expand array to show all items', ->
|
||||||
|
content = [1, 2, 3]
|
||||||
|
array = Travis.LimitedArray.create content: content, limit: 2
|
||||||
|
|
||||||
expect( array.get('length') ).toEqual 3
|
array.showAll()
|
||||||
expect( array.toArray() ).toEqual [1, 2, 3]
|
|
||||||
|
equal( array.get('length'), 3)
|
||||||
|
deepEqual( array.toArray(), [1, 2, 3])
|
||||||
|
|
|
@ -1,105 +0,0 @@
|
||||||
record = null
|
|
||||||
store = null
|
|
||||||
|
|
||||||
describe 'Travis.Model - merge', ->
|
|
||||||
beforeEach ->
|
|
||||||
Travis.Foo = Travis.Model.extend
|
|
||||||
login: DS.attr('string')
|
|
||||||
firstName: DS.attr('string')
|
|
||||||
email: DS.attr('string')
|
|
||||||
|
|
||||||
bar: DS.belongsTo('Travis.Bar')
|
|
||||||
|
|
||||||
Travis.Bar = Travis.Model.extend
|
|
||||||
foos: DS.hasMany('Travis.Foo')
|
|
||||||
|
|
||||||
store = Travis.Store.create()
|
|
||||||
|
|
||||||
afterEach ->
|
|
||||||
delete Travis.Foo
|
|
||||||
delete Travis.Bar
|
|
||||||
store.destroy()
|
|
||||||
|
|
||||||
it 'updates the attributes of materialized record', ->
|
|
||||||
data = { id: '1', firstName: 'Piotr', email: 'drogus@example.org' }
|
|
||||||
store.load(Travis.Foo, { id: '1' }, data)
|
|
||||||
record = store.find(Travis.Foo, '1')
|
|
||||||
|
|
||||||
changes = 0
|
|
||||||
|
|
||||||
observer = ->
|
|
||||||
changes += 1
|
|
||||||
record.addObserver 'firstName', observer
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
store.merge(Travis.Foo, { id: '1', first_name: 'Peter', login: 'drogus' })
|
|
||||||
|
|
||||||
record.removeObserver 'firstName', observer
|
|
||||||
|
|
||||||
expect(changes > 0).toBeTruthy()
|
|
||||||
expect(record.get('firstName')).toEqual('Peter')
|
|
||||||
expect(record.get('login')).toEqual('drogus')
|
|
||||||
expect(record.get('email')).toEqual('drogus@example.org')
|
|
||||||
|
|
||||||
it 'updates belongsTo relationship of materialized record', ->
|
|
||||||
data = { id: '1', login: 'drogus', bar_id: '1' }
|
|
||||||
store.load(Travis.Foo, data, { id: '1' })
|
|
||||||
store.load(Travis.Bar, { id: '1' }, { id: '1' })
|
|
||||||
store.load(Travis.Bar, { id: '2' }, { id: '2' })
|
|
||||||
record = store.find(Travis.Foo, '1')
|
|
||||||
|
|
||||||
changed = false
|
|
||||||
|
|
||||||
observer = ->
|
|
||||||
changed = true
|
|
||||||
record.addObserver 'bar', observer
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
store.merge(Travis.Foo, { id: '1', bar_id: '2' })
|
|
||||||
|
|
||||||
record.removeObserver 'bar', observer
|
|
||||||
|
|
||||||
bar = store.find(Travis.Bar, '2')
|
|
||||||
|
|
||||||
expect(changed).toEqual(true)
|
|
||||||
expect(record.get('bar')).toEqual(bar)
|
|
||||||
|
|
||||||
it 'updates hasMany relationship of materialized record', ->
|
|
||||||
data = { id: '1', foo_ids: [1] }
|
|
||||||
store.load(Travis.Bar, data, { id: '1' })
|
|
||||||
store.load(Travis.Foo, { id: '1' }, { id: '1' })
|
|
||||||
store.load(Travis.Foo, { id: '2' }, { id: '2' })
|
|
||||||
|
|
||||||
record = store.find(Travis.Bar, '1')
|
|
||||||
|
|
||||||
changed = false
|
|
||||||
|
|
||||||
observer = ->
|
|
||||||
changed = true
|
|
||||||
record.addObserver 'foos.length', observer
|
|
||||||
|
|
||||||
Ember.run ->
|
|
||||||
store.merge(Travis.Bar, { id: '1', foo_ids: [1, 2] })
|
|
||||||
|
|
||||||
record.removeObserver 'foos.length', observer
|
|
||||||
|
|
||||||
expect(changed).toEqual(true)
|
|
||||||
expect(record.get('foos.length')).toEqual(2)
|
|
||||||
expect(record.get('foos').mapProperty('id')).toEqual(['1', '2'])
|
|
||||||
|
|
||||||
it 'loads given data if it\'s not in the store yet', ->
|
|
||||||
store.merge(Travis.Foo, { id: '1', login: 'drogus' })
|
|
||||||
|
|
||||||
record = store.find(Travis.Foo, 1)
|
|
||||||
|
|
||||||
expect(record.get('login')).toEqual('drogus')
|
|
||||||
expect(record.get('email')).toEqual(null)
|
|
||||||
|
|
||||||
it 'merges data if it\'s just loaded into store', ->
|
|
||||||
store.load(Travis.Foo, { id: '1', login: 'drogus', email: 'drogus@example.org' }, { id: '1' })
|
|
||||||
store.merge(Travis.Foo, { id: '1', login: 'svenfuchs' })
|
|
||||||
|
|
||||||
record = store.find(Travis.Foo, 1)
|
|
||||||
|
|
||||||
expect(record.get('login')).toEqual('svenfuchs')
|
|
||||||
expect(record.get('email')).toEqual('drogus@example.org')
|
|
122
assets/scripts/spec/unit/model_spec.coffee
Normal file
122
assets/scripts/spec/unit/model_spec.coffee
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
fullPostHash = null
|
||||||
|
Post = null
|
||||||
|
Author = null
|
||||||
|
Comment = null
|
||||||
|
|
||||||
|
module "Travis.Model",
|
||||||
|
setup: ->
|
||||||
|
fullPostHash = {
|
||||||
|
id: '1',
|
||||||
|
title: 'foo',
|
||||||
|
published_at: 'today',
|
||||||
|
|
||||||
|
author_id: '1',
|
||||||
|
comment_ids: ['1', '2']
|
||||||
|
}
|
||||||
|
|
||||||
|
Author = Travis.Model.extend(
|
||||||
|
name: Ember.attr('string')
|
||||||
|
)
|
||||||
|
Author.toString = -> return 'Author'
|
||||||
|
|
||||||
|
Comment = Travis.Model.extend(
|
||||||
|
body: Ember.attr('string')
|
||||||
|
)
|
||||||
|
Comment.toString = -> return 'Comment'
|
||||||
|
|
||||||
|
Post = Travis.Model.extend(
|
||||||
|
title: Ember.attr('string'),
|
||||||
|
publishedAt: Ember.attr('string'),
|
||||||
|
|
||||||
|
author: Ember.belongsTo(Author, { key: 'author_id' }),
|
||||||
|
comments: Ember.hasMany(Comment, { key: 'comment_ids' })
|
||||||
|
)
|
||||||
|
Post.toString = -> return 'Post'
|
||||||
|
|
||||||
|
Comment.adapter = Ember.FixtureAdapter.create()
|
||||||
|
Author.adapter = Ember.FixtureAdapter.create()
|
||||||
|
Post.adapter = Ember.FixtureAdapter.create()
|
||||||
|
|
||||||
|
Author.load([
|
||||||
|
{ id: '1', name: 'drogus' }
|
||||||
|
])
|
||||||
|
Comment.load([
|
||||||
|
{ id: '1', body: 'comment 1' },
|
||||||
|
{ id: '2', body: 'comment 2' }
|
||||||
|
])
|
||||||
|
test "new data can be merged into the record", ->
|
||||||
|
delete fullPostHash.title
|
||||||
|
delete fullPostHash.author_id
|
||||||
|
delete fullPostHash.comment_ids
|
||||||
|
post = Post.findFromCacheOrLoad(fullPostHash)
|
||||||
|
|
||||||
|
post.loadTheRest = (->)
|
||||||
|
|
||||||
|
equal(post.get('title'), null, 'title should be null')
|
||||||
|
equal(post.get('comments.length'), 0, 'comments should be empty')
|
||||||
|
equal(post.get('author'), null, 'author should be null')
|
||||||
|
|
||||||
|
Ember.run -> post.merge(title: 'teh title', comment_ids: ['1', '2'], author_id: '1')
|
||||||
|
|
||||||
|
author = null
|
||||||
|
Ember.run -> author = Author.find('1').get('name')
|
||||||
|
title = null
|
||||||
|
Ember.run -> title = post.get('title')
|
||||||
|
console.log('title', title)
|
||||||
|
|
||||||
|
equal(post.get('title'), 'teh title', 'title should be updated')
|
||||||
|
equal(post.get('comments.length'), 2, 'comments should be updated and have length of 2')
|
||||||
|
equal(post.get('comments.firstObject.body'), 'comment 1', 'comment should be loaded')
|
||||||
|
equal(author, 'drogus', 'author should be loaded')
|
||||||
|
equal(post.get('publishedAt'), 'today', 'existing attributes are not overwritten')
|
||||||
|
|
||||||
|
module "Travis.Model.loadOrMerge",
|
||||||
|
setup: ->
|
||||||
|
Post = Travis.Model.extend(
|
||||||
|
title: Ember.attr('string')
|
||||||
|
)
|
||||||
|
Post.toString = -> return 'Post'
|
||||||
|
|
||||||
|
test "it doesn't update record if skipIfExists is passed and record is already in store", ->
|
||||||
|
Post.load([{id: '1', title: 'foo'}])
|
||||||
|
|
||||||
|
post = Post.find('1')
|
||||||
|
equal(post.get('title'), 'foo', 'precondition - title of the post should be set')
|
||||||
|
|
||||||
|
Ember.run ->
|
||||||
|
Travis.loadOrMerge(Post, { id: '1', title: 'bar' }, { skipIfExists: true })
|
||||||
|
|
||||||
|
equal(post.get('title'), 'foo', 'title should stay unchanged')
|
||||||
|
|
||||||
|
test "it updates record if record is already in the store", ->
|
||||||
|
Post.load([{id: '1', title: 'foo'}])
|
||||||
|
|
||||||
|
post = Post.find('1')
|
||||||
|
equal(post.get('title'), 'foo', 'precondition - title of the post should be set')
|
||||||
|
|
||||||
|
Ember.run ->
|
||||||
|
Travis.loadOrMerge(Post, { id: '1', title: 'bar' })
|
||||||
|
|
||||||
|
equal(post.get('title'), 'bar', 'title should be updated')
|
||||||
|
|
||||||
|
test "record is not instantiated by default", ->
|
||||||
|
reference = null
|
||||||
|
Ember.run ->
|
||||||
|
reference = Travis.loadOrMerge(Post, { id: '1', title: 'bar' })
|
||||||
|
|
||||||
|
equal(reference.id, '1', 'reference should be created')
|
||||||
|
ok(Ember.isNone(reference.record), 'record should not be created')
|
||||||
|
|
||||||
|
post = null
|
||||||
|
Ember.run -> post = Post.find('1')
|
||||||
|
equal(post.get('title'), 'bar', 'record should be loaded from cached data')
|
||||||
|
equal(reference.record, post, 'record should be created')
|
||||||
|
|
||||||
|
test "data is merged to the existing data cache", ->
|
||||||
|
Post.load([{id: '1', title: 'foo'}])
|
||||||
|
|
||||||
|
Ember.run ->
|
||||||
|
Travis.loadOrMerge(Post, { id: '1', title: 'bar' })
|
||||||
|
|
||||||
|
post = Post.find('1')
|
||||||
|
equal(post.get('title'), 'bar', 'title should be updated')
|
Loading…
Reference in New Issue
Block a user