Add a simple acceptance test for dashboard and tooling needed to run it
Apart from adding a test, this commit also adds a dummy implementation for Auth that can be used in tests to control the auth status.
This commit is contained in:
parent
b2b70b592f
commit
7e1168cae2
|
@ -1,7 +1,8 @@
|
||||||
`import Auth from 'travis/utils/auth'`
|
`import Auth from 'travis/utils/auth'`
|
||||||
|
`import TestAuth from 'travis/utils/test-auth'`
|
||||||
|
|
||||||
initialize = (container, app) ->
|
initialize = (container, app) ->
|
||||||
app.register 'auth:main', Auth
|
app.register 'auth:main', if Ember.testing then TestAuth else Auth
|
||||||
|
|
||||||
app.inject('route', 'auth', 'auth:main')
|
app.inject('route', 'auth', 'auth:main')
|
||||||
app.inject('controller', 'auth', 'auth:main')
|
app.inject('controller', 'auth', 'auth:main')
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Ember from 'ember';
|
||||||
|
|
||||||
var limit = function(dependentKey, limitKey) {
|
var limit = function(dependentKey, limitKey) {
|
||||||
var options = {
|
var options = {
|
||||||
addedItem: function(array, item, changeMeta, instanceMeta) {
|
addedItem: function(array, item, changeMeta) {
|
||||||
var limit = Ember.get(this, limitKey);
|
var limit = Ember.get(this, limitKey);
|
||||||
if (changeMeta.index < limit) {
|
if (changeMeta.index < limit) {
|
||||||
array.insertAt(changeMeta.index, item);
|
array.insertAt(changeMeta.index, item);
|
||||||
|
@ -12,7 +12,7 @@ var limit = function(dependentKey, limitKey) {
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
},
|
},
|
||||||
removedItem: function(array, item, changeMeta, instanceMeta) {
|
removedItem: function(array, item, changeMeta) {
|
||||||
var limit = Ember.get(this, limitKey);
|
var limit = Ember.get(this, limitKey);
|
||||||
if (changeMeta.index < limit && changeMeta.index < Ember.get(array, 'length')) {
|
if (changeMeta.index < limit && changeMeta.index < Ember.get(array, 'length')) {
|
||||||
array.removeAt(changeMeta.index, 1);
|
array.removeAt(changeMeta.index, 1);
|
||||||
|
|
51
app/utils/test-auth.coffee
Normal file
51
app/utils/test-auth.coffee
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
|
||||||
|
Auth = Ember.Object.extend
|
||||||
|
state: 'signed-out'
|
||||||
|
|
||||||
|
# I want to disable auto sign in for tests for now, the plan is to either
|
||||||
|
# explicitly say that you're signed in or out (the latter being the default)
|
||||||
|
autoSignIn: (->)
|
||||||
|
|
||||||
|
signOutForTests: ->
|
||||||
|
@set('state', 'signed-out')
|
||||||
|
@set('currentUser', null)
|
||||||
|
|
||||||
|
signInForTests: (user) ->
|
||||||
|
@set('state', 'signed-in')
|
||||||
|
if user.constructor.typeKey? != 'user'
|
||||||
|
@store.pushPayload(users: [user])
|
||||||
|
user = @store.recordForId('user', user.id)
|
||||||
|
|
||||||
|
@set('currentUser', user)
|
||||||
|
|
||||||
|
# TODO: we use these properties in templates, but there
|
||||||
|
# really should be something like a 'session' service that can be
|
||||||
|
# injected where we need it
|
||||||
|
userName: (->
|
||||||
|
@get('currentUser.name') || @get('currentUser.login')
|
||||||
|
).property('currentUser.login', 'currentUser.name')
|
||||||
|
|
||||||
|
gravatarUrl: (->
|
||||||
|
"#{location.protocol}//www.gravatar.com/avatar/#{@get('currentUser.gravatarId')}?s=48&d=mm"
|
||||||
|
).property('currentUser.gravatarId')
|
||||||
|
|
||||||
|
permissions: Ember.computed.alias('currentUser.permissions')
|
||||||
|
|
||||||
|
signedIn: (->
|
||||||
|
@get('state') == 'signed-in'
|
||||||
|
).property('state')
|
||||||
|
|
||||||
|
signedOut: (->
|
||||||
|
@get('state') == 'signed-out'
|
||||||
|
).property('state')
|
||||||
|
|
||||||
|
signingIn: (->
|
||||||
|
@get('state') == 'signing-in'
|
||||||
|
).property('state')
|
||||||
|
|
||||||
|
token: ->
|
||||||
|
if @get('state') == 'signed-in'
|
||||||
|
'a-token'
|
||||||
|
|
||||||
|
`export default Auth`
|
|
@ -17,6 +17,7 @@
|
||||||
"JavaScript-MD5": "~1.1.0",
|
"JavaScript-MD5": "~1.1.0",
|
||||||
"moment": "~2.9.0",
|
"moment": "~2.9.0",
|
||||||
"jquery-timeago": "~1.4.1",
|
"jquery-timeago": "~1.4.1",
|
||||||
"pusher": "~2.2.3"
|
"pusher": "~2.2.3",
|
||||||
|
"pretender": "0.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
"ember-cli-ic-ajax": "0.1.1",
|
"ember-cli-ic-ajax": "0.1.1",
|
||||||
"ember-cli-inject-live-reload": "^1.3.0",
|
"ember-cli-inject-live-reload": "^1.3.0",
|
||||||
"ember-cli-inline-images": "^0.0.3",
|
"ember-cli-inline-images": "^0.0.3",
|
||||||
|
"ember-cli-pretender": "0.3.1",
|
||||||
"ember-cli-qunit": "0.3.0",
|
"ember-cli-qunit": "0.3.0",
|
||||||
"ember-cli-sauce": "0.0.7",
|
"ember-cli-sauce": "0.0.7",
|
||||||
"ember-cli-uglify": "1.0.1",
|
"ember-cli-uglify": "1.0.1",
|
||||||
|
|
67
tests/acceptance/dashboard-test.coffee
Normal file
67
tests/acceptance/dashboard-test.coffee
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
`import startApp from '../helpers/start-app'`
|
||||||
|
`import Pretender from 'pretender'`
|
||||||
|
|
||||||
|
application = null
|
||||||
|
server = null
|
||||||
|
|
||||||
|
module 'Acceptance: Dashboard',
|
||||||
|
setup: ->
|
||||||
|
application = startApp()
|
||||||
|
Ember.run ->
|
||||||
|
application.auth.signInForTests(id: 1, login: 'drogus')
|
||||||
|
server = new Pretender ->
|
||||||
|
@get('/v3/repos', (request) ->
|
||||||
|
data = {
|
||||||
|
"@type": "repositories",
|
||||||
|
"repositories": [{
|
||||||
|
"@type": "repository",
|
||||||
|
"active": true,
|
||||||
|
"id": 1,
|
||||||
|
"name": "travis-web",
|
||||||
|
"slug": "travis-ci/travis-web",
|
||||||
|
"description": "The Ember web client for Travis CI",
|
||||||
|
"github_language": "CoffeeScript",
|
||||||
|
"private": false,
|
||||||
|
"owner": {
|
||||||
|
"@type": "organization",
|
||||||
|
"id": 1,
|
||||||
|
"login": "travis-ci"
|
||||||
|
},
|
||||||
|
"last_build": {
|
||||||
|
"@type": "build",
|
||||||
|
"id": 1,
|
||||||
|
"number": "1",
|
||||||
|
"state": "passed",
|
||||||
|
"duration": 20,
|
||||||
|
"started_at": "2015-02-05T09:58:31Z",
|
||||||
|
"finished_at": "2015-02-05T10:09:10Z"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"@type": "repository",
|
||||||
|
"active": true,
|
||||||
|
"id": 2,
|
||||||
|
"name": "travis-test",
|
||||||
|
"slug": "travis-ci/travis-test",
|
||||||
|
"private": false,
|
||||||
|
"owner": {
|
||||||
|
"@type": "organization",
|
||||||
|
"id": 87,
|
||||||
|
"login": "travis-ci"
|
||||||
|
},
|
||||||
|
"last_build": null
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
return [200, { "Content-Type": "application/json" }, JSON.stringify(data)]
|
||||||
|
)
|
||||||
|
|
||||||
|
teardown: ->
|
||||||
|
Ember.run application, 'destroy'
|
||||||
|
server.shutdown()
|
||||||
|
|
||||||
|
test 'visiting /dashboard', ->
|
||||||
|
visit '/dashboard'
|
||||||
|
|
||||||
|
andThen ->
|
||||||
|
equal find('.tiles .repo').length, 1, 'there should be one repo displayed on dashboard'
|
||||||
|
equal find('.tiles .repo').text(), 'travis-web', 'travis-web repository should be displayed'
|
|
@ -15,5 +15,11 @@ export default function startApp(attrs) {
|
||||||
application.injectTestHelpers();
|
application.injectTestHelpers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: I'm not sure if this is the best thing to do, but it seems
|
||||||
|
// easiest for now. That way in tests I can just write:
|
||||||
|
//
|
||||||
|
// application.auth.signInForTests()
|
||||||
|
application.auth = application.__container__.lookup('auth:main');
|
||||||
|
|
||||||
return application;
|
return application;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user