-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from emberjs/application-tests
Implement `startApplicationTest` from emberjs/rfcs#268.
- Loading branch information
Showing
9 changed files
with
171 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { module, test } from 'qunit'; | ||
import EmberRouter from '@ember/routing/router'; | ||
import Route from '@ember/routing/route'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
import { visit, currentRouteName, currentURL, click } from '@ember/test-helpers'; | ||
import { setResolverRegistry } from '../helpers/resolver'; | ||
import hasEmberVersion from 'ember-test-helpers/has-ember-version'; | ||
|
||
module('setupApplicationTest tests', function(hooks) { | ||
if (!hasEmberVersion(2, 4)) { | ||
return; | ||
} | ||
|
||
const Router = EmberRouter.extend({ location: 'none' }); | ||
Router.map(function() { | ||
this.route('widgets'); | ||
this.route('posts', function() { | ||
this.route('post', { path: ':post_id' }); | ||
}); | ||
}); | ||
|
||
hooks.beforeEach(function() { | ||
setResolverRegistry({ | ||
'router:main': Router, | ||
'template:application': hbs` | ||
<div class="nav">{{link-to 'posts' 'posts'}} | {{link-to 'widgets' 'widgets'}}</div> | ||
{{outlet}} | ||
`, | ||
'template:index': hbs`<h1>Hello World!</h1>`, | ||
'template:posts': hbs`<h1>Posts Page</h1>{{outlet}}`, | ||
'template:posts/post': hbs`<div class="post-id">{{model.post_id}}</div>`, | ||
'route:posts/post': Route.extend({ | ||
model(params) { | ||
return params; | ||
}, | ||
}), | ||
}); | ||
}); | ||
|
||
setupApplicationTest(hooks); | ||
|
||
test('can render', async function(assert) { | ||
await visit('/'); | ||
|
||
assert.equal(currentRouteName(), 'index'); | ||
assert.equal(currentURL(), '/'); | ||
|
||
assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets'); | ||
assert.equal(this.element.querySelector('h1').textContent, 'Hello World!'); | ||
}); | ||
|
||
test('can perform a basic template rendering for nested route', async function(assert) { | ||
await visit('/posts/1'); | ||
|
||
assert.equal(currentRouteName(), 'posts.post'); | ||
assert.equal(currentURL(), '/posts/1'); | ||
|
||
assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets'); | ||
assert.equal(this.element.querySelector('.post-id').textContent, '1'); | ||
}); | ||
|
||
test('can visit multiple times', async function(assert) { | ||
await visit('/posts/1'); | ||
|
||
assert.equal(currentRouteName(), 'posts.post'); | ||
assert.equal(currentURL(), '/posts/1'); | ||
|
||
assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets'); | ||
assert.equal(this.element.querySelector('.post-id').textContent, '1'); | ||
|
||
await visit('/'); | ||
|
||
assert.equal(currentRouteName(), 'index'); | ||
assert.equal(currentURL(), '/'); | ||
|
||
assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets'); | ||
assert.equal(this.element.querySelector('h1').textContent, 'Hello World!'); | ||
|
||
await visit('/posts/2'); | ||
|
||
assert.equal(currentRouteName(), 'posts.post'); | ||
assert.equal(currentURL(), '/posts/2'); | ||
|
||
assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets'); | ||
assert.equal(this.element.querySelector('.post-id').textContent, '2'); | ||
}); | ||
|
||
test('can navigate amongst routes', async function(assert) { | ||
await visit('/'); | ||
|
||
assert.equal(currentRouteName(), 'index'); | ||
assert.equal(currentURL(), '/'); | ||
|
||
await click('a[href="/posts"]'); | ||
|
||
assert.equal(currentRouteName(), 'posts.index'); | ||
assert.equal(currentURL(), '/posts'); | ||
|
||
assert.equal(this.element.querySelector('h1').textContent, 'Posts Page'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import Resolver from 'ember-resolver'; | ||
|
||
export default Resolver; | ||
export let registry = Object.create(null); | ||
export function setRegistry(newRegistry) { | ||
registry = newRegistry; | ||
} | ||
|
||
export default Resolver.extend({ | ||
resolve(fullName) { | ||
return registry[fullName] || this._super(...arguments); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,18 @@ | ||
import Ember from 'ember'; | ||
import AppResolver from '../../resolver'; | ||
import App from '../../app'; | ||
import { setRegistry } from '../../resolver'; | ||
import config from '../../config/environment'; | ||
import { setResolver } from 'ember-test-helpers'; | ||
|
||
const Resolver = AppResolver.extend({ | ||
resolve: function(fullName) { | ||
return this.registry[fullName] || this._super.apply(this, arguments); | ||
}, | ||
|
||
normalize: function(fullName) { | ||
return Ember.String.dasherize(fullName); | ||
}, | ||
export const application = App.create(config.APP); | ||
export const resolver = application.Resolver.create({ | ||
namespace: application, | ||
isResolverFromTestHelpers: true, | ||
}); | ||
const resolver = Resolver.create(); | ||
|
||
resolver.namespace = { | ||
modulePrefix: config.modulePrefix, | ||
podModulePrefix: config.podModulePrefix, | ||
}; | ||
|
||
export default resolver; | ||
|
||
setResolver(resolver); | ||
|
||
export function setResolverRegistry(registry) { | ||
resolver.set('registry', registry); | ||
setRegistry(registry); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import resolver from './helpers/resolver'; | ||
import { setResolver, start } from 'ember-qunit'; | ||
import { application } from './helpers/resolver'; | ||
import { start } from 'ember-qunit'; | ||
import { setApplication } from '@ember/test-helpers'; | ||
|
||
setResolver(resolver); | ||
setApplication(application); | ||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters