Skip to content

Commit

Permalink
Make basic visit work...
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Dec 15, 2017
1 parent 9be2e74 commit e2ed394
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addon-test-support/@ember/test-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export {
export { default as teardownContext } from './teardown-context';
export { default as setupRenderingContext, render, clearRender } from './setup-rendering-context';
export { default as teardownRenderingContext } from './teardown-rendering-context';
export { default as setupApplicationContext } from './setup-application-context';
export { default as teardownApplicationContext } from './teardown-application-context';
export { default as settled, isSettled, getState as getSettledState } from './settled';
export { default as waitUntil } from './wait-until';
export { default as validateErrorHandler } from './validate-error-handler';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { nextTickPromise } from './-utils';

export default function(context) {
return nextTickPromise().then(() => {
let { owner } = context;

let element;
context.visit = function visit(url) {
return owner.visit(url).then(() => {
element = document.querySelector('#ember-testing > .ember-view');
});
};

Object.defineProperty(context, 'element', {
enumerable: true,
configurable: true,
get() {
return element;
},
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function() {}
64 changes: 64 additions & 0 deletions tests/unit/setup-application-context-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { module, test } from 'qunit';
import EmberRouter from '@ember/routing/router';
import Service from '@ember/service';
import {
setupContext,
setupApplicationContext,
teardownContext,
teardownApplicationContext,
setApplication,
click,
} from '@ember/test-helpers';
import hasEmberVersion from 'ember-test-helpers/has-ember-version';
import { setResolverRegistry, application } from '../helpers/resolver';
import hbs from 'htmlbars-inline-precompile';

const Router = EmberRouter.extend({ location: 'none' });
Router.map(function() {
this.route('posts');
this.route('widgets');
});

module('setupApplicationContext', function(hooks) {
if (!hasEmberVersion(2, 4)) {
return;
}

hooks.beforeEach(async 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>`,
'service:foo': Service.extend({ isFoo: true }),
});

setApplication(application);

await setupContext(this);
await setupApplicationContext(this);
});

hooks.afterEach(async function() {
await teardownApplicationContext(this);
await teardownContext(this);
});

test('can perform a basic template rendering', async function(assert) {
await this.visit('/');

assert.equal(this.element.querySelector('.nav').textContent, 'posts | widgets');
assert.equal(this.element.querySelector('h1').textContent, 'Hello World!');
});

test('can navigate amongst routes', async function(assert) {
await this.visit('/');

await click('a[href="/posts"]');

assert.equal(this.element.querySelector('h1').textContent, 'Posts Page');
});
});

0 comments on commit e2ed394

Please sign in to comment.